No at home. The previous reply was short and I had to use my Treo.

On 20 May 2007 at 11:02, Zack Weinberg wrote:
| I think you have misunderstood what I am trying to do here.  I have
| deliberately constructed a floating-point number that differs from
| 0.37 by one "unit in the last place" as the numerical analysts call
| it.  (If R supported it, I would be using C99 hexadecimal floating
| pont notation to be *absolutely sure* that I had entered the correct
| bit pattern.)  R does everything right with this number - in
| particular, yes, I *intended* it to compare unequal to 0.37 by == -
| except print its true value when I request enough decimal places to
| see the difference.  For an IEEE double, which is what R appears to
| use, 20 digits after the decimal point is enough to distinguish all
| possible (binary) values.  [Actually I think 17 is enough, but I'm not
| sure there.]

Note the comment in the help page for print.default (indented two space here):

  Warning:

       Using too large a value of 'digits' may lead to representation
       errors in the calculation of the number of significant digits and
       the decimal representation: these are likely for 'digits >= 16',
       and as from R 2.5.0 these possible errors are taken into account
       in assessing the numher of significant digits to be printed in
       that case.

       Whereas earlier versions of R might have printed further digits
       for 'digits >= 16' on some platforms, they were not necessarily
       reliable.

Also, see this example:

> options("digits"=22); for (i in seq(11,20)) print(0.37 + 1*10^-i)
[1] 0.37000000001
[1] 0.370000000001
[1] 0.3700000000001
[1] 0.37000000000001
[1] 0.370000000000001
[1] 0.37
[1] 0.37
[1] 0.37
[1] 0.37
[1] 0.37
> 

I you use the large possible digits setting, you get to see the difference
til about 10^-15 which sound about right for double precision on x86.

| Furthermore, glibc's sprintf() gets this right, and therefore R must
| actually be doing extra work in order to get it wrong!

That isn't really relevant as nobody claims that any of R's print methods are
pass-throughs to glibc's.  That said, this avenue may provide the easiest fix
for you -- set up little wrapper function that calls sprintf directly and use
that in your application.

There is no R bug here.  

Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
                                                  -- Thomas A. Edison


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to