Skip to content

Commit 60be663

Browse files
authored
Rollup merge of #149477 - RalfJung:minimum-maximum, r=tgross35
float::maximum/minimum: make docs more streamlined This does with `maximum`/`minimum` what #149475 did with `max`/`min`: first a self-contained description of the semantics, then comparing with other operations. It also makes the wording consistent with those other functions. Previously we had some of the semantics below the examples for some reason, and we repeated "If one of the arguments is NaN, then NaN is returned"; that has been streamlined as well. r? `@tgross35`
2 parents 7850fc4 + e773409 commit 60be663

File tree

4 files changed

+72
-72
lines changed

4 files changed

+72
-72
lines changed

library/core/src/num/f128.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,15 @@ impl f128 {
756756

757757
/// Returns the maximum of the two numbers, propagating NaN.
758758
///
759-
/// This returns NaN when *either* argument is NaN, as opposed to
760-
/// [`f128::max`] which only returns NaN when *both* arguments are NaN.
759+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
760+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
761+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
762+
/// non-NaN inputs.
763+
///
764+
/// This is in contrast to [`f128::max`] which only returns NaN when *both* arguments are NaN,
765+
/// and which does not reliably order `-0.0` and `+0.0`.
766+
///
767+
/// This follows the IEEE 754-2019 semantics for `maximum`.
761768
///
762769
/// ```
763770
/// #![feature(f128)]
@@ -772,13 +779,6 @@ impl f128 {
772779
/// assert!(x.maximum(f128::NAN).is_nan());
773780
/// # }
774781
/// ```
775-
///
776-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
777-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
778-
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
779-
///
780-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
781-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
782782
#[inline]
783783
#[unstable(feature = "f128", issue = "116909")]
784784
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
@@ -789,8 +789,15 @@ impl f128 {
789789

790790
/// Returns the minimum of the two numbers, propagating NaN.
791791
///
792-
/// This returns NaN when *either* argument is NaN, as opposed to
793-
/// [`f128::min`] which only returns NaN when *both* arguments are NaN.
792+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
793+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
794+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
795+
/// non-NaN inputs.
796+
///
797+
/// This is in contrast to [`f128::min`] which only returns NaN when *both* arguments are NaN,
798+
/// and which does not reliably order `-0.0` and `+0.0`.
799+
///
800+
/// This follows the IEEE 754-2019 semantics for `minimum`.
794801
///
795802
/// ```
796803
/// #![feature(f128)]
@@ -805,13 +812,6 @@ impl f128 {
805812
/// assert!(x.minimum(f128::NAN).is_nan());
806813
/// # }
807814
/// ```
808-
///
809-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
810-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
811-
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
812-
///
813-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
814-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
815815
#[inline]
816816
#[unstable(feature = "f128", issue = "116909")]
817817
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]

library/core/src/num/f16.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,15 @@ impl f16 {
747747

748748
/// Returns the maximum of the two numbers, propagating NaN.
749749
///
750-
/// This returns NaN when *either* argument is NaN, as opposed to
751-
/// [`f16::max`] which only returns NaN when *both* arguments are NaN.
750+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
751+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
752+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
753+
/// non-NaN inputs.
754+
///
755+
/// This is in contrast to [`f16::max`] which only returns NaN when *both* arguments are NaN,
756+
/// and which does not reliably order `-0.0` and `+0.0`.
757+
///
758+
/// This follows the IEEE 754-2019 semantics for `maximum`.
752759
///
753760
/// ```
754761
/// #![feature(f16)]
@@ -762,13 +769,6 @@ impl f16 {
762769
/// assert!(x.maximum(f16::NAN).is_nan());
763770
/// # }
764771
/// ```
765-
///
766-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
767-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
768-
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
769-
///
770-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
771-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
772772
#[inline]
773773
#[unstable(feature = "f16", issue = "116909")]
774774
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
@@ -779,8 +779,15 @@ impl f16 {
779779

780780
/// Returns the minimum of the two numbers, propagating NaN.
781781
///
782-
/// This returns NaN when *either* argument is NaN, as opposed to
783-
/// [`f16::min`] which only returns NaN when *both* arguments are NaN.
782+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
783+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
784+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
785+
/// non-NaN inputs.
786+
///
787+
/// This is in contrast to [`f16::min`] which only returns NaN when *both* arguments are NaN,
788+
/// and which does not reliably order `-0.0` and `+0.0`.
789+
///
790+
/// This follows the IEEE 754-2019 semantics for `minimum`.
784791
///
785792
/// ```
786793
/// #![feature(f16)]
@@ -794,13 +801,6 @@ impl f16 {
794801
/// assert!(x.minimum(f16::NAN).is_nan());
795802
/// # }
796803
/// ```
797-
///
798-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
799-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
800-
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
801-
///
802-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
803-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
804804
#[inline]
805805
#[unstable(feature = "f16", issue = "116909")]
806806
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]

library/core/src/num/f32.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,15 @@ impl f32 {
949949

950950
/// Returns the maximum of the two numbers, propagating NaN.
951951
///
952-
/// This returns NaN when *either* argument is NaN, as opposed to
953-
/// [`f32::max`] which only returns NaN when *both* arguments are NaN.
952+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
953+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
954+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
955+
/// non-NaN inputs.
956+
///
957+
/// This is in contrast to [`f32::max`] which only returns NaN when *both* arguments are NaN,
958+
/// and which does not reliably order `-0.0` and `+0.0`.
959+
///
960+
/// This follows the IEEE 754-2019 semantics for `maximum`.
954961
///
955962
/// ```
956963
/// #![feature(float_minimum_maximum)]
@@ -960,13 +967,6 @@ impl f32 {
960967
/// assert_eq!(x.maximum(y), y);
961968
/// assert!(x.maximum(f32::NAN).is_nan());
962969
/// ```
963-
///
964-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
965-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
966-
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
967-
///
968-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
969-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
970970
#[must_use = "this returns the result of the comparison, without modifying either input"]
971971
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
972972
#[inline]
@@ -976,8 +976,15 @@ impl f32 {
976976

977977
/// Returns the minimum of the two numbers, propagating NaN.
978978
///
979-
/// This returns NaN when *either* argument is NaN, as opposed to
980-
/// [`f32::min`] which only returns NaN when *both* arguments are NaN.
979+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
980+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
981+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
982+
/// non-NaN inputs.
983+
///
984+
/// This is in contrast to [`f32::min`] which only returns NaN when *both* arguments are NaN,
985+
/// and which does not reliably order `-0.0` and `+0.0`.
986+
///
987+
/// This follows the IEEE 754-2019 semantics for `minimum`.
981988
///
982989
/// ```
983990
/// #![feature(float_minimum_maximum)]
@@ -987,13 +994,6 @@ impl f32 {
987994
/// assert_eq!(x.minimum(y), x);
988995
/// assert!(x.minimum(f32::NAN).is_nan());
989996
/// ```
990-
///
991-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
992-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
993-
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
994-
///
995-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
996-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
997997
#[must_use = "this returns the result of the comparison, without modifying either input"]
998998
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
999999
#[inline]

library/core/src/num/f64.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,15 @@ impl f64 {
967967

968968
/// Returns the maximum of the two numbers, propagating NaN.
969969
///
970-
/// This returns NaN when *either* argument is NaN, as opposed to
971-
/// [`f64::max`] which only returns NaN when *both* arguments are NaN.
970+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
971+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
972+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
973+
/// non-NaN inputs.
974+
///
975+
/// This is in contrast to [`f64::max`] which only returns NaN when *both* arguments are NaN,
976+
/// and which does not reliably order `-0.0` and `+0.0`.
977+
///
978+
/// This follows the IEEE 754-2019 semantics for `maximum`.
972979
///
973980
/// ```
974981
/// #![feature(float_minimum_maximum)]
@@ -978,13 +985,6 @@ impl f64 {
978985
/// assert_eq!(x.maximum(y), y);
979986
/// assert!(x.maximum(f64::NAN).is_nan());
980987
/// ```
981-
///
982-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
983-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
984-
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
985-
///
986-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
987-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
988988
#[must_use = "this returns the result of the comparison, without modifying either input"]
989989
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
990990
#[inline]
@@ -994,8 +994,15 @@ impl f64 {
994994

995995
/// Returns the minimum of the two numbers, propagating NaN.
996996
///
997-
/// This returns NaN when *either* argument is NaN, as opposed to
998-
/// [`f64::min`] which only returns NaN when *both* arguments are NaN.
997+
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
998+
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
999+
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
1000+
/// non-NaN inputs.
1001+
///
1002+
/// This is in contrast to [`f64::min`] which only returns NaN when *both* arguments are NaN,
1003+
/// and which does not reliably order `-0.0` and `+0.0`.
1004+
///
1005+
/// This follows the IEEE 754-2019 semantics for `minimum`.
9991006
///
10001007
/// ```
10011008
/// #![feature(float_minimum_maximum)]
@@ -1005,13 +1012,6 @@ impl f64 {
10051012
/// assert_eq!(x.minimum(y), x);
10061013
/// assert!(x.minimum(f64::NAN).is_nan());
10071014
/// ```
1008-
///
1009-
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
1010-
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
1011-
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
1012-
///
1013-
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
1014-
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
10151015
#[must_use = "this returns the result of the comparison, without modifying either input"]
10161016
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
10171017
#[inline]

0 commit comments

Comments
 (0)