Repository navigation
Tracking Issue (take 2) for more_float_constants #146939
Copy link
Copy link
Open
Labels
A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Feature gate: #![feature(more_float_constants)]
This is a tracking issue for additional constants in the {f16, f32, f64, f128}::consts modules. Most of these match C++, with the exception of 1/sqrt(2π) https://en.cppreference.com/w/cpp/numeric/constants.html.
The original tracking issue was #103883 but we lost the ability to edit the top post.
Public API
// in core::{f16, f32, f64, f128}::consts
/// 1/sqrt(π)
pub const FRAC_1_SQRT_PI: f64 = 0.564189583547756286948079451560772586_f64;
/// 1/sqrt(2π)
pub const FRAC_1_SQRT_2PI: f64 = 0.398942280401432677939946059934381868_f64;
/// sqrt(3)
pub const SQRT_3: f64 = 1.732050807568877293527446341505872367_f64;
/// 1/sqrt(3)
pub const FRAC_1_SQRT_3: f64 = 0.577350269189625764509148780501957456_f64;
/* Already stabilized as euler_gamma_golden_ratio */
/// The golden ratio (φ)
pub const GOLDEN_RATIO: f64 = 1.618033988749894848204586834365638118_f64;
/// The Euler-Mascheroni constant (γ)
pub const EULER_GAMMA: f64 = 0.577215664901532860606512090082402431_f64;Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
- ACP: ACP: Add a constant for the golden ratio (phi) to the floating point types libs-team#119
- ACP for
FRAC_1_SQRT_2PIAddFRAC_1_SQRT_2PIconstant libs-team#383 - Implementation: Add additional float constants #103836
- Add
FRAC_1_SQRT_2PIAddFRAC_1_SQRT_2PIconstant to f16/f32/f64/f128 #125253 - Add constants for
f16andf128Add constants for f16 and f128 #123850 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Naming of the Euler-Mascheroni constant (gamma).
-
FRAC_1_SQRT_2PIorFRAC_1_SQRT_TAUto match the existingTAU - Any additional constants?
- How do we decide whether or not a constant makes the cutoff?
Footnotes
Reacted by Gabriel Bjørnager Jensen, José Luis Cruz, Eyal Kalderon, Alexander Medvedev, Johanna Sörngård and Brandon Stilson
Reacted by Gabriel Bjørnager Jensen and Alexander Medvedev
Reacted by M, Alexander Medvedev, Ricardo Fernández Serrata and Quinn Gregg
Metadata
Metadata
Assignees
Labels
A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
more_float_constants#103883 as a duplicate of this issue[-]Tracking Issue take 2 for `more_float_constants`[/-][+]Tracking Issue (take 2) for `more_float_constants`[/+]tgross35 commentedon Sep 26, 2025
Since there is a proposal for more constants at rust-lang/libs-team#661, seems worth discussing whether there is interest in stabilizing the ones we already have. They have been unstably around since 2023, and most of the values have been stable for a few thousand years. There are a few unresolved questions on the issue.
@rustbot label +I-libs-api-nominated
Names for
PHIandEGAMMAhave come up a few times. Survey of other languages:phi,egamma) https://en.cppreference.com/w/cpp/numeric/constants.htmleulergammaandγ,goldenandφhttps://docs.julialang.org/en/v1/base/numbers/#Base.MathConstants.eulergammaeulergammahttps://www.mathworks.com/help/symbolic/eulergamma.html, no phieuler_gamma,goldenandgolden_ratiohttps://numpy.org/devdocs/reference/constants.html#numpy.euler_gamma https://docs.scipy.org/doc/scipy/reference/constants.htmltgross35 commentedon Sep 26, 2025
@joshuarayton replying from #103883 (comment):
Note that this is a soft conflict with the
gammafunction (tgammain math.h) which is represented by an uppercase gamma.My personal preference would be to closer match Julia and Numpy by calling these
EULER_GAMMAandGOLDEN_RATIO(don't feel very strongly about phi though).joshuarayton commentedon Sep 26, 2025
My personal preference would be
GAMMAfor the Euler-Mascheroni constant andPHIfor the golden ratio. When these constants can be used multiple times in a single line of code, it's easier to have shorter names to prevent line wrapping.I don't think
GAMMA(constant) would conflict withgamma(function) because it is typical to have upper-case constant definitions. But I do accept this could be a reason against.kennytm commentedon Sep 27, 2025
i'm fine with
GAMMA/EGAMMA/EULER_GAMMA. but if you need a shorter name you could always rename the import yourself.Jules-Bertholet commentedon Sep 27, 2025
This seems right to me as well. “Phi” and “gamma” can mean many things, it’s better to use unambiguous names. As @kennytm mentions, you can and should rename the import if needed; that gives the benefit of brevity without losing any clarity.
Rollup merge of rust-lang#147076 - joshuarayton:more-float-constants-…
bjoernager commentedon Sep 27, 2025
The current convention is to use the name of the symbol rather than of the constant itself (
E,PI, andTAUbeing the stable examples).Searching for "gamma constant" on Wikipedia yields both Euler's constant and the Fransén-Robinson constant. Yet, only the former is denoted with a gamma letter (γ vs. F). Some find
GAMMAto be too ambiguous for it, but I haven't seen any actual example (yet) of how it is more so thanEorTAU– or, more importantly, what it would be confused with in any practical case.The Golden Ratio is almost always synonymous with merely "phi." I can't find any other constant that is widely denoted by a phi letter. I would argue that this is similar to how "pi" is exclusive to Archimedes' constant π.
Jules-Bertholet commentedon Sep 27, 2025
PIis by far the most common and well-known name for the constant it references; there wasn’t really any choice there. The proponents ofTAUwant it to become as common asPI. As forE, personally I think it should have beenEULER_E, especially as mathematics generally denotes it with a lowercase “e”, and “E” is used for a different constant.Rollup merge of rust-lang#147076 - joshuarayton:more-float-constants-…
17 remaining items
kennytm commentedon Jan 15, 2026
Yes someone needs to make a PR to rename the two constants
EGAMMA,PHItoEULER_GAMMA,GOLDEN_RATIOand stabilize them (only forf32andf64), as per the FCP decision above.bjoernager commentedon Jan 15, 2026
bjoernager commentedon Jan 15, 2026
Renaming and stabilisation PR: #151164
Rollup merge of rust-lang#151164 - euler-gamma-golden-ratio, r=jhpratt
Unrolled build for #151164
tisonkun commentedon Jan 30, 2026
I'd like to see "golden ratio" stabilized. Is there any way to stabilize some of them now?
tgross35 commentedon Jan 30, 2026
🪄 abracadabra!
Rollup merge of rust-lang#151825 - joshuarayton:more-float-constants,…
Rollup merge of rust-lang#151825 - joshuarayton:more-float-constants,…
Rollup merge of rust-lang#151825 - joshuarayton:more-float-constants,…
Rollup merge of rust-lang#151825 - joshuarayton:more-float-constants,…
Rollup merge of rust-lang#151825 - joshuarayton:more-float-constants,…
Unrolled build for #151825