[records] equality on float / double components
forax at univ-mlv.fr
Wed Dec 6 18:51:38 UTC 2017
> De: "Paul Sandoz" <paul.sandoz at oracle.com>
> À: "Kevin Bourrillion" <kevinb at google.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Mercredi 6 Décembre 2017 19:49:08
> Objet: Re: [records] equality on float / double components
>> On 6 Dec 2017, at 10:22, Kevin Bourrillion < [ mailto:kevinb at google.com |
>> kevinb at google.com ] > wrote:
>> I'd strongly expect this to behave exactly as Float.equals() does. The +0.0/-0.0
>> problem exists but is nothing new.
> I concur. Float/Double.equals/compare is also used for float/double array
> equals and compare.
>> On Wed, Dec 6, 2017 at 1:07 PM, Brian Goetz < [ mailto:brian.goetz at oracle.com |
>> brian.goetz at oracle.com ] > wrote:
>>> It's time to play everyone's favorite game show, "What about NaN".
>>> If we have a record:
>>> record Foo(float f);
>>> We would like Object.equals() to be reflexive, symmetric, and transitive. But if
>>> we define equals() in the obvious way (delegating to float==), then `new
>>> Foo(Float.NaN`) would not be equal to itself.
>>> If we delegate instead to `Float.compare(this.f, that.f)`, the NaN problem goes
>>> away (though comparison becomes modestly more expensive), but now +0 and -0 are
>>> distinguished (== treats them the same.)
>> Kevin Bourrillion | Java Librarian | Google, Inc. | [ mailto:kevinb at google.com |
>> kevinb at google.com ]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the amber-spec-experts