2

I had an issue with some NaNs that came from 0/0 not being Canonical in a system I was making and I reduced the problem to this case.

public class Test {
    public static void main(String[] args){
        Float zero = Float.intBitsToFloat(0);
        // Passes
        assert Float.floatToRawIntBits(zero) == Float.floatToRawIntBits(0f);
        // Fails
        assert Float.floatToRawIntBits(zero / zero) ==  Float.floatToRawIntBits(0f / 0f); 
    }
}

This is quite bizarre to me. Additionally when debugging with Intellij, watch expressions respond like you would expect; both assertions pass.

I am using openjdk version "1.8.0_131".

TheThirdOne
  • 427
  • 3
  • 10
  • @Vivick, my problem is with the actual bit representations. Because I am working directly with the bit representations in my project, the type of NaN result matters. – TheThirdOne Sep 26 '17 at 19:59
  • @shmosel, While I agree with this being marked as a duplicate, the other questions don't answer my base question of why the two are different. It appears that its hardware multiplication vs constant folding, but that is quite a satisfactory answer. Especially because 0xFFC00000 is not canonical and so hardware shouldn't produce it anyway from 0/0. – TheThirdOne Sep 26 '17 at 20:17

0 Answers0