title: Different float values for same bytes on JVM/CLR
body: <p>I'm porting a program originally written in VB.NET to Java. I'm reading from a file which stores 32 bit floats in little endian order.</p>
  
  <p>The original program does this:</p>
  
  <pre><code>Dim br As BinaryReader = ...
  Dim f_vb As Single = br.ReadSingle
  </code></pre>
  
  <p>Java is big endian, so I reverse the bytes before converting to a float.</p>
  
  <pre><code>RandomAccessFile raf = // ...
  int i = raf.readInt();
  int bigEndian = Integer.reverseBytes(i);
  float f_java = Float.intBitsToFloat(bigEndian);
  </code></pre>
  
  <p>As far as I can tell, <code>f_vb</code> and <code>f_java</code> contain the same bits. That is, <code>BitConverter.ToInt32</code> on <code>f_vb</code> and <code>Float.floatToIntBits</code> (and <code>floatToRawIntBits</code>) on <code>f_java</code> give the same thing. However, the floats are not equal. For example, let <code>bigEndian == 0x4969F52F</code>. Java will report <code>958290.94</code>, and VB.NET will report <code>958290.938</code>. I'm guessing this comes from a difference in the way the JVM and CLR handle floating point numbers, but I don't know enough about floating point issues to figure out why. This loss of precision is causing trouble down the line, so I'd like to identify the source.</p>