mirror of https://github.com/rm-dr/daisy
Added "per" division
parent
bb73350613
commit
24b221bf42
1
TODO.md
1
TODO.md
|
@ -2,7 +2,6 @@
|
|||
- Reference previous results
|
||||
- Minimize parenthesis when printing expressions
|
||||
- Sane autoconversion (mi + km)
|
||||
- "per" as division?
|
||||
- -> as "to"
|
||||
- strip_unit function
|
||||
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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 {}",
|
||||
|
|
Loading…
Reference in New Issue