The documentation describes .Machine$double.eps
as The smallest positive floating-point number x such that 1 + x != 1
. So I would expect the following to produce a 1:
options(digits=17)
1 + .Machine$double.eps
# [1] 1.0000000000000002
but it doesn't. It appears that I have to go as low as 0.5*.Machine$double.eps
before I get the expected round-off to one. Am I misunderstanding something about .Machine$double.eps
? Is this platform-dependent? (sessionInfo() below)
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.0.2
Thank you
Just because it's interesting, here is the code R uses to calculate eps (extracted into its own program):
#include <stdio.h>
int main() {
double temp, tempa, a;
double eps;
double one = 1;
double zero = one - one;
double beta = 2;
a = 1.38777878078144568e-17;
for(;;) {
temp = one + a;
if (temp - one != zero)
break;
a = a * beta;
}
eps = a;
printf("%e\n", eps);
}
It yields 2.22e-16 as documented.
Note that it jumps by a factor of 2 each time -- so it's not actually going to find the strictly smallest floating point where 1 + x
isn't 1
. But it is going to find the smallest one on that ladder of powers of 2.
So, I would say that strictly speaking the documentation is not quite accurate, because it is indeed true that 0.75*eps + 1 != 1
and 0.75*eps < eps
.
It seems you misunderstood the documentation. Note that it says that it is the smallest x
such that 1 + x != 1
So read that carefully - if we add 1 to .Machine$double.eps
then we should NOT get 1 back. So the result you got was as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With