Fixed mod bug

newfloat
Mark 2023-08-17 16:38:02 -07:00
parent b846a7c144
commit cc81c3979c
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 8 additions and 2 deletions

View File

@ -162,6 +162,11 @@ pub fn eval_operator(context: &mut Context, g: &Expression) -> Result<Option<Exp
if va.fract() != Quantity::new_rational(0f64).unwrap() { return Err((*la + *lb + *op_loc, DaisyError::BadMath)); }
if vb.fract() != Quantity::new_rational(0f64).unwrap() { return Err((*la + *lb + *op_loc, DaisyError::BadMath)); }
let o = va.clone() % vb.clone();
if o.is_nan() {return Err((*la + *lb + *op_loc, DaisyError::BadMath));}
return Ok(Some(Expression::Quantity(*la + *lb + *op_loc, va.clone() % vb.clone())));
} else { return Ok(None); }
} else { return Ok(None); }

View File

@ -244,7 +244,7 @@ impl Rem<FloatBase> for FloatBase {
(!modulus.fract().unwrap().is_zero())
} { panic!() }
FloatBase{val : self.val.fract() % modulus.val.fract()}
FloatBase{val : self.val.trunc() % modulus.val.trunc()}
}
}

View File

@ -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}
}
}

View File

@ -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");