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
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:
Which yields:
Which is the same as Python
%
: