mirror of https://github.com/rm-dr/daisy
Fixed mod bug
parent
b846a7c144
commit
cc81c3979c
|
@ -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); }
|
||||
|
|
|
@ -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()}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue