Added "per" division

pull/2/head
Mark 2023-06-14 08:59:06 -07:00
parent bb73350613
commit 24b221bf42
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
3 changed files with 12 additions and 1 deletions

View File

@ -2,7 +2,6 @@
- Reference previous results
- Minimize parenthesis when printing expressions
- Sane autoconversion (mi + km)
- "per" as division?
- -> as "to"
- strip_unit function

View File

@ -16,6 +16,7 @@ pub fn eval_operator(op: &Operator, args: &VecDeque<Token>) -> Result<Token, Eva
Operator::ImplicitMultiply |
Operator::Sqrt |
Operator::Divide |
Operator::DivideLong |
Operator::Subtract => { panic!() }
Operator::Negative => {

View File

@ -12,6 +12,7 @@ use super::Function;
#[repr(usize)]
pub enum Operator {
ModuloLong = 0, // Mod invoked with "mod"
DivideLong,
UnitConvert,
Subtract,
Add,
@ -69,6 +70,7 @@ impl Operator {
"i*" => {Some( Operator::ImplicitMultiply )},
"%" => {Some( Operator::Modulo )},
"mod" => {Some( Operator::ModuloLong )},
"per" => {Some( Operator::DivideLong )},
"to" => {Some( Operator::UnitConvert )},
"^"|"**" => {Some( Operator::Power )},
"!" => {Some( Operator::Factorial )},
@ -146,6 +148,7 @@ impl Operator {
)
},
Operator::DivideLong |
Operator::Divide => {
if args.len() != 2 { panic!() }
let a = args.pop_front().unwrap();
@ -232,6 +235,14 @@ impl Operator {
);
},
Operator::DivideLong => {
return format!(
"{} per {}",
self.add_parens_to_arg(&args[0]),
self.add_parens_to_arg(&args[1])
);
},
Operator::UnitConvert => {
return format!(
"{} to {}",