Skip to content

Commit 4882559

Browse files
committed
8367942: Add API note discussing Double.compareTo total order and IEEE 754 total order
Reviewed-by: rgiulietti
1 parent d0fe8f7 commit 4882559

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/java.base/share/classes/java/lang/Double.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,13 +1425,29 @@ public static long doubleToLongBits(double value) {
14251425
* This method chooses to define positive zero ({@code +0.0d}),
14261426
* to be greater than negative zero ({@code -0.0d}).
14271427
* </ul>
1428-
1428+
*
14291429
* This ensures that the <i>natural ordering</i> of {@code Double}
14301430
* objects imposed by this method is <i>consistent with
14311431
* equals</i>; see {@linkplain ##equivalenceRelation this
14321432
* discussion for details of floating-point comparison and
14331433
* ordering}.
14341434
*
1435+
* @apiNote
1436+
* The inclusion of a total order idiom in the Java SE API
1437+
* predates the inclusion of that functionality in the IEEE 754
1438+
* standard. The ordering of the totalOrder predicate chosen by
1439+
* IEEE 754 differs from the total order chosen by this method.
1440+
* While this method treats all NaN representations as being in
1441+
* the same equivalence class, the IEEE 754 total order defines an
1442+
* ordering based on the bit patterns of the NaN among the
1443+
* different NaN representations. The IEEE 754 order regards
1444+
* "negative" NaN representations, that is NaN representations
1445+
* whose sign bit is set, to be less than any finite or infinite
1446+
* value and less than any "positive" NaN. In addition, the IEEE
1447+
* order regards all positive NaN values as greater than positive
1448+
* infinity. See the IEEE 754 standard for full details of its
1449+
* total ordering.
1450+
*
14351451
* @param anotherDouble the {@code Double} to be compared.
14361452
* @return the value {@code 0} if {@code anotherDouble} is
14371453
* numerically equal to this {@code Double}; a value

src/java.base/share/classes/java/lang/Float.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,10 @@ public static short floatToFloat16(float f) {
12531253
* discussion for details of floating-point comparison and
12541254
* ordering}.
12551255
*
1256+
* @apiNote
1257+
* For a discussion of differences between the total order of this
1258+
* method compared to the total order defined by the IEEE 754
1259+
* standard, see the note in {@link Double#compareTo(Double)}.
12561260
*
12571261
* @param anotherFloat the {@code Float} to be compared.
12581262
* @return the value {@code 0} if {@code anotherFloat} is

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,11 @@ public static Float16 shortBitsToFloat16(short bits) {
969969
* to be greater than negative zero.
970970
* </ul>
971971
*
972+
* @apiNote
973+
* For a discussion of differences between the total order of this
974+
* method compared to the total order defined by the IEEE 754
975+
* standard, see the note in {@link Double#compareTo(Double)}.
976+
*
972977
* @param anotherFloat16 the {@code Float16} to be compared.
973978
* @return the value {@code 0} if {@code anotherFloat16} is
974979
* numerically equal to this {@code Float16}; a value

0 commit comments

Comments
 (0)