On Mon, 9 Jan 2023 12:12:08 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> 
wrote:

>> For the other direction it uses the `floatToRawIntBits`: 
>> https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template#L148-L153
>> 
>> I think for symmatry we should keep it as is.
>
> I see - thanks for the explanation - the problem is with `floatToIntBits` vs 
> `floatToRawIntBits` in the "put" operation. The get operation is ok, but then 
> having asymmetry where we use a float VH in one case (get) but not in the 
> other (put) is not desirable.

@mcimadamore According to the spec, `floatToRawIntBits` and 
`doubleToRawLongBits` ensure that the original input bits are all preserved, 
even for NaN values.
On the other hand, the spec says that `intBitsToFloat` and `longBitsToDouble` 
only ensure a best effort in preserving the output bits of NaN values.
So I think `VarHandle` `get` and `put` do their best to preserve the bits, but 
no more than the underlying platform can possibly offer.
This behavior for floating-point values is not fully specified in `VarHandle`, 
so there's room for improvement in the doc.

-------------

PR: https://git.openjdk.org/jdk/pull/11840

Reply via email to