Skip to content
Prev 29078 / 63424 Next

significant digits (PR#9682)

On 6/3/2008 11:43 AM, Patrick Carr wrote:
It's easy to make mistakes in this, but a little outside-of-R 
experimentation suggests those are the right answers.  The number 12345 
is exactly representable, so it is exactly half-way between 12340 and 
12350, so 12340 is the right answer by the unbiased round-to-even rule. 
  The number 0.12345 is not exactly representable, but (I think) it is 
represented by something slightly closer to 0.1235 than to 0.1234.  So 
it looks as though Windows gets it right.
Which would seem to imply OS X gets it wrong.  Both are supposed to be 
using the 64 bit floating point standard, so they should both give the 
same answer:  but the actual arithmetic is being done by run-time 
libraries that are outside our control to a large extent, and it looks 
as though the one on the Mac is less accurate than the one on Windows.


  But (on both windows and OS X):
This is a different problem.  The number is correctly computed as 
12345.12345 (or at least a representable number quite close to that), 
and then the default display rounds it some more.  Set 
options(digits=19) to see it in its full glory.

Duncan Murdoch