From cc81c3979c66270ad2e47d2d1e587c80ab430f06 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 17 Aug 2023 16:38:02 -0700 Subject: [PATCH] Fixed mod bug --- src/evaluate/operator.rs | 5 +++++ src/quantity/scalar/floatbase.rs | 2 +- src/quantity/scalar/scalar.rs | 2 +- src/tests.rs | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/evaluate/operator.rs b/src/evaluate/operator.rs index bc77de4..1268554 100644 --- a/src/evaluate/operator.rs +++ b/src/evaluate/operator.rs @@ -162,6 +162,11 @@ pub fn eval_operator(context: &mut Context, g: &Expression) -> Result for FloatBase { (!modulus.fract().unwrap().is_zero()) } { panic!() } - FloatBase{val : self.val.fract() % modulus.val.fract()} + FloatBase{val : self.val.trunc() % modulus.val.trunc()} } } diff --git a/src/quantity/scalar/scalar.rs b/src/quantity/scalar/scalar.rs index 514e575..756e5bb 100644 --- a/src/quantity/scalar/scalar.rs +++ b/src/quantity/scalar/scalar.rs @@ -186,7 +186,7 @@ impl Scalar { pub fn is_nan(&self) -> bool { match self { Scalar::Float {v} => {v.val.is_nan()}, - Scalar::Rational {..} => {panic!()} + Scalar::Rational {..} => {false} } } diff --git a/src/tests.rs b/src/tests.rs index 0f41c8d..cf30e25 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -162,6 +162,7 @@ fn operators() { good_expr("2", "6/3"); good_expr("2", "5%3"); + good_expr("4", "2^5 mod 7"); good_expr("8", "5+3"); good_expr("64", "4^3"); good_expr("64", "4 ^ 3");