[Rd] R 2.5.0 refuses to print enough digits to recover exact floating point values
Petr Savicky
savicky at cs.cas.cz
Wed May 23 18:55:24 CEST 2007
> > 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.
More information about the R-devel
mailing list