Value object equality & floating-point values
forax at univ-mlv.fr
forax at univ-mlv.fr
Tue Feb 13 21:33:28 UTC 2024
----- Original Message -----
> From: "John Rose" <john.r.rose at oracle.com>
> To: "daniel smith" <daniel.smith at oracle.com>
> Cc: "valhalla-spec-experts" <valhalla-spec-experts at openjdk.java.net>, "Remi Forax" <forax at univ-mlv.fr>
> Sent: Tuesday, February 13, 2024 9:22:49 PM
> Subject: Re: Value object equality & floating-point values
> On 12 Feb 2024, at 13:00, Dan Smith wrote:
>
>>> For each `float` or `double` field in a value class, the constructor will
>>> generate normalization code
>
> Indeed we considered this, but consider the tradeoff:
>
> Benefit: Somebody who is looking very closely indeed at NaNs sees a different
> op== behavior. That person is pleased, yay!
>
> Cost: Everybody who stores floats and doubles in value classes sees object
> creation slow down due to branchy normalization logic, at least wherever
> hardware creates unpredictable NaNs and/or NaNs that don’t fit the Java model
> of “good” NaNs.
>
> The cost is too risky, just to please a few NaN-detectives.
It depends if the normalization is done at creation time or when == is executed.
For the latter, in most case, no non canonical NaN will be seen so it will be a branch non taken (especially if the test only branch for non-canonical NaNs).
Rémi
More information about the valhalla-spec-experts
mailing list