Use constant for 180/π in f32::to_degrees#61
Merged
bors[bot] merged 3 commits intorust-num:masterfrom May 4, 2018
Merged
Conversation
The current `f32::to_degrees` implementation uses a division to calculate 180/π, which causes a loss of precision. Using a constant is still not perfect (implementing a maximally-precise algorithm would come with a high performance cost), but improves precision with a minimal change. This is a backport from [`std`]. [`std`]: rust-lang/rust@e34c31b
Member
|
Just for reference, we also discussed the implication that some inputs are now less accurate, in rust-lang/rust#48617. But the rounding is more correct in general, and here we forward to |
cuviper
reviewed
Apr 10, 2018
|
|
||
| #[test] | ||
| fn to_degrees_rounding() { | ||
| assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703); |
Member
There was a problem hiding this comment.
When we forward to std, this fails on Rust 1.8 since it lacks rust-lang/rust#47919. Maybe just limit this test to no-std builds? (with a comment explaining this reason)
Member
|
Strange, 1.8 still failed! |
Member
|
Solved by explicitly calling bors r+ |
bors Bot
added a commit
that referenced
this pull request
May 4, 2018
61: Use constant for 180/π in f32::to_degrees r=cuviper a=vks The current `f32::to_degrees` implementation uses a division to calculate 180/π, which causes a loss of precision. Using a constant is still not perfect (implementing a maximally-precise algorithm would come with a high performance cost), but improves precision with a minimal change. This is a backport from [`std`]. [`std`]: rust-lang/rust@e34c31b Co-authored-by: Vinzent Steinberg <vinzent.steinberg@gmail.com> Co-authored-by: Josh Stone <cuviper@gmail.com>
Contributor
Author
|
Thanks for the fix! I forgot about this PR... |
Contributor
Build succeeded |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The current
f32::to_degreesimplementation uses a division tocalculate 180/π, which causes a loss of precision. Using a constant is
still not perfect (implementing a maximally-precise algorithm would come
with a high performance cost), but improves precision with a minimal
change.
This is a backport from
std.