pub fn wrap_offset(x: f64, period: f64) -> f64Expand description
A difference moved into [−period / 2, period / 2), by wrapping
x + period / 2 into [0, period) and moving back. Unlike
wrap_signed it can return a value one rounding from x when x
is already in range, because of the add and subtract of the half
period; callers that were written against it keep that rounding.
use arris_math::wrap_offset;
use core::f64::consts::{PI, TAU};
assert_eq!(wrap_offset(0.0, TAU), 0.0);
// Exactly half a period goes to the lower end.
assert_eq!(wrap_offset(PI, TAU), -PI);
assert!((wrap_offset(TAU + 0.25, TAU) - 0.25).abs() < 1e-15);
// A period that is not a turn.
assert_eq!(wrap_offset(1.0, 1.0), 0.0);