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
|
- Reference previous results
|
||||||
- Minimize parenthesis when printing expressions
|
- Minimize parenthesis when printing expressions
|
||||||
- Sane autoconversion (mi + km)
|
- Sane autoconversion (mi + km)
|
||||||
- "per" as division?
|
|
||||||
- -> as "to"
|
- -> as "to"
|
||||||
- strip_unit function
|
- strip_unit function
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub fn eval_operator(op: &Operator, args: &VecDeque<Token>) -> Result<Token, Eva
|
||||||
Operator::ImplicitMultiply |
|
Operator::ImplicitMultiply |
|
||||||
Operator::Sqrt |
|
Operator::Sqrt |
|
||||||
Operator::Divide |
|
Operator::Divide |
|
||||||
|
Operator::DivideLong |
|
||||||
Operator::Subtract => { panic!() }
|
Operator::Subtract => { panic!() }
|
||||||
|
|
||||||
Operator::Negative => {
|
Operator::Negative => {
|
||||||
|
|
|
@ -12,6 +12,7 @@ use super::Function;
|
||||||
#[repr(usize)]
|
#[repr(usize)]
|
||||||
pub enum Operator {
|
pub enum Operator {
|
||||||
ModuloLong = 0, // Mod invoked with "mod"
|
ModuloLong = 0, // Mod invoked with "mod"
|
||||||
|
DivideLong,
|
||||||
UnitConvert,
|
UnitConvert,
|
||||||
Subtract,
|
Subtract,
|
||||||
Add,
|
Add,
|
||||||
|
@ -69,6 +70,7 @@ impl Operator {
|
||||||
"i*" => {Some( Operator::ImplicitMultiply )},
|
"i*" => {Some( Operator::ImplicitMultiply )},
|
||||||
"%" => {Some( Operator::Modulo )},
|
"%" => {Some( Operator::Modulo )},
|
||||||
"mod" => {Some( Operator::ModuloLong )},
|
"mod" => {Some( Operator::ModuloLong )},
|
||||||
|
"per" => {Some( Operator::DivideLong )},
|
||||||
"to" => {Some( Operator::UnitConvert )},
|
"to" => {Some( Operator::UnitConvert )},
|
||||||
"^"|"**" => {Some( Operator::Power )},
|
"^"|"**" => {Some( Operator::Power )},
|
||||||
"!" => {Some( Operator::Factorial )},
|
"!" => {Some( Operator::Factorial )},
|
||||||
|
@ -146,6 +148,7 @@ impl Operator {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Operator::DivideLong |
|
||||||
Operator::Divide => {
|
Operator::Divide => {
|
||||||
if args.len() != 2 { panic!() }
|
if args.len() != 2 { panic!() }
|
||||||
let a = args.pop_front().unwrap();
|
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 => {
|
Operator::UnitConvert => {
|
||||||
return format!(
|
return format!(
|
||||||
"{} to {}",
|
"{} to {}",
|
||||||
|
|
Loading…
Reference in New Issue