Skip to content

Commit b8a3f31

Browse files
authored
Unrolled build for #149563
Rollup merge of #149563 - RalfJung:f-min-max, r=tgross35 f*::min/max: fix comparing with libm and IEEE operations What we document actually doesn't match what libm does any more, libm got "fixed"/changed in https://sourceware.org/bugzilla/show_bug.cgi?id=20947. So better remove the remark. Instead, explicitly call out that this is a mix of `minNum` and `minimumNumber`. Also fix the intrinsics which incorrectly claimed to be like `minNum`, but their intended SNaN behavior is actually different from that. r? `@tgross35`
2 parents b4f1098 + 2421920 commit b8a3f31

File tree

5 files changed

+88
-80
lines changed

5 files changed

+88
-80
lines changed

library/core/src/intrinsics/mod.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,9 +2949,9 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
29492949

29502950
/// Returns the minimum of two `f16` values, ignoring NaN.
29512951
///
2952-
/// This behaves like IEEE 754-2008 minNum. In particular:
2953-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
2954-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
2952+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
2953+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
2954+
/// and `-0.0`), either input may be returned non-deterministically.
29552955
///
29562956
/// Note that, unlike most intrinsics, this is safe to call;
29572957
/// it does not require an `unsafe` block.
@@ -2965,9 +2965,9 @@ pub const fn minnumf16(x: f16, y: f16) -> f16;
29652965

29662966
/// Returns the minimum of two `f32` values, ignoring NaN.
29672967
///
2968-
/// This behaves like IEEE 754-2008 minNum. In particular:
2969-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
2970-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
2968+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
2969+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
2970+
/// and `-0.0`), either input may be returned non-deterministically.
29712971
///
29722972
/// Note that, unlike most intrinsics, this is safe to call;
29732973
/// it does not require an `unsafe` block.
@@ -2982,9 +2982,9 @@ pub const fn minnumf32(x: f32, y: f32) -> f32;
29822982

29832983
/// Returns the minimum of two `f64` values, ignoring NaN.
29842984
///
2985-
/// This behaves like IEEE 754-2008 minNum. In particular:
2986-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
2987-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
2985+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
2986+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
2987+
/// and `-0.0`), either input may be returned non-deterministically.
29882988
///
29892989
/// Note that, unlike most intrinsics, this is safe to call;
29902990
/// it does not require an `unsafe` block.
@@ -2999,9 +2999,9 @@ pub const fn minnumf64(x: f64, y: f64) -> f64;
29992999

