Question:
The Math class has a method:
public static long round(double a) {
if (a != 0x1.fffffffffffffp-2) // greatest double value less than 0.5
return (long)floor(a + 0.5d);
else
return 0;
}
Please tell me what kind of number is 0x1.fffffffffffffp-2. I don't get it 🙂
Answer:
This hexadecimal number 0.49999999999999994 is the largest number less than 0.5 that Java can represent. 0x1.ffffffffffff is 1.9999999999999998 in hexadecimal. p-2 means that it is multiplied by 2^-2 = 0.25 i.e. divided by 4. It's like an exponent (for example, 1.23e-5), only for hexadecimal numbers.