Skip to content

Commit fd218fe

Browse files
committed
intrinsics: clarify float min/max behavios for NaNs and signed zeros
1 parent c268b39 commit fd218fe

File tree

1 file changed

+56
-16
lines changed
  • library/core/src/intrinsics

1 file changed

+56
-16
lines changed

library/core/src/intrinsics/mod.rs

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

29502950
/// Returns the minimum (IEEE 754-2008 minNum) of two `f16` values.
29512951
///
2952+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
2953+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
2954+
///
29522955
/// Note that, unlike most intrinsics, this is safe to call;
29532956
/// it does not require an `unsafe` block.
29542957
/// Therefore, implementations must not require the user to uphold
29552958
/// any safety invariants.
29562959
///
2957-
/// The stabilized version of this intrinsic is
2958-
/// [`f16::min`]
2960+
/// The stabilized version of this intrinsic is [`f16::min`].
29592961
#[rustc_nounwind]
29602962
#[rustc_intrinsic]
29612963
pub const fn minnumf16(x: f16, y: f16) -> f16;
29622964

29632965
/// Returns the minimum (IEEE 754-2008 minNum) of two `f32` values.
29642966
///
2967+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
2968+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
2969+
///
29652970
/// Note that, unlike most intrinsics, this is safe to call;
29662971
/// it does not require an `unsafe` block.
29672972
/// Therefore, implementations must not require the user to uphold
29682973
/// any safety invariants.
29692974
///
2970-
/// The stabilized version of this intrinsic is
2971-
/// [`f32::min`]
2975+
/// The stabilized version of this intrinsic is [`f32::min`].
29722976
#[rustc_nounwind]
29732977
#[rustc_intrinsic_const_stable_indirect]
29742978
#[rustc_intrinsic]
29752979
pub const fn minnumf32(x: f32, y: f32) -> f32;
29762980

29772981
/// Returns the minimum (IEEE 754-2008 minNum) of two `f64` values.
29782982
///
2983+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
2984+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
2985+
///
29792986
/// Note that, unlike most intrinsics, this is safe to call;
29802987
/// it does not require an `unsafe` block.
29812988
/// Therefore, implementations must not require the user to uphold
29822989
/// any safety invariants.
29832990
///
2984-
/// The stabilized version of this intrinsic is
2985-
/// [`f64::min`]
2991+
/// The stabilized version of this intrinsic is [`f64::min`].
29862992
#[rustc_nounwind]
29872993
#[rustc_intrinsic_const_stable_indirect]
29882994
#[rustc_intrinsic]
29892995
pub const fn minnumf64(x: f64, y: f64) -> f64;
29902996

29912997
/// Returns the minimum (IEEE 754-2008 minNum) of two `f128` values.
29922998
///
2999+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3000+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3001+
///
29933002
/// Note that, unlike most intrinsics, this is safe to call;
29943003
/// it does not require an `unsafe` block.
29953004
/// Therefore, implementations must not require the user to uphold
29963005
/// any safety invariants.
29973006
///
2998-
/// The stabilized version of this intrinsic is
2999-
/// [`f128::min`]
3007+
/// The stabilized version of this intrinsic is [`f128::min`].
30003008
#[rustc_nounwind]
30013009
#[rustc_intrinsic]
30023010
pub const fn minnumf128(x: f128, y: f128) -> f128;
30033011

