[Rd] significant digits (PR#9682)

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jun 4 14:18:26 CEST 2008


That (and simpler, sprintf()) merely tell you about your OS's sprintf 
function.  That is not required to accurately give a decimal 
representation of more than DECIMAL_DIG digits, and certainly not 50.
The help for formatC does warn you about this.

On my F8 system DECIMAL_DIG is mentioned in math.h but not defined there. 
(It is defined in the compiler, AFAICS -- SunStudio has it as 21, and gcc 
computes __DECIMAL_DIG__ also as 21.)  The C99 standard says that it 
should be at least 10 and that 17 is appropriate for IEC60559 arithmetic.


On Wed, 4 Jun 2008, Karl Ove Hufthammer wrote:

> Duncan Murdoch:
>
>> 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.
>
> I like using formatC for checking such things. On my (Linux) system, I get:
>
> $ formatC(.12345,digits=50)
> [1] "0.12345000000000000417443857259058859199285507202148"
>
>> So it looks as though Windows gets it right.
>
> -- 
> Karl Ove Hufthammer
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list