-
Notifications
You must be signed in to change notification settings - Fork 13.4k
doc: expand description for f32 and f64 associated constants #104153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,38 +357,76 @@ 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I admit I've not paged discussion on #89238 into cache, but since that annotates this with "A minimum number of significant digits in base 10." it feels somewhat surprising to have "maximum" here. (Perhaps the language is actually equivalent, I would need to actually thoroughly understand what the significance is to make a call there). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly,
I wrote "maximum" there because if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example for let s1 = "8.589973e9";
let float: f32 = s1.parse().unwrap();
let s2 = format!("{float:.6e}");
assert_eq!(s1, s2); panics with
|
||
/// | ||
/// 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; | ||
|
||
/// [Machine epsilon] value for `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 | ||
tspiteri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// ≥ 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; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.