Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 36a20f7

Browse files
committedJun 24, 2024
Reword docs for f32 and f64
Better explain the reasoning for the `next_up`/`next_down` integer implementation, as requested by Ralf.
1 parent 6839ec5 commit 36a20f7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
 

‎core/src/num/f32.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,9 @@ impl f32 {
796796
#[unstable(feature = "float_next_up_down", issue = "91399")]
797797
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
798798
pub const fn next_up(self) -> Self {
799-
// We must use strictly integer arithmetic to prevent denormals from
800-
// flushing to zero after an arithmetic operation on some platforms.
799+
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
800+
// denormals to zero. This is in general unsound and unsupported, but here
801+
// we do our best to still produce the correct result on such targets.
801802
let bits = self.to_bits();
802803
if self.is_nan() || bits == Self::INFINITY.to_bits() {
803804
return self;
@@ -843,8 +844,9 @@ impl f32 {
843844
#[unstable(feature = "float_next_up_down", issue = "91399")]
844845
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
845846
pub const fn next_down(self) -> Self {
846-
// We must use strictly integer arithmetic to prevent denormals from
847-
// flushing to zero after an arithmetic operation on some platforms.
847+
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
848+
// denormals to zero. This is in general unsound and unsupported, but here
849+
// we do our best to still produce the correct result on such targets.
848850
let bits = self.to_bits();
849851
if self.is_nan() || bits == Self::NEG_INFINITY.to_bits() {
850852
return self;

‎core/src/num/f64.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,9 @@ impl f64 {
804804
#[unstable(feature = "float_next_up_down", issue = "91399")]
805805
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
806806
pub const fn next_up(self) -> Self {
807-
// We must use strictly integer arithmetic to prevent denormals from
808-
// flushing to zero after an arithmetic operation on some platforms.
807+
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
808+
// denormals to zero. This is in general unsound and unsupported, but here
809+
// we do our best to still produce the correct result on such targets.
809810
let bits = self.to_bits();
810811
if self.is_nan() || bits == Self::INFINITY.to_bits() {
811812
return self;
@@ -851,8 +852,9 @@ impl f64 {
851852
#[unstable(feature = "float_next_up_down", issue = "91399")]
852853
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
853854
pub const fn next_down(self) -> Self {
854-
// We must use strictly integer arithmetic to prevent denormals from
855-
// flushing to zero after an arithmetic operation on some platforms.
855+
// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
856+
// denormals to zero. This is in general unsound and unsupported, but here
857+
// we do our best to still produce the correct result on such targets.
856858
let bits = self.to_bits();
857859
if self.is_nan() || bits == Self::NEG_INFINITY.to_bits() {
858860
return self;

0 commit comments

Comments
 (0)
Failed to load comments.