Skip to content

Commit a349390

Browse files
authored
Unrolled build for #149238
Rollup merge of #149238 - RalfJung:clamp-signed-zeros, r=Amanieu float::clamp: make treatment of signed zeros unspecified Fixes #83984 by explicitly documenting that we do not specify the treatment of signed zeros in `clamp`. `@rust-lang/libs-api` Is this what you'd like to see? Cc `@tgross35` `@thomcc`
2 parents a417515 + 69d3218 commit a349390

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

library/core/src/num/f128.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,8 @@ impl f128 {
12381238
/// less than `min`. Otherwise this returns `self`.
12391239
///
12401240
/// Note that this function returns NaN if the initial value was NaN as
1241-
/// well.
1241+
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
1242+
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
12421243
///
12431244
/// # Panics
12441245
///
@@ -1255,6 +1256,12 @@ impl f128 {
12551256
/// assert!((0.0f128).clamp(-2.0, 1.0) == 0.0);
12561257
/// assert!((2.0f128).clamp(-2.0, 1.0) == 1.0);
12571258
/// assert!((f128::NAN).clamp(-2.0, 1.0).is_nan());
1259+
///
1260+
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
1261+
/// assert!((0.0f128).clamp(-0.0, -0.0) == 0.0);
1262+
/// assert!((1.0f128).clamp(-0.0, 0.0) == 0.0);
1263+
/// // This is definitely a negative zero.
1264+
/// assert!((-1.0f128).clamp(-0.0, 1.0).is_sign_negative());
12581265
/// # }
12591266
/// ```
12601267
#[inline]

library/core/src/num/f16.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,8 @@ impl f16 {
12171217
/// less than `min`. Otherwise this returns `self`.
12181218
///
12191219
/// Note that this function returns NaN if the initial value was NaN as
1220-
/// well.
1220+
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
1221+
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
12211222
///
12221223
/// # Panics
12231224
///
@@ -1233,6 +1234,12 @@ impl f16 {
12331234
/// assert!((0.0f16).clamp(-2.0, 1.0) == 0.0);
12341235
/// assert!((2.0f16).clamp(-2.0, 1.0) == 1.0);
12351236
/// assert!((f16::NAN).clamp(-2.0, 1.0).is_nan());
1237+
///
1238+
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
1239+
/// assert!((0.0f16).clamp(-0.0, -0.0) == 0.0);
1240+
/// assert!((1.0f16).clamp(-0.0, 0.0) == 0.0);
1241+
/// // This is definitely a negative zero.
1242+
/// assert!((-1.0f16).clamp(-0.0, 1.0).is_sign_negative());
12361243
/// # }
12371244
/// ```
12381245
#[inline]

library/core/src/num/f32.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,8 @@ impl f32 {
13971397
/// less than `min`. Otherwise this returns `self`.
13981398
///
13991399
/// Note that this function returns NaN if the initial value was NaN as
1400-
/// well.
1400+
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
1401+
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
14011402
///
14021403
/// # Panics
14031404
///
@@ -1410,6 +1411,12 @@ impl f32 {
14101411
/// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
14111412
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
14121413
/// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
1414+
///
1415+
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
1416+
/// assert!((0.0f32).clamp(-0.0, -0.0) == 0.0);
1417+
/// assert!((1.0f32).clamp(-0.0, 0.0) == 0.0);
1418+
/// // This is definitely a negative zero.
1419+
/// assert!((-1.0f32).clamp(-0.0, 1.0).is_sign_negative());
14131420
/// ```
14141421
#[must_use = "method returns a new number and does not mutate the original value"]
14151422
#[stable(feature = "clamp", since = "1.50.0")]

library/core/src/num/f64.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,8 @@ impl f64 {
13951395
/// less than `min`. Otherwise this returns `self`.
13961396
///
13971397
/// Note that this function returns NaN if the initial value was NaN as
1398-
/// well.
1398+
/// well. If the result is zero and among the three inputs `self`, `min`, and `max` there are
1399+
/// zeros with different sign, either `0.0` or `-0.0` is returned non-deterministically.
13991400
///
14001401
/// # Panics
14011402
///
@@ -1408,6 +1409,12 @@ impl f64 {
14081409
/// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0);
14091410
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
14101411
/// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan());
1412+
///
1413+
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
1414+
/// assert!((0.0f64).clamp(-0.0, -0.0) == 0.0);
1415+
/// assert!((1.0f64).clamp(-0.0, 0.0) == 0.0);
1416+
/// // This is definitely a negative zero.
1417+
/// assert!((-1.0f64).clamp(-0.0, 1.0).is_sign_negative());
14111418
/// ```
14121419
#[must_use = "method returns a new number and does not mutate the original value"]
14131420
#[stable(feature = "clamp", since = "1.50.0")]

0 commit comments

Comments
 (0)