Added check for negative powers

pull/2/head
Mark 2023-06-07 15:21:36 -07:00
parent 8ca4ffd51f
commit dae76f3d56
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 5 additions and 0 deletions

View File

@ -171,6 +171,7 @@ fn operators() {
good_expr("7", "3!+1"); good_expr("7", "3!+1");
good_expr("18", "3!3"); good_expr("18", "3!3");
bad_expr("3.1!"); bad_expr("3.1!");
bad_expr("0^(-1)");
bad_expr("pi!"); bad_expr("pi!");
} }

View File

@ -460,6 +460,10 @@ impl Operator{
return Err(EvalError::IncompatibleUnit); return Err(EvalError::IncompatibleUnit);
} }
if va.is_zero() && vb.is_negative() {
return Err(EvalError::ZeroDivision);
}
let p = va.pow(vb); let p = va.pow(vb);
if p.is_nan() {return Err(EvalError::BadMath);} if p.is_nan() {return Err(EvalError::BadMath);}
return Ok(Token::Number(p)); return Ok(Token::Number(p));