RFD: "equal" vs "equivalent" in Float.NaN, Double.NaN
Joseph D. Darcy
joe.darcy at oracle.com
Fri Nov 1 19:42:45 UTC 2024
On 11/1/2024 12:11 PM, Eirik Bjørsnøs wrote:
> Hi,
>
> Just an observation from a floating point layman:
>
> I noticed that Float and Double uses "It is equal to the value.." when
> describing various constant values like MIN_VALUE, MAX_VALUE etc.
A few releases back, a discussion of "quality, equivalence, and
comparison of floating-point values" was added to java.lang.Double:
https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Double.html#equivalenceRelation
That note discusses the topics in question.
>
> However, Float.NaN and Double.NaN instead uses "equivalent to":
>
> /**
> * A constant holding a Not-a-Number (NaN) value of type
> * {@code float}. It is /equivalent/ to the value returned by
> * {@code Float.intBitsToFloat(0x7fc00000)}.
> */
> public static final float NaN = 0.0f / 0.0f;
>
>
> Is this difference in terms deliberate and justified by there being
> more than one NaN bit pattern? Is the implementation allowed to return
> any NaN, since all NaNs are equivalent, even when not equal?
In terms of NaN, relevant factors are there are multiple bit patterns
than encode a NaN and a NaN is not equal to itself per the IEEE 754
standard.
HTH; cheers,
-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20241101/b23143b6/attachment.htm>
More information about the core-libs-dev
mailing list