-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add/improve num const docs #34277
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
Merged
Merged
Add/improve num const docs #34277
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,121 +20,121 @@ use mem; | |
use num::Float; | ||
use num::FpCategory as Fp; | ||
|
||
/// The radix or base of the internal representation of `f32`. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const RADIX: u32 = 2; | ||
|
||
/// Number of significant digits in base 2. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const MANTISSA_DIGITS: u32 = 24; | ||
/// Approximate number of significant digits in base 10. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const DIGITS: u32 = 6; | ||
|
||
/// Difference between `1.0` and the next largest representable number. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const EPSILON: f32 = 1.19209290e-07_f32; | ||
|
||
/// Smallest finite f32 value | ||
/// Smallest finite `f32` value. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const MIN: f32 = -3.40282347e+38_f32; | ||
/// Smallest positive, normalized f32 value | ||
/// Smallest positive normal `f32` value. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32; | ||
/// Largest finite f32 value | ||
/// Largest finite `f32` value. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const MAX: f32 = 3.40282347e+38_f32; | ||
|
||
/// One greater than the minimum possible normal power of 2 exponent. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const MIN_EXP: i32 = -125; | ||
/// Maximum possible power of 2 exponent. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const MAX_EXP: i32 = 128; | ||
|
||
/// Minimum possible normal power of 10 exponent. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const MIN_10_EXP: i32 = -37; | ||
/// Maximum possible power of 10 exponent. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const MAX_10_EXP: i32 = 38; | ||
|
||
/// Not a Number (NaN). | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const NAN: f32 = 0.0_f32/0.0_f32; | ||
/// Infinity (∞). | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const INFINITY: f32 = 1.0_f32/0.0_f32; | ||
/// Negative infinity (-∞). | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[allow(missing_docs)] | ||
pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32; | ||
|
||
/// Basic mathematical constants. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod consts { | ||
// FIXME: replace with mathematical constants from cmath. | ||
|
||
/// Archimedes' constant | ||
/// Archimedes' constant (π) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const PI: f32 = 3.14159265358979323846264338327950288_f32; | ||
|
||
/// pi/2.0 | ||
/// π/2 | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32; | ||
|
||
/// pi/3.0 | ||
/// π/3 | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_PI_3: f32 = 1.04719755119659774615421446109316763_f32; | ||
|
||
/// pi/4.0 | ||
/// π/4 | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_PI_4: f32 = 0.785398163397448309615660845819875721_f32; | ||
|
||
/// pi/6.0 | ||
/// π/6 | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_PI_6: f32 = 0.52359877559829887307710723054658381_f32; | ||
|
||
/// pi/8.0 | ||
/// π/8 | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_PI_8: f32 = 0.39269908169872415480783042290993786_f32; | ||
|
||
/// 1.0/pi | ||
/// 1/π | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32; | ||
|
||
/// 2.0/pi | ||
/// 2/π | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32; | ||
|
||
/// 2.0/sqrt(pi) | ||
/// 2/sqrt(π) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_2_SQRT_PI: f32 = 1.12837916709551257389615890312154517_f32; | ||
|
||
/// sqrt(2.0) | ||
/// sqrt(2) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const SQRT_2: f32 = 1.41421356237309504880168872420969808_f32; | ||
|
||
/// 1.0/sqrt(2.0) | ||
/// 1/sqrt(2) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const FRAC_1_SQRT_2: f32 = 0.707106781186547524400844362104849039_f32; | ||
|
||
/// Euler's number | ||
/// Euler's number (e) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const E: f32 = 2.71828182845904523536028747135266250_f32; | ||
|
||
/// log2(e) | ||
/// log<sub>2</sub>(e) | ||
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. log2? Nice! :D |
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const LOG2_E: f32 = 1.44269504088896340735992468100189214_f32; | ||
|
||
/// log10(e) | ||
/// log<sub>10</sub>(e) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const LOG10_E: f32 = 0.434294481903251827651128918916605082_f32; | ||
|
||
/// ln(2.0) | ||
/// ln(2) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const LN_2: f32 = 0.693147180559945309417232121458176568_f32; | ||
|
||
/// ln(10.0) | ||
/// ln(10) | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, the reason these are
2.0
instead of2
is that2
is an integer in Rust, not a floating point number. Could you restore the.0
s on all these?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And add whitespaces as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention was for these to be mathematical expressions not Rust expressions. "π/2" is a mathematical expression representing a real number and "
PI / 2.0
" is a Rust expression representing a floating point value. These shouldn't be Rust expressions because for examplef64::consts::PI / 3.0 != f64::consts::FRAC_PI_3
.