compare « float « Java Data Type Q&A

1. Manipulating and comparing floating points in java

In Java the floating point arithmetic is not represented precisely. For example following snippet of code

            float a = 1.2; ...

2. Can I get Java to throw an exception when doing a comparison between floats when one of them turns out to be NaN?

I spent about 2 hours tracking down a bug today and I would've found it much quicker had java thrown an exception when comparing NaN with a float. It would ...

3. Comparing floating point numbers in Java

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

4. Comparing float and double primitives in Java

I came across a strange corner of Java.(It seems strange to me)

double dd = 3.5;          
float ff = 3.5f;
o/p: ...

5. Java implementation of Comparing floating point numbers

According to the JLS (S15.16.3) Java's floating point remainder (using the '%' operator) is *different from* the java.lang.Math.IEEEremainder() function. The operator is based on truncating division while the function is based on rounding division. You might think that this won't add up to much, but 8.0 % 3.0 results in -1.0 with rounding division versus 2.0 with truncating division.

6. Help in Float comparison

8. float & double comparison in Java

9. Comparing Two Float Numbers