diff --git a/tests/power_of.rs b/tests/power_of.rs index fb309088..c82e4d93 100644 --- a/tests/power_of.rs +++ b/tests/power_of.rs @@ -3,6 +3,9 @@ use rhai::{Engine, EvalAltResult, INT}; #[cfg(not(feature = "no_float"))] use rhai::FLOAT; +#[cfg(not(feature = "no_float"))] +const EPSILON: FLOAT = 0.0000000001; + #[test] fn test_power_of() -> Result<(), EvalAltResult> { let mut engine = Engine::new(); @@ -12,9 +15,8 @@ fn test_power_of() -> Result<(), EvalAltResult> { #[cfg(not(feature = "no_float"))] { - assert_eq!( - engine.eval::("2.2 ~ 3.3")?, - 13.489468760533388 as FLOAT + assert!( + (engine.eval::("2.2 ~ 3.3")? - 13.489468760533386 as FLOAT).abs() <= EPSILON ); assert_eq!(engine.eval::("2.0~-2.0")?, 0.25 as FLOAT); assert_eq!(engine.eval::("(-2.0~-2.0)")?, 0.25 as FLOAT); @@ -34,9 +36,9 @@ fn test_power_of_equals() -> Result<(), EvalAltResult> { #[cfg(not(feature = "no_float"))] { - assert_eq!( - engine.eval::("let x = 2.2; x ~= 3.3; x")?, - 13.489468760533388 as FLOAT + assert!( + (engine.eval::("let x = 2.2; x ~= 3.3; x")? - 13.489468760533386 as FLOAT).abs() + <= EPSILON ); assert_eq!( engine.eval::("let x = 2.0; x ~= -2.0; x")?,