Possible Duplicate:
Manipulating and comparing floating points in java
Am I supposed to use an Epsilon while comparing floating point numbers in Java ? Does the Float.compare(float f1, float f2) static method is safe to use ?
Thanks !
EDIT : I think I got it.
When I write, let's say, 3.6f in eclipse, the compilator interpret this number as 3.6. However, when I write 1.2f * 3.0f, the result is 3.6000001. While mathematically this is false, these two results are obviously inequals. Hence the need to have an epsilon while checking equality.
However, when I write 0.0f in eclipse, the compilator interpret this as 0 strictly, because IEEE 754 is able to handle it correctly. Therefore, ensuring a float is strictly positive with (value > 0.0f) is correct.
The only problem I see is when the computer doesn't use IEEE 754 representation, and instead use a representation which doesn't handle 0 correctly.
Am I right ?