From 6d6794456e5233168be3d82db0a2e6b05b7ee1f3 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 27 Mar 2025 23:49:44 -0400 Subject: [PATCH] improve wrap function --- src/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.rs b/src/util.rs index 7596f17..d56f137 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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); }