Skip to content

Commit 1e3b5d6

Browse files
authored
Rollup merge of #88523 - kpreid:category, r=yaahc
Expand documentation for `FpCategory`. I intend these changes to be helpful to readers who are not yet familiar with the quirks of floating-point numbers. Additionally, I felt it was misleading to describe `Nan` as being the result of division by zero, since most divisions by zero (except for 0/0) produce `Infinite` floats, so I moved that remark to the `Infinite` variant with adjustment. The first sentence of the `Nan` documentation is copied from `f32`; I followed the example of the `f64` documentation by referring to `f32` for general concepts, rather than duplicating the text. ---- I considered making similar changes to the documentation of the `is_*` methods of floats, but decided that that was a much larger and trickier problem; here, each of the variants' descriptions can be expected to be read in context of being mutually exclusive with the others.
2 parents 3209582 + 18df8d6 commit 1e3b5d6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Diff for: library/core/src/num/mod.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -865,23 +865,41 @@ impl usize {
865865
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
866866
#[stable(feature = "rust1", since = "1.0.0")]
867867
pub enum FpCategory {
868-
/// "Not a Number", often obtained by dividing by zero.
868+
/// NaN (not a number): this value results from calculations like `(-1.0).sqrt()`.
869+
///
870+
/// See [the documentation for `f32`](f32) for more information on the unusual properties
871+
/// of NaN.
869872
#[stable(feature = "rust1", since = "1.0.0")]
870873
Nan,
871874

872-
/// Positive or negative infinity.
875+
/// Positive or negative infinity, which often results from dividing a nonzero number
876+
/// by zero.
873877
#[stable(feature = "rust1", since = "1.0.0")]
874878
Infinite,
875879

876880
/// Positive or negative zero.
881+
///
882+
/// See [the documentation for `f32`](f32) for more information on the signedness of zeroes.
877883
#[stable(feature = "rust1", since = "1.0.0")]
878884
Zero,
879885

880-
/// De-normalized floating point representation (less precise than `Normal`).
886+
/// “Subnormal” or “denormal” floating point representation (less precise, relative to
887+
/// their magnitude, than [`Normal`]).
888+
///
889+
/// Subnormal numbers are larger in magnitude than [`Zero`] but smaller in magnitude than all
890+
/// [`Normal`] numbers.
891+
///
892+
/// [`Normal`]: Self::Normal
893+
/// [`Zero`]: Self::Zero
881894
#[stable(feature = "rust1", since = "1.0.0")]
882895
Subnormal,
883896

884-
/// A regular floating point number.
897+
/// A regular floating point number, not any of the exceptional categories.
898+
///
899+
/// The smallest positive normal numbers are [`f32::MIN_POSITIVE`] and [`f64::MIN_POSITIVE`],
900+
/// and the largest positive normal numbers are [`f32::MAX`] and [`f64::MAX`]. (Unlike signed
901+
/// integers, floating point numbers are symmetric in their range, so negating any of these
902+
/// constants will produce their negative counterpart.)
885903
#[stable(feature = "rust1", since = "1.0.0")]
886904
Normal,
887905
}

0 commit comments

Comments
 (0)