Handle negative m value#78
Merged
Merged
Conversation
If the `m` value in the CPR calculation works out to be negative the use
of `%` results in an incorrect (negative) value.
This commit uses `rem_euclid` instead of `%` to get the expected value
when calculating longitude (at least for the test input used and within
a few decimal places).
I'm not entirely sure that `rem_euclid` is the correct replacement but
from the little bit of reading I've done to refresh myself on modulus
and related math I think it is suitable (plus the existing test suite
still passes in addtion to the new test for this case).
Example Rust code to show differences:
#![allow(unused)]
fn main() {
let ni = 47.0;
let m: f64 = -28.0;
println!("ni = {}", ni);
println!("m = {}", m);
println!("m % ni = {}", (m % ni));
println!("m.rem_euclid(ni) = {}", m.rem_euclid(ni));
}
Which yields:
ni = 47
m = -28
m % ni = -28
m.rem_euclid(ni) = 19
Which is the same as Python `%`:
In [1]: -28 % 47
Out[1]: 19
Member
|
Hey! Thanks for the fix. |
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.
If the
mvalue in the CPR calculation works out to be negative the useof
%results in an incorrect (negative) value.This commit uses
rem_euclidinstead of%to get the expected valuewhen calculating longitude (at least for the test input used and within
a few decimal places).
I'm not entirely sure that
rem_euclidis the correct replacement butfrom the little bit of reading I've done to refresh myself on modulus
and related math I think it is suitable (plus the existing test suite
still passes in addtion to the new test for this case).
Example Rust code to show differences:
Which yields:
Which is the same as Python
%: