I considered a simple way to approximate Machine Epsilon in Java:
float machEps = 1.0f;
do
machEps /= 2.0f;
while ((float) (1.0 + (machEps / 2.0)) != 1.0);
System.out.println( machEps);
This returns:
1.1920929E-7
However, when I remove the transform in floatin a loop while:
float machEps = 1.0f;
do
machEps /= 2.0f;
while ( (1.0 + (machEps / 2.0)) != 1.0);
System.out.println( machEps);
I get:
2.220446E-16
I don’t quite understand why this is .... my guess is that in the second case, Java is trying to deploy machEpsfrom floatto double. However, I'm not sure if this is an exact statement, or there is another reason why I get two different answers.
source
share