diff --git a/src/java.base/share/classes/java/lang/Double.java b/src/java.base/share/classes/java/lang/Double.java index 729adcf5b03..c25468ed666 100644 --- a/src/java.base/share/classes/java/lang/Double.java +++ b/src/java.base/share/classes/java/lang/Double.java @@ -790,7 +790,15 @@ public final class Double extends Number * #doubleToLongBits(double)} returns the identical * {@code long} value when applied to each. * - *

Note that in most cases, for two instances of class + * @apiNote + * This method is defined in terms of {@link + * #doubleToLongBits(double)} rather than the {@code ==} operator + * on {@code double} values since the {@code ==} operator does + * not define an equivalence relation and to satisfy the + * {@linkplain Object#equals equals contract} an equivalence + * relation must be implemented. + * + * However, in most cases, for two instances of class * {@code Double}, {@code d1} and {@code d2}, the * value of {@code d1.equals(d2)} is {@code true} if and * only if @@ -800,23 +808,48 @@ public final class Double extends Number * * *

also has the value {@code true}. However, there are two - * exceptions: + * exceptions where the properties of an equivalence relations are + * not satisfied by {@code ==}: *

- * This definition allows hash tables to operate properly. + * + * Despite not defining an equivalence relation, the semantics of + * the IEEE 754 {@code ==} operator were deliberately designed to + * meet other needs of numerical computation. + * + * By defining an equivalence relation largely consistent with the + * {@code ==} operator, this method allows hash tables on {@code + * Double} objects to operate properly while reducing surprising + * behavior. + * * @param obj the object to compare with. * @return {@code true} if the objects are the same; * {@code false} otherwise. * @see java.lang.Double#doubleToLongBits(double) + * @jls 4.2.3 Floating-Point Types, Formats, and Values + * @jls 4.2.4. Floating-Point Operations + * @jls 15.21.1 Numerical Equality Operators == and != */ public boolean equals(Object obj) { return (obj instanceof Double) @@ -968,19 +1001,29 @@ public final class Double extends Number public static native double longBitsToDouble(long bits); /** - * Compares two {@code Double} objects numerically. There - * are two ways in which comparisons performed by this method - * differ from those performed by the Java language numerical - * comparison operators ({@code <, <=, ==, >=, >}) - * when applied to primitive {@code double} values: - *