mirror of
https://github.com/rust-lang/rust.git
synced 2026-01-25 07:48:44 +00:00
Rollup merge of #149477 - RalfJung:minimum-maximum, r=tgross35
float::maximum/minimum: make docs more streamlined This does with `maximum`/`minimum` what https://github.com/rust-lang/rust/pull/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`
This commit is contained in:
@@ -756,8 +756,15 @@ impl f128 {
|
||||
|
||||
/// Returns the maximum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f128::max`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f128::max`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(f128)]
|
||||
@@ -772,13 +779,6 @@ impl f128 {
|
||||
/// assert!(x.maximum(f128::NAN).is_nan());
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[inline]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
@@ -789,8 +789,15 @@ impl f128 {
|
||||
|
||||
/// Returns the minimum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f128::min`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f128::min`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(f128)]
|
||||
@@ -805,13 +812,6 @@ impl f128 {
|
||||
/// assert!(x.minimum(f128::NAN).is_nan());
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[inline]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
|
||||
@@ -747,8 +747,15 @@ impl f16 {
|
||||
|
||||
/// Returns the maximum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f16::max`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f16::max`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(f16)]
|
||||
@@ -762,13 +769,6 @@ impl f16 {
|
||||
/// assert!(x.maximum(f16::NAN).is_nan());
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[inline]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
@@ -779,8 +779,15 @@ impl f16 {
|
||||
|
||||
/// Returns the minimum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f16::min`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f16::min`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(f16)]
|
||||
@@ -794,13 +801,6 @@ impl f16 {
|
||||
/// assert!(x.minimum(f16::NAN).is_nan());
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[inline]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
|
||||
@@ -949,8 +949,15 @@ impl f32 {
|
||||
|
||||
/// Returns the maximum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f32::max`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f32::max`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(float_minimum_maximum)]
|
||||
@@ -960,13 +967,6 @@ impl f32 {
|
||||
/// assert_eq!(x.maximum(y), y);
|
||||
/// assert!(x.maximum(f32::NAN).is_nan());
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[must_use = "this returns the result of the comparison, without modifying either input"]
|
||||
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
#[inline]
|
||||
@@ -976,8 +976,15 @@ impl f32 {
|
||||
|
||||
/// Returns the minimum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f32::min`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f32::min`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(float_minimum_maximum)]
|
||||
@@ -987,13 +994,6 @@ impl f32 {
|
||||
/// assert_eq!(x.minimum(y), x);
|
||||
/// assert!(x.minimum(f32::NAN).is_nan());
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[must_use = "this returns the result of the comparison, without modifying either input"]
|
||||
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
#[inline]
|
||||
|
||||
@@ -967,8 +967,15 @@ impl f64 {
|
||||
|
||||
/// Returns the maximum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f64::max`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f64::max`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(float_minimum_maximum)]
|
||||
@@ -978,13 +985,6 @@ impl f64 {
|
||||
/// assert_eq!(x.maximum(y), y);
|
||||
/// assert!(x.maximum(f64::NAN).is_nan());
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `maximum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[must_use = "this returns the result of the comparison, without modifying either input"]
|
||||
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
#[inline]
|
||||
@@ -994,8 +994,15 @@ impl f64 {
|
||||
|
||||
/// Returns the minimum of the two numbers, propagating NaN.
|
||||
///
|
||||
/// This returns NaN when *either* argument is NaN, as opposed to
|
||||
/// [`f64::min`] which only returns NaN when *both* arguments are NaN.
|
||||
/// If at least one of the arguments is NaN, the return value is NaN, with the bit pattern
|
||||
/// picked using the usual [rules for arithmetic operations](f32#nan-bit-patterns). Furthermore,
|
||||
/// `-0.0` is considered to be less than `+0.0`, making this function fully deterministic for
|
||||
/// non-NaN inputs.
|
||||
///
|
||||
/// This is in contrast to [`f64::min`] which only returns NaN when *both* arguments are NaN,
|
||||
/// and which does not reliably order `-0.0` and `+0.0`.
|
||||
///
|
||||
/// This follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(float_minimum_maximum)]
|
||||
@@ -1005,13 +1012,6 @@ impl f64 {
|
||||
/// assert_eq!(x.minimum(y), x);
|
||||
/// assert!(x.minimum(f64::NAN).is_nan());
|
||||
/// ```
|
||||
///
|
||||
/// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser
|
||||
/// of the two numbers. For this operation, -0.0 is considered to be less than +0.0.
|
||||
/// Note that this follows the IEEE 754-2019 semantics for `minimum`.
|
||||
///
|
||||
/// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN
|
||||
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
|
||||
#[must_use = "this returns the result of the comparison, without modifying either input"]
|
||||
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user