diff options
| author | Trevor Gross <tmgross@umich.edu> | 2024-06-21 03:30:15 -0400 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2024-06-24 00:42:21 -0500 |
| commit | 0314fe62bd178200a620b90b59becd735d6c2e66 (patch) | |
| tree | 37a72febd00d7a692475f63fb1b4012ed45d523d | |
| parent | fce07a82c632ec28ac02361b786e64bf56ec1739 (diff) | |
| download | rust-0314fe62bd178200a620b90b59becd735d6c2e66.tar.gz rust-0314fe62bd178200a620b90b59becd735d6c2e66.zip | |
Reword docs for `f32` and `f64`
Better explain the reasoning for the `next_up`/`next_down` integer implementation, as requested by Ralf.
| -rw-r--r-- | library/core/src/num/f32.rs | 10 | ||||
| -rw-r--r-- | library/core/src/num/f64.rs | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 271965c2884..b9c84a66ed1 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -796,8 +796,9 @@ impl f32 { #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { - // We must use strictly integer arithmetic to prevent denormals from - // flushing to zero after an arithmetic operation on some platforms. + // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing + // denormals to zero. This is in general unsound and unsupported, but here + // we do our best to still produce the correct result on such targets. let bits = self.to_bits(); if self.is_nan() || bits == Self::INFINITY.to_bits() { return self; @@ -843,8 +844,9 @@ impl f32 { #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { - // We must use strictly integer arithmetic to prevent denormals from - // flushing to zero after an arithmetic operation on some platforms. + // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing + // denormals to zero. This is in general unsound and unsupported, but here + // we do our best to still produce the correct result on such targets. let bits = self.to_bits(); if self.is_nan() || bits == Self::NEG_INFINITY.to_bits() { return self; diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index bccd39f6059..f8e4555fc44 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -804,8 +804,9 @@ impl f64 { #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { - // We must use strictly integer arithmetic to prevent denormals from - // flushing to zero after an arithmetic operation on some platforms. + // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing + // denormals to zero. This is in general unsound and unsupported, but here + // we do our best to still produce the correct result on such targets. let bits = self.to_bits(); if self.is_nan() || bits == Self::INFINITY.to_bits() { return self; @@ -851,8 +852,9 @@ impl f64 { #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { - // We must use strictly integer arithmetic to prevent denormals from - // flushing to zero after an arithmetic operation on some platforms. + // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing + // denormals to zero. This is in general unsound and unsupported, but here + // we do our best to still produce the correct result on such targets. let bits = self.to_bits(); if self.is_nan() || bits == Self::NEG_INFINITY.to_bits() { return self; |
