[records] equality on float / double components
brian.goetz at oracle.com
Wed Dec 6 18:07:42 UTC 2017
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.)
More information about the amber-spec-observers