So I have BigDecimal holding value 0.99 and I invoke:
- Float.toHexString(rationalNumber.floatValue()) I get 0x1.fae148p-1
- Double.toHexString(rationalNumber.doubleValue()) I get 0x1.fae147ae147aep-1
I'm thinking since we are representing a small number like 0.99 we should get the same hex value regardless. Agree?
Code (failing test):
@Test public void testDelta() {
BigDecimal rationalNumber = new BigDecimal("0.99").setScale(2,BigDecimal.ROUND_DOWN);
String hexFromFloat = Float.toHexString(rationalNumber.floatValue());
String hexFromDouble = Double.toHexString(rationalNumber.doubleValue());
String hexFromFloatMsg = rationalNumber.floatValue() + " = " + hexFromFloat;
String hexFromDoubleMsg = rationalNumber.doubleValue() + " = " + hexFromDouble;
Assert.assertEquals(hexFromFloatMsg + ", " + hexFromDoubleMsg, hexFromDouble, hexFromFloat);
}
Output:
org.junit.ComparisonFailure: 0.99 = 0x1.fae148p-1, 0.99 = 0x1.fae147ae147aep-1
Expected :0x1.fae147ae147aep-1
Actual :0x1.fae148p-1