Possible duplicate:
Keep precision with doubling in java
Do you know the difference between these two operations in Java.
final double m1 = 11d / 1e9;
final double m2 = 11d * 1e-9;
I see in the generated bytecode that the precompiled result m2 is no longer the one I expected.
At the output, javap -verbose -cI see the following value:
const #3 = double 1.1E-8d;
[...]
const #6 = double 1.1000000000000001E-8d;
When I use m1 or m2 in other expressions, I do not have the same result.
When I try to do the same in C, m1 and m2 are strictly 1.1e-8
I think my problem is how java handles calculations with double precision, but I cannot explain what I missed.
Joker source
share