Numerical error on native float access

Ulf Zibis Ulf.Zibis at
Tue Apr 20 05:12:34 PDT 2010

Am 20.04.2010 09:02, schrieb Martin Buchholz:
> On Sat, Apr 17, 2010 at 15:37, Ulf Zibis<Ulf.Zibis at>  wrote:
>> There seems to be a bug in Float.intBitsToFloat(int) and/or
>> Float.floatToRawIntBits(float) and/or sun.misc.Unsafe.getInt/Float.
>> If I replace
>>         return
>> Float.intBitsToFloat(Integer.reverseBytes(unsafe.getInt(offset)));
>> with
>>         return reverseBytes(unsafe.getFloat(offset));
> It looks like you are accessing a float value using getInt,

Contrary, DirectFloat/DoubleBufferS#get/put() currently use get/putInt/Long.
My attempt is, to avoid this by shifting the swap mechanics to Unsafe class.

> which is breaking the rules.
> In any case, swapping bytes of floating point values is
> something no one is likely to care about.
> At least, I'm finding it hard to care.

Sounds not good.

I think we need a native byte swapping for float/double types to ensure 
correctness on little-endian machines for 

What you think?


More information about the nio-dev mailing list