Skip to content

Commit

Permalink
Auto merge of #103836 - H4x5:extra-float-constants, r=thomcc
Browse files Browse the repository at this point in the history
Add additional float constants

Initial implementation of this ACP: rust-lang/libs-team#119. [Accepted]
Tracking issue: #103883

The values for the constants are copied from the [`libstdc++` source code](https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/include/std/numbers#L57-L120).
  • Loading branch information
bors committed Aug 28, 2023
2 parents 7e02fd8 + f7dec78 commit 1bd0430
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ pub mod consts {
#[stable(feature = "tau_constant", since = "1.47.0")]
pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;

/// The golden ratio (φ)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const PHI: f32 = 1.618033988749894848204586834365638118_f32;

/// The Euler-Mascheroni constant (γ)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const EGAMMA: f32 = 0.577215664901532860606512090082402431_f32;

/// π/2
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32;
Expand All @@ -301,6 +309,10 @@ pub mod consts {
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32;

/// 1/sqrt(π)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const FRAC_1_SQRT_PI: f32 = 0.564189583547756286948079451560772586_f32;

/// 2/π
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32;
Expand All @@ -317,6 +329,14 @@ pub mod consts {
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_1_SQRT_2: f32 = 0.707106781186547524400844362104849039_f32;

/// sqrt(3)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const SQRT_3: f32 = 1.732050807568877293527446341505872367_f32;

/// 1/sqrt(3)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957456_f32;

/// Euler's number (e)
#[stable(feature = "rust1", since = "1.0.0")]
pub const E: f32 = 2.71828182845904523536028747135266250_f32;
Expand Down
20 changes: 20 additions & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ pub mod consts {
#[stable(feature = "tau_constant", since = "1.47.0")]
pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;

/// The golden ratio (φ)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const PHI: f64 = 1.618033988749894848204586834365638118_f64;

/// The Euler-Mascheroni constant (γ)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const EGAMMA: f64 = 0.577215664901532860606512090082402431_f64;

/// π/2
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64;
Expand All @@ -301,6 +309,10 @@ pub mod consts {
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64;

/// 1/sqrt(π)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const FRAC_1_SQRT_PI: f64 = 0.564189583547756286948079451560772586_f64;

/// 2/π
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64;
Expand All @@ -317,6 +329,14 @@ pub mod consts {
#[stable(feature = "rust1", since = "1.0.0")]
pub const FRAC_1_SQRT_2: f64 = 0.707106781186547524400844362104849039_f64;

/// sqrt(3)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const SQRT_3: f64 = 1.732050807568877293527446341505872367_f64;

/// 1/sqrt(3)
#[unstable(feature = "more_float_constants", issue = "103883")]
pub const FRAC_1_SQRT_3: f64 = 0.577350269189625764509148780501957456_f64;

/// Euler's number (e)
#[stable(feature = "rust1", since = "1.0.0")]
pub const E: f64 = 2.71828182845904523536028747135266250_f64;
Expand Down

0 comments on commit 1bd0430

Please sign in to comment.