From zack at cogsci.ucsd.edu  Sun May 27 02:50:43 2007
From: zack at cogsci.ucsd.edu (Zack Weinberg)
Date: Sat, 26 May 2007 17:50:43 -0700
Subject: [Rd] R 2.5.0 refuses to print enough digits to recover exact
	floating point values
In-Reply-To: <Pine.LNX.4.64.0705231538310.27405@gannet.stats.ox.ac.uk>
References: <eb97335b0705220013m6f3e137cp147d429c46717e24@mail.gmail.com>
	<4652C19F.1040509@statistik.uni-dortmund.de>
	<f8e6ff050705230251t1170b47enea9ced70a6ca4a1e@mail.gmail.com>
	<f8e6ff050705230257q72f3dbd5ua18072424b38386@mail.gmail.com>
	<Pine.LNX.4.64.0705231538310.27405@gannet.stats.ox.ac.uk>
Message-ID: <eb97335b0705261750i3a1f69fdia860e6ba4a29df11@mail.gmail.com>

On 5/23/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
[...]
> It really is the case that writing out a number to > 15 significant digits
> and reading it back in again is not required to give exactly the same
> IEC60559 (sic) number, and furthermore there are R platforms for which
> this does not happen.  What Mr Weinberg claimed is 'now impossible' never
> was possible in general (and he seems to be berating the R developers for
> not striving to do better than the C standard requires of OSes).  In fact,
> I believe this to be impossible unless you have access to extended
> precsion arithmetic, as otherwise printf/scanf have to use the same
> arithmetic as the computations.

I did not intend to berate anyone - I may have come across that way
because I was frustrated, in which case I apologize.

 I *do* think it is reasonable to expect a numerical analysis program
to have numerically stable, 100% accurate, perfectly roundtripping
floating-point-to-text conversion, even if the system's runtime
libraries don't get it right, even if the hardware does not provide
extended precision to make it easier.  In the worst case you have to
muck around with software-emulated extended-precision FP, and even
that really isn't that hard.

There is code in GCC that does exactly this, it's only about 5000 LOC,
and it does quite a bit more than R would need.  If there were
interest I could see about porting it across.

zw



[Rd] R 2.5.0 refuses to print enough digits to recover exact floating point values
Zack Weinberg