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

Add FRAC_1_SQRT_2PI constant to f16/f32/f64/f128 #125253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sunsided
Copy link

@sunsided sunsided commented May 18, 2024

This adds the FRAC_1_SQRT_2PI to the f16, f32, f64 and f128 as 1/√(2π). The rationale is that while FRAC_1_SQRT_PI already exists, Gaussian calculations for random normal distributions require a 1/(σ√(2π)) term, which could then be directly expressed e.g. as f32::FRAC_1_SQRT_2PI / sigma.

The actual value is approximately 1/√(2π) = 0.3989422804014326779399460599343818684758586311649346576659258296…. Truncated/rounded forms were used for the individual types.


I did not any of the #[unstable] attributes since I am not aware of their implications.

Edit: I applied the stability attributes from the surrounding types according to what seemed most likely correct. I believe the more_float_constants feature marker is incorrectly applied, but I wasn't sure how to proceed.

@rustbot
Copy link
Collaborator

rustbot commented May 18, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 18, 2024
@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. needs-acp This change is blocked on the author creating an ACP. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2024
@Mark-Simulacrum
Copy link
Member

New unstable API surface area currently requires an ACP. Please file one and if it's approved we can merge.

@rustbot author

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 25, 2024
@sunsided
Copy link
Author

Thanks, added it at rust-lang/libs-team#383. Exciting!

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 26, 2024
This is create symmetry between the already existing TAU constant (2pi)
and the newly-introduced FRAC_1_SQRT_2PI, keeping the more common
name while increasing visibility.
@sunsided
Copy link
Author

I added #[doc(alias = "FRAC_1_SQRT_TAU")] to the constants to create a bit of symmetry with the already-existing TAU constant, as discussed in rust-lang/libs-team#383.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-acp This change is blocked on the author creating an ACP. S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants