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

Chen Liang liach at openjdk.org
Fri Feb 9 16:58:04 UTC 2024


On Thu, 8 Feb 2024 15:33:29 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> 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).

I believe the discrepancy in `equals` and `==` is valid; value objects may contain reference pointers too, thus they still should be compared by `equals` instead of `==`. Having double fields act like reference fields is fine.

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

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



More information about the valhalla-dev mailing list