Skip to content

Commit

Permalink
test: fmod with a variety of values/signs
Browse files Browse the repository at this point in the history
  • Loading branch information
bcliden committed Nov 26, 2024
1 parent e93219d commit d02ca3b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nannou_core/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,27 @@ where
{
s.rad_to_turns()
}

#[cfg(test)]
mod tests {
use super::*;
use float_eq::assert_float_eq;

#[test]
fn test_fmod() {
/*
Test values sourced from:
https://en.cppreference.com/w/c/numeric/math/fmod
*/
assert_float_eq!(fmod(5.1, 3.0), 2.1, r2nd <= Float::epsilon());
assert_float_eq!(fmod(-5.1, 3.0), -2.1, r2nd <= Float::epsilon());
assert_float_eq!(fmod(5.1, -3.0), 2.1, r2nd <= Float::epsilon());
assert_float_eq!(fmod(-5.1, -3.0), -2.1, r2nd <= Float::epsilon());

assert_float_eq!(fmod(0.0, 1.0), 0.0, r2nd <= Float::epsilon());
assert_float_eq!(fmod(-0.0, 1.0), -0.0, r2nd <= Float::epsilon());

assert!(fmod(5.1, Float::infinity()).is_sign_negative());
assert!(fmod(5.1, Float::infinity()).is_nan());
}
}

0 comments on commit d02ca3b

Please sign in to comment.