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

From: Petr Savicky <savicky_at_cs.cas.cz>
Date: Wed, 23 May 2007 18:55:24 +0200

> > Well, okay, now what about dump, write.table, save, etc?
> 
> save() uses the required precision. For exp(1) it stores 
> "2.718281828459045" and you will see that
> 
> exp(1) == 2.718281828459045  is TRUE
> 

save(...,ascii=TRUE) uses 16 digit precision, but this seems not to be sufficient. In R-2.5.0, I obtained:

> otab <- data.frame(val=1+1/(1:1000));
> ntab <- otab;
> save(otab,file="save.txt",ascii=TRUE);
> rm(otab);
> load("save.txt");
  

> cbind(table(otab[,1]-ntab[,1]))

                        [,1]

  -4.44089209850063e-16 159
  -2.22044604925031e-16 220
  0                      240

  2.22044604925031e-16 213
  4.44089209850063e-16 168

So, most of the numbers are changed. The changes are within the last two bits. The last bit represents the difference 2^(-52) = 2.220446e-16.

Petr.



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 23 May 2007 - 16:58:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 May 2007 - 17:33:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.