[lworld] RFR: 8298659: [lworld] ValueObject isSubstutitable comparison of float/double should use raw bits

Roger Riggs rriggs at openjdk.org
Thu Feb 8 15:36:09 UTC 2024


On Wed, 7 Feb 2024 22:32:28 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> Update the substitutability implementation to match the new JLS for JEP 401.
>> Float and double values should be compared for equality using the raw bits.
>
> src/java.base/share/classes/java/lang/runtime/ObjectMethods.java line 183:
> 
>> 181:     private static boolean eq(long a, long b) { return a == b; }
>> 182:     private static boolean eq(float a, float b) {
>> 183:         return Float.floatToRawIntBits(a) == Float.floatToRawIntBits(b);
> 
> `ObjectMethods` are used for records as well and so these methods should not be modified.  Instead I suggest to add new methods in `ValueObjectMethods` class for value object substutitability comparison of float/double.

I'm beginning to doubt the wisdom of a difference in field comparisons between value objects and records (and the `==` operator).

-------------

PR Review Comment: https://git.openjdk.org/valhalla/pull/998#discussion_r1483174418



More information about the valhalla-dev mailing list