Skip to content
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

Tracking Issue for more_float_constants #103883

Open
1 of 3 tasks
ghost opened this issue Nov 2, 2022 · 3 comments
Open
1 of 3 tasks

Tracking Issue for more_float_constants #103883

ghost opened this issue Nov 2, 2022 · 3 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Nov 2, 2022

Feature gate: #![feature(more_float_constants)]

This is a tracking issue for additional constants in the {f32,f64}::consts modules.

ACP: rust-lang/libs-team#119

Public API

// in core::{f32, f64}::consts

/// The golden ratio (φ)
pub const PHI: f64 = 1.618033988749894848204586834365638118_f64;

/// The Euler-Mascheroni constant (γ)
pub const EGAMMA: f64 = 0.577215664901532860606512090082402431_f64;

/// 1/sqrt(π)
pub const FRAC_1_SQRT_PI: f64 = 0.564189583547756286948079451560772586_f64;

/// sqrt(3)
pub const SQRT_3: f64 = 1.732050807568877293527446341505872367_f64;

/// 1/sqrt(3)
pub const FRAC_1_SQRT_3: f64 = 0.577350269189625764509148780501957456_f64;

Steps / History

Unresolved Questions

  • Naming of the Euler-Mascheroni constant (gamma)
  • Any additional constants?
    • ln(3)

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@ghost ghost added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 2, 2022
@leonardo-m
Copy link

On constants defined like:

pub const PHI: f64 = 1.618033988749894848204586834365638118_f64;

Clippy raises a "float has excessive precision" using this lint:

https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision

@ghost
Copy link
Author

ghost commented Nov 2, 2022

The lint also triggers for like every other constant in the {f32,f64}::consts modules. It's not necessarily a bad thing, as rustc just silently truncates them.

@torvalamo
Copy link

torvalamo commented May 25, 2023

As for the question of additional constants: SQRT_5, which is an element in the proposed PHI and also used for various geometric and trigonometric calculations. PHI probably covers the most common usage of SQRT_5, but it wouldn't hurt to include it as it is relatively common (more so than EGAMMA I would argue). Just my 2 cents.

simdimdim added a commit to simdimdim/nushell that referenced this issue May 30, 2023
fdncred pushed a commit to nushell/nushell that referenced this issue Jun 1, 2023
… of an existing one) (#9181)

Adding more float constants for when
rust-lang/rust#103883 is accepted and merged.
And fixing a small conflation in the description of the Euler number.
Please take a look and let me know if I've missed or screwed up
anything.
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 28, 2023
Add additional float constants

Initial implementation of this ACP: rust-lang/libs-team#119. [Accepted]
Tracking issue: rust-lang#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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants