I'm trying to get the mantissa of a float (just to learn), but it isn't working as expected.
The mantissa of say 5.3 is 53, right? I tried this code:
System.out.println(Float.floatToIntBits(5.3f) & 0x7FFFFF);
It printed 2726298
. Shouldn't it remove the exponent bits and leave 53? I tried plenty of things, but this always happens. What am I doing wrong here?
From the article IBM: Java's new math. Floating-point numbers (in Russian) the simplest way to get the mantissa is:
public static double getMantissa(double x) {
int exponent = Math.getExponent(x);
return x / Math.pow(2, exponent);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With