improve wrap function
This commit is contained in:
parent
a60847ad6f
commit
6d6794456e
@ -1,6 +1,6 @@
|
||||
#[inline]
|
||||
pub fn wrap(x: f32, max: f32) -> f32 {
|
||||
x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32)
|
||||
x - max * ((x > max) as i32 - x.is_sign_negative() as i32) as f32
|
||||
}
|
||||
|
||||
/// Truncate x and y and return a corresponding index into the data slice.
|
||||
@ -18,7 +18,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn wrap_test() {
|
||||
assert_eq!(wrap(1.1, 1.0), 0.100000024);
|
||||
assert_eq!(wrap(1.1, 1.0), 0.100000024); // floating point weirdness
|
||||
assert_eq!(wrap(0.5, 1.0), 0.5);
|
||||
assert_eq!(wrap(-1.0, 2.0), 1.0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user