add support for rational numbers, division.

This commit is contained in:
Mark Thom
2017-12-02 11:10:25 -07:00
parent a65adf960e
commit 9a7419c507
10 changed files with 218 additions and 71 deletions

View File

@@ -97,12 +97,14 @@ impl<'a> ArithmeticEvaluator<'a> {
-> Result<ArithmeticInstruction, ArithmeticError>
{
match name.as_str() {
"+" => Ok(ArithmeticInstruction::Add(a1, a2, t)),
"-" => Ok(ArithmeticInstruction::Sub(a1, a2, t)),
"//" => Ok(ArithmeticInstruction::IDiv(a1, a2, t)),
"div" => Ok(ArithmeticInstruction::IDiv(a1, a2, t)),
"*" => Ok(ArithmeticInstruction::Mul(a1, a2, t)),
_ => Err(ArithmeticError::InvalidOp)
"+" => Ok(ArithmeticInstruction::Add(a1, a2, t)),
"-" => Ok(ArithmeticInstruction::Sub(a1, a2, t)),
"/" => Ok(ArithmeticInstruction::Div(a1, a2, t)),
"//" => Ok(ArithmeticInstruction::IDiv(a1, a2, t)),
"div" => Ok(ArithmeticInstruction::IDiv(a1, a2, t)),
"rdiv" => Ok(ArithmeticInstruction::RDiv(a1, a2, t)),
"*" => Ok(ArithmeticInstruction::Mul(a1, a2, t)),
_ => Err(ArithmeticError::InvalidOp)
}
}