Added nounit and tobase functions

This commit is contained in:
2023-06-14 09:24:34 -07:00
parent aa02b35cc5
commit 061f58ba53
6 changed files with 83 additions and 35 deletions

View File

@ -11,6 +11,13 @@ pub fn eval_function(f: &Function, args: &VecDeque<Token>) -> Result<Token, Eval
let a = &args[0];
let Token::Quantity(q) = a else {panic!()};
match f {
Function::NoUnit => { return Ok(Token::Quantity(q.without_unit())); }
Function::ToBase => { return Ok(Token::Quantity(q.convert_to_base())); }
_ => {}
}
if !q.unitless() {
return Err(EvalError::IncompatibleUnit);
}
@ -89,5 +96,8 @@ pub fn eval_function(f: &Function, args: &VecDeque<Token>) -> Result<Token, Eval
);
},
Function::ToBase
| Function::NoUnit
=> panic!()
}
}