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

Zack Weinberg zack at cogsci.ucsd.edu
Sun May 27 02:50:43 CEST 2007


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



More information about the R-devel mailing list