30043012
/// Returns the minimum (IEEE 754-2019 minimum) of two `f16` values.
30053013
///
3014+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3015+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3016+
///
30063017
/// Note that, unlike most intrinsics, this is safe to call;
30073018
/// it does not require an `unsafe` block.
30083019
/// Therefore, implementations must not require the user to uphold
@@ -3024,6 +3035,9 @@ pub const fn minimumf16(x: f16, y: f16) -> f16 {
30243035

30253036
/// Returns the minimum (IEEE 754-2019 minimum) of two `f32` values.
30263037
///
3038+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3039+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3040+
///
30273041
/// Note that, unlike most intrinsics, this is safe to call;
30283042
/// it does not require an `unsafe` block.
30293043
/// Therefore, implementations must not require the user to uphold
@@ -3045,6 +3059,9 @@ pub const fn minimumf32(x: f32, y: f32) -> f32 {
30453059

30463060
/// Returns the minimum (IEEE 754-2019 minimum) of two `f64` values.
30473061
///
3062+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3063+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3064+
///
30483065
/// Note that, unlike most intrinsics, this is safe to call;
30493066
/// it does not require an `unsafe` block.
30503067
/// Therefore, implementations must not require the user to uphold
@@ -3066,6 +3083,9 @@ pub const fn minimumf64(x: f64, y: f64) -> f64 {
30663083

30673084
/// Returns the minimum (IEEE 754-2019 minimum) of two `f128` values.
30683085
///
3086+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3087+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3088+
///
30693089
/// Note that, unlike most intrinsics, this is safe to call;
30703090
/// it does not require an `unsafe` block.
30713091
/// Therefore, implementations must not require the user to uphold
@@ -3087,60 +3107,71 @@ pub const fn minimumf128(x: f128, y: f128) -> f128 {
30873107

30883108
/// Returns the maximum (IEEE 754-2008 maxNum) of two `f16` values.
30893109
///
3110+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3111+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3112+
///
30903113
/// Note that, unlike most intrinsics, this is safe to call;
30913114
/// it does not require an `unsafe` block.
30923115
/// Therefore, implementations must not require the user to uphold
30933116
/// any safety invariants.
30943117
///
3095-
/// The stabilized version of this intrinsic is
3096-
/// [`f16::max`]
3118+
/// The stabilized version of this intrinsic is [`f16::max`].
30973119
#[rustc_nounwind]
30983120
#[rustc_intrinsic]
30993121
pub const fn maxnumf16(x: f16, y: f16) -> f16;
31003122

31013123
/// Returns the maximum (IEEE 754-2008 maxNum) of two `f32` values.
31023124
///
3125+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3126+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3127+
///
31033128
/// Note that, unlike most intrinsics, this is safe to call;
31043129
/// it does not require an `unsafe` block.
31053130
/// Therefore, implementations must not require the user to uphold
31063131
/// any safety invariants.
31073132
///
3108-
/// The stabilized version of this intrinsic is
3109-
/// [`f32::max`]
3133+
/// The stabilized version of this intrinsic is [`f32::max`].
31103134
#[rustc_nounwind]
31113135
#[rustc_intrinsic_const_stable_indirect]
31123136
#[rustc_intrinsic]
31133137
pub const fn maxnumf32(x: f32, y: f32) -> f32;
31143138

31153139
/// Returns the maximum (IEEE 754-2008 maxNum) of two `f64` values.
31163140
///
3141+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3142+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3143+
///
31173144
/// Note that, unlike most intrinsics, this is safe to call;
31183145
/// it does not require an `unsafe` block.
31193146
/// Therefore, implementations must not require the user to uphold
31203147
/// any safety invariants.
31213148
///
3122-
/// The stabilized version of this intrinsic is
3123-
/// [`f64::max`]
3149+
/// The stabilized version of this intrinsic is [`f64::max`].
31243150
#[rustc_nounwind]
31253151
#[rustc_intrinsic_const_stable_indirect]
31263152
#[rustc_intrinsic]
31273153
pub const fn maxnumf64(x: f64, y: f64) -> f64;
31283154

31293155
/// Returns the maximum (IEEE 754-2008 maxNum) of two `f128` values.
31303156
///
3157+
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
3158+
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
3159+
///
31313160
/// Note that, unlike most intrinsics, this is safe to call;
31323161
/// it does not require an `unsafe` block.
31333162
/// Therefore, implementations must not require the user to uphold
31343163
/// any safety invariants.
31353164
///
3136-
/// The stabilized version of this intrinsic is
3137-
/// [`f128::max`]
3165+
/// The stabilized version of this intrinsic is [`f128::max`].
31383166
#[rustc_nounwind]
31393167
#[rustc_intrinsic]
31403168
pub const fn maxnumf128(x: f128, y: f128) -> f128;
31413169

31423170
/// Returns the maximum (IEEE 754-2019 maximum) of two `f16` values.
31433171
///
3172+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3173+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3174+
///
31443175
/// Note that, unlike most intrinsics, this is safe to call;
31453176
/// it does not require an `unsafe` block.
31463177
/// Therefore, implementations must not require the user to uphold
@@ -3161,6 +3192,9 @@ pub const fn maximumf16(x: f16, y: f16) -> f16 {
31613192

31623193
/// Returns the maximum (IEEE 754-2019 maximum) of two `f32` values.
31633194
///
3195+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3196+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3197+
///
31643198
/// Note that, unlike most intrinsics, this is safe to call;
31653199
/// it does not require an `unsafe` block.
31663200
/// Therefore, implementations must not require the user to uphold
@@ -3181,6 +3215,9 @@ pub const fn maximumf32(x: f32, y: f32) -> f32 {
31813215

31823216
/// Returns the maximum (IEEE 754-2019 maximum) of two `f64` values.
31833217
///
3218+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3219+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3220+
///
31843221
/// Note that, unlike most intrinsics, this is safe to call;
31853222
/// it does not require an `unsafe` block.
31863223
/// Therefore, implementations must not require the user to uphold
@@ -3201,6 +3238,9 @@ pub const fn maximumf64(x: f64, y: f64) -> f64 {
32013238

32023239
/// Returns the maximum (IEEE 754-2019 maximum) of two `f128` values.
32033240
///
3241+
/// If one of the arguments is NaN, then a NaN is returned using the usual NaN propagation rules.
3242+
/// For this operation, -0.0 is considered to be strictly less than +0.0.
3243+
///
32043244
/// Note that, unlike most intrinsics, this is safe to call;
32053245
/// it does not require an `unsafe` block.
32063246
/// Therefore, implementations must not require the user to uphold

0 commit comments

Comments
 (0)