RFD: "equal" vs "equivalent" in Float.NaN, Double.NaN

Eirik Bjørsnøs eirbjo at gmail.com
Fri Nov 1 19:11:22 UTC 2024


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.

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?

If not, would it perhaps be more appropriate to use "equal to" here as
well?

Cheers,
Eirik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20241101/b4755bdf/attachment.htm>


More information about the core-libs-dev mailing list