Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,8 @@ impl f128 {
/// less than `min`. Otherwise this returns `self`.
///
/// Note that this function returns NaN if the initial value was NaN as
/// well.
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
///
/// # Panics
///
Expand All @@ -1253,6 +1254,12 @@ impl f128 {
/// assert!((0.0f128).clamp(-2.0, 1.0) == 0.0);
/// assert!((2.0f128).clamp(-2.0, 1.0) == 1.0);
/// assert!((f128::NAN).clamp(-2.0, 1.0).is_nan());
///
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
/// assert!((0.0f128).clamp(-0.0, -0.0) == 0.0);
/// assert!((1.0f128).clamp(-0.0, 0.0) == 0.0);
/// // This is definitely a negative zero.
/// assert!((-1.0f128).clamp(-0.0, 1.0).is_sign_negative());
/// # }
/// ```
#[inline]
Expand Down
9 changes: 8 additions & 1 deletion library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,8 @@ impl f16 {
/// less than `min`. Otherwise this returns `self`.
///
/// Note that this function returns NaN if the initial value was NaN as
/// well.
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
///
/// # Panics
///
Expand All @@ -1231,6 +1232,12 @@ impl f16 {
/// assert!((0.0f16).clamp(-2.0, 1.0) == 0.0);
/// assert!((2.0f16).clamp(-2.0, 1.0) == 1.0);
/// assert!((f16::NAN).clamp(-2.0, 1.0).is_nan());
///
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
/// assert!((0.0f16).clamp(-0.0, -0.0) == 0.0);
/// assert!((1.0f16).clamp(-0.0, 0.0) == 0.0);
/// // This is definitely a negative zero.
/// assert!((-1.0f16).clamp(-0.0, 1.0).is_sign_negative());
/// # }
/// ```
#[inline]
Expand Down
9 changes: 8 additions & 1 deletion library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,8 @@ impl f32 {
/// less than `min`. Otherwise this returns `self`.
///
/// Note that this function returns NaN if the initial value was NaN as
/// well.
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
///
/// # Panics
///
Expand All @@ -1408,6 +1409,12 @@ impl f32 {
/// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
/// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
///
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
/// assert!((0.0f32).clamp(-0.0, -0.0) == 0.0);
/// assert!((1.0f32).clamp(-0.0, 0.0) == 0.0);
/// // This is definitely a negative zero.
/// assert!((-1.0f32).clamp(-0.0, 1.0).is_sign_negative());
/// ```
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "clamp", since = "1.50.0")]
Expand Down
9 changes: 8 additions & 1 deletion library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,8 @@ impl f64 {
/// less than `min`. Otherwise this returns `self`.
///
/// Note that this function returns NaN if the initial value was NaN as
/// well.
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
///
/// # Panics
///
Expand All @@ -1406,6 +1407,12 @@ impl f64 {
/// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0);
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
/// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan());
///
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
/// assert!((0.0f64).clamp(-0.0, -0.0) == 0.0);
/// assert!((1.0f64).clamp(-0.0, 0.0) == 0.0);
/// // This is definitely a negative zero.
/// assert!((-1.0f64).clamp(-0.0, 1.0).is_sign_negative());
/// ```
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "clamp", since = "1.50.0")]
Expand Down
Loading