diff options
| author | Trevor Spiteri <tspiteri@ieee.org> | 2022-11-08 15:52:20 +0100 |
|---|---|---|
| committer | Trevor Spiteri <tspiteri@ieee.org> | 2022-11-08 15:52:20 +0100 |
| commit | c953b6c0147557d3775f7cde55f8ffdb2d82bc45 (patch) | |
| tree | 9169de515eb6e3bab606237181d907d82a333062 /library | |
| parent | ddfe1e87f7c85c03773c29180a931447fcd03b65 (diff) | |
| download | rust-c953b6c0147557d3775f7cde55f8ffdb2d82bc45.tar.gz rust-c953b6c0147557d3775f7cde55f8ffdb2d82bc45.zip | |
doc: expand description for f32 and f64 associated constants
This explains the meaning of some of the floating-point associated constants.
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/num/f32.rs | 42 | ||||
| -rw-r--r-- | library/core/src/num/f64.rs | 42 |
2 files changed, 80 insertions, 4 deletions
diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 2c6a0ba64f2..2e218ddeb75 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -357,6 +357,13 @@ impl f32 { pub const MANTISSA_DIGITS: u32 = 24; /// Approximate number of significant digits in base 10. + /// + /// This is the maximum <i>x</i> such that any decimal number with <i>x</i> + /// significant digits can be converted to `f32` and back without loss. + /// + /// Equal to floor(log<sub>10</sub> 2<sup>[`MANTISSA_DIGITS`] − 1</sup>). + /// + /// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const DIGITS: u32 = 6; @@ -364,31 +371,62 @@ impl f32 { /// /// This is the difference between `1.0` and the next larger representable number. /// + /// Equal to 2<sup>1 − [`MANTISSA_DIGITS`]</sup>. + /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon + /// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const EPSILON: f32 = 1.19209290e-07_f32; /// Smallest finite `f32` value. + /// + /// Equal to −[`MAX`]. + /// + /// [`MAX`]: f32::MAX #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN: f32 = -3.40282347e+38_f32; /// Smallest positive normal `f32` value. + /// + /// Equal to 2<sup>[`MIN_EXP`] − 1</sup>. + /// + /// [`MIN_EXP`]: f32::MIN_EXP #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32; /// Largest finite `f32` value. + /// + /// Equal to + /// (1 − 2<sup>−[`MANTISSA_DIGITS`]</sup>) 2<sup>[`MAX_EXP`]</sup>. + /// + /// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS + /// [`MAX_EXP`]: f32::MAX_EXP #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX: f32 = 3.40282347e+38_f32; /// One greater than the minimum possible normal power of 2 exponent. + /// + /// If <i>x</i> = `MIN_EXP`, then normal numbers + /// ≥ 0.5 × 2<sup><i>x</i></sup>. #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_EXP: i32 = -125; /// Maximum possible power of 2 exponent. + /// + /// If <i>x</i> = `MAX_EXP`, then normal numbers + /// < 1 × 2<sup><i>x</i></sup>. #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_EXP: i32 = 128; - /// Minimum possible normal power of 10 exponent. + /// Minimum <i>x</i> for which 10<sup><i>x</i></sup> is normal. + /// + /// Equal to ceil(log<sub>10</sub> [`MIN_POSITIVE`]). + /// + /// [`MIN_POSITIVE`]: f32::MIN_POSITIVE #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_10_EXP: i32 = -37; - /// Maximum possible power of 10 exponent. + /// Maximum <i>x</i> for which 10<sup><i>x</i></sup> is normal. + /// + /// Equal to floor(log<sub>10</sub> [`MAX`]). + /// + /// [`MAX`]: f32::MAX #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_10_EXP: i32 = 38; diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index fd3c18ce29b..5ea6eb73920 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -356,6 +356,13 @@ impl f64 { #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MANTISSA_DIGITS: u32 = 53; /// Approximate number of significant digits in base 10. + /// + /// This is the maximum <i>x</i> such that any decimal number with <i>x</i> + /// significant digits can be converted to `f64` and back without loss. + /// + /// Equal to floor(log<sub>10</sub> 2<sup>[`MANTISSA_DIGITS`] − 1</sup>). + /// + /// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const DIGITS: u32 = 15; @@ -363,31 +370,62 @@ impl f64 { /// /// This is the difference between `1.0` and the next larger representable number. /// + /// Equal to 2<sup>1 − [`MANTISSA_DIGITS`]</sup>. + /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon + /// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const EPSILON: f64 = 2.2204460492503131e-16_f64; /// Smallest finite `f64` value. + /// + /// Equal to −[`MAX`]. + /// + /// [`MAX`]: f64::MAX #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN: f64 = -1.7976931348623157e+308_f64; /// Smallest positive normal `f64` value. + /// + /// Equal to 2<sup>[`MIN_EXP`] − 1</sup>. + /// + /// [`MIN_EXP`]: f64::MIN_EXP #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64; /// Largest finite `f64` value. + /// + /// Equal to + /// (1 − 2<sup>−[`MANTISSA_DIGITS`]</sup>) 2<sup>[`MAX_EXP`]</sup>. + /// + /// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS + /// [`MAX_EXP`]: f64::MAX_EXP #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX: f64 = 1.7976931348623157e+308_f64; /// One greater than the minimum possible normal power of 2 exponent. + /// + /// If <i>x</i> = `MIN_EXP`, then normal numbers + /// ≥ 0.5 × 2<sup><i>x</i></sup>. #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_EXP: i32 = -1021; /// Maximum possible power of 2 exponent. + /// + /// If <i>x</i> = `MAX_EXP`, then normal numbers + /// < 1 × 2<sup><i>x</i></sup>. #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_EXP: i32 = 1024; - /// Minimum possible normal power of 10 exponent. + /// Minimum <i>x</i> for which 10<sup><i>x</i></sup> is normal. + /// + /// Equal to ceil(log<sub>10</sub> [`MIN_POSITIVE`]). + /// + /// [`MIN_POSITIVE`]: f64::MIN_POSITIVE #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_10_EXP: i32 = -307; - /// Maximum possible power of 10 exponent. + /// Maximum <i>x</i> for which 10<sup><i>x</i></sup> is normal. + /// + /// Equal to floor(log<sub>10</sub> [`MAX`]). + /// + /// [`MAX`]: f64::MAX #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_10_EXP: i32 = 308; |
