From savicky at cs.cas.cz  Wed May 23 18:55:24 2007
From: savicky at cs.cas.cz (Petr Savicky)
Date: Wed, 23 May 2007 18:55:24 +0200
Subject: [Rd] R 2.5.0 refuses to print enough digits to recover exact
	floating point values
In-Reply-To: <46540A76.2080909@statistik.uni-dortmund.de>
References: <eb97335b0705220013m6f3e137cp147d429c46717e24@mail.gmail.com>
	<4652C19F.1040509@statistik.uni-dortmund.de>
	<eb97335b0705220849l624d8cai6e49e37e2565ab81@mail.gmail.com>
	<46540A76.2080909@statistik.uni-dortmund.de>
Message-ID: <20070523165523.GA23733@cs.cas.cz>

> > 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.



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