30003000
/// Returns the minimum of two `f128` values, ignoring NaN.
30013001
///
3002-
/// This behaves like IEEE 754-2008 minNum. In particular:
3003-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3004-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3002+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
3003+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
3004+
/// and `-0.0`), either input may be returned non-deterministically.
30053005
///
30063006
/// Note that, unlike most intrinsics, this is safe to call;
30073007
/// it does not require an `unsafe` block.
@@ -3115,9 +3115,9 @@ pub const fn minimumf128(x: f128, y: f128) -> f128 {
31153115

31163116
/// Returns the maximum of two `f16` values, ignoring NaN.
31173117
///
3118-
/// This behaves like IEEE 754-2008 maxNum. In particular:
3119-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3120-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3118+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
3119+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
3120+
/// and `-0.0`), either input may be returned non-deterministically.
31213121
///
31223122
/// Note that, unlike most intrinsics, this is safe to call;
31233123
/// it does not require an `unsafe` block.
@@ -3131,9 +3131,9 @@ pub const fn maxnumf16(x: f16, y: f16) -> f16;
31313131

31323132
/// Returns the maximum of two `f32` values, ignoring NaN.
31333133
///
3134-
/// This behaves like IEEE 754-2008 maxNum. In particular:
3135-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3136-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3134+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
3135+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
3136+
/// and `-0.0`), either input may be returned non-deterministically.
31373137
///
31383138
/// Note that, unlike most intrinsics, this is safe to call;
31393139
/// it does not require an `unsafe` block.
@@ -3148,9 +3148,9 @@ pub const fn maxnumf32(x: f32, y: f32) -> f32;
31483148

31493149
/// Returns the maximum of two `f64` values, ignoring NaN.
31503150
///
3151-
/// This behaves like IEEE 754-2008 maxNum. In particular:
3152-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3153-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3151+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
3152+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
3153+
/// and `-0.0`), either input may be returned non-deterministically.
31543154
///
31553155
/// Note that, unlike most intrinsics, this is safe to call;
31563156
/// it does not require an `unsafe` block.
@@ -3165,9 +3165,9 @@ pub const fn maxnumf64(x: f64, y: f64) -> f64;
31653165

31663166
/// Returns the maximum of two `f128` values, ignoring NaN.
31673167
///
3168-
/// This behaves like IEEE 754-2008 maxNum. In particular:
3169-
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3170-
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3168+
/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
3169+
/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
3170+
/// and `-0.0`), either input may be returned non-deterministically.
31713171
///
31723172
/// Note that, unlike most intrinsics, this is safe to call;
31733173
/// it does not require an `unsafe` block.

library/core/src/num/f128.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,15 @@ impl f128 {
694694

695695
/// Returns the maximum of the two numbers, ignoring NaN.
696696
///
697-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
698-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
699-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
700-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
697+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
698+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
699+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
700+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
701+
/// non-deterministically.
701702
///
702-
/// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs;
703-
/// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity.
704-
/// This also matches the behavior of libm’s `fmax`.
703+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `maximumNumber`, treating all
704+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
705+
/// follows the IEEE 754-2008 semantics for `maxNum`.
705706
///
706707
/// ```
707708
/// #![feature(f128)]
@@ -725,14 +726,15 @@ impl f128 {
725726

726727
/// Returns the minimum of the two numbers, ignoring NaN.
727728
///
728-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
729-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
730-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
731-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
729+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
730+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
731+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
732+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
733+
/// non-deterministically.
732734
///
733-
/// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs;
734-
/// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity.
735-
/// This also matches the behavior of libm’s `fmin`.
735+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `minimumNumber`, treating all
736+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
737+
/// follows the IEEE 754-2008 semantics for `minNum`.
736738
///
737739
/// ```
738740
/// #![feature(f128)]

library/core/src/num/f16.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,15 @@ impl f16 {
687687

688688
/// Returns the maximum of the two numbers, ignoring NaN.
689689
///
690-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
691-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
692-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
693-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
690+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
691+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
692+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
693+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
694+
/// non-deterministically.
694695
///
695-
/// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs;
696-
/// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity.
697-
/// This also matches the behavior of libm’s `fmax`.
696+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `maximumNumber`, treating all
697+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
698+
/// follows the IEEE 754-2008 semantics for `maxNum`.
698699
///
699700
/// ```
700701
/// #![feature(f16)]
@@ -717,14 +718,15 @@ impl f16 {
717718

718719
/// Returns the minimum of the two numbers, ignoring NaN.
719720
///
720-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
721-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
722-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
723-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
721+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
722+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
723+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
724+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
725+
/// non-deterministically.
724726
///
725-
/// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs;
726-
/// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity.
727-
/// This also matches the behavior of libm’s `fmin`.
727+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `minimumNumber`, treating all
728+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
729+
/// follows the IEEE 754-2008 semantics for `minNum`.
728730
///
729731
/// ```
730732
/// #![feature(f16)]

library/core/src/num/f32.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,15 @@ impl f32 {
897897

898898
/// Returns the maximum of the two numbers, ignoring NaN.
899899
///
900-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
901-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
902-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
903-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
900+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
901+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
902+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
903+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
904+
/// non-deterministically.
904905
///
905-
/// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs;
906-
/// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity.
907-
/// This also matches the behavior of libm’s `fmax`.
906+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `maximumNumber`, treating all
907+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
908+
/// follows the IEEE 754-2008 semantics for `maxNum`.
908909
///
909910
/// ```
910911
/// let x = 1.0f32;
@@ -923,14 +924,15 @@ impl f32 {
923924

924925
/// Returns the minimum of the two numbers, ignoring NaN.
925926
///
926-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
927-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
928-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
929-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
927+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
928+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
929+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
930+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
931+
/// non-deterministically.
930932
///
931-
/// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs;
932-
/// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity.
933-
/// This also matches the behavior of libm’s `fmin`.
933+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `minimumNumber`, treating all
934+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
935+
/// follows the IEEE 754-2008 semantics for `minNum`.
934936
///
935937
/// ```
936938
/// let x = 1.0f32;

library/core/src/num/f64.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -915,14 +915,15 @@ impl f64 {
915915

916916
/// Returns the maximum of the two numbers, ignoring NaN.
917917
///
918-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
919-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
920-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
921-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
918+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
919+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
920+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
921+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
922+
/// non-deterministically.
922923
///
923-
/// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs;
924-
/// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity.
925-
/// This also matches the behavior of libm’s `fmax`.
924+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `maximumNumber`, treating all
925+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
926+
/// follows the IEEE 754-2008 semantics for `maxNum`.
926927
///
927928
/// ```
928929
/// let x = 1.0_f64;
@@ -941,14 +942,15 @@ impl f64 {
941942

942943
/// Returns the minimum of the two numbers, ignoring NaN.
943944
///
944-
/// If exactly one of the arguments is NaN, then the other argument is returned. If both
945-
/// arguments are NaN, the return value is NaN, with the bit pattern picked using the usual
946-
/// [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs compare equal (such
947-
/// as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
945+
/// If exactly one of the arguments is NaN (quiet or signaling), then the other argument is
946+
/// returned. If both arguments are NaN, the return value is NaN, with the bit pattern picked
947+
/// using the usual [rules for arithmetic operations](f32#nan-bit-patterns). If the inputs
948+
/// compare equal (such as for the case of `+0.0` and `-0.0`), either input may be returned
949+
/// non-deterministically.
948950
///
949-
/// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs;
950-
/// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity.
951-
/// This also matches the behavior of libm’s `fmin`.
951+
/// The handling of NaNs follows the IEEE 754-2019 semantics for `minimumNumber`, treating all
952+
/// NaNs the same way to ensure the operation is associative. The handling of signed zeros
953+
/// follows the IEEE 754-2008 semantics for `minNum`.
952954
///
953955
/// ```
954956
/// let x = 1.0_f64;

0 commit comments

Comments
 (0)