From ripley at stats.ox.ac.uk  Wed Jun  4 14:18:26 2008
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 4 Jun 2008 13:18:26 +0100 (BST)
Subject: [Rd] significant digits (PR#9682)
In-Reply-To: <g25tl0$bbi$1@ger.gmane.org>
References: <20080602234017.CB1FD282C786@mail.pubhealth.ku.dk>
	<48451EBC.1000207@stats.uwo.ca>
	<a696b2f20806030843i5c290c87u1125b280b8a7672e@mail.gmail.com>
	<48459200.20401@stats.uwo.ca> <g25tl0$bbi$1@ger.gmane.org>
Message-ID: <alpine.LFD.1.10.0806041230470.24876@gannet.stats.ox.ac.uk>

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



[Rd] significant digits (PR#9682)
Prof Brian Ripley