I came to interesting problem when dealing with Java primitive type float
I try to subtract 1.0 from Float.MAX_VALUE, strangely it returns the value equals Float.MAX_VALUE. Here is an example:
float floatMaxValue = Float.MAX_VALUE;
float subtractedMaxValue = Float.MAX_VALUE - 1.0f;
System.out.println(floatMaxValue);
System.out.println(subtractedMaxValue);
Assert.assertTrue(floatMaxValue == subtractedMaxValue); // return true even false expected
Could someone explain me why this happens? I guess is some magic with floating point.