forked from bonsai/harakit
rpn(1): unicode subtraction, multiplication, division & code cleanup
This commit is contained in:
parent
b68f13acdc
commit
0d97f81f49
26
src/rpn.rs
26
src/rpn.rs
@ -94,9 +94,9 @@ fn str_to_calc_type(string: &str) -> Option<CalcType> {
|
||||
|
||||
match string {
|
||||
"+" => Some(Add),
|
||||
"-" => Some(Subtract),
|
||||
"*" => Some(Multiply),
|
||||
"/" => Some(Divide),
|
||||
"-" | "−" => Some(Subtract),
|
||||
"*" | "×" => Some(Multiply),
|
||||
"/" | "÷" => Some(Divide),
|
||||
"^" => Some(Power),
|
||||
"//" => Some(Floor),
|
||||
"%" => Some(Modulo),
|
||||
@ -145,19 +145,19 @@ fn eval(
|
||||
},
|
||||
_ => {
|
||||
let (x, y) = (
|
||||
&stack.pop_back().unwrap(),
|
||||
&stack.pop_back().unwrap(),
|
||||
stack.pop_back().unwrap(),
|
||||
stack.pop_back().unwrap(),
|
||||
);
|
||||
|
||||
match op {
|
||||
Add => &stack.push_back(y + x),
|
||||
Subtract => &stack.push_back(y - x),
|
||||
Multiply => &stack.push_back(y * x),
|
||||
Divide => &stack.push_back(y / x),
|
||||
Power => &stack.push_back(x.powf(*y)),
|
||||
Floor => &stack.push_back((y / x).floor()),
|
||||
Modulo => &stack.push_back(y % x),
|
||||
_ => &{},
|
||||
Add => stack.push_back(y + x),
|
||||
Subtract => stack.push_back(y - x),
|
||||
Multiply => stack.push_back(y * x),
|
||||
Divide => stack.push_back(y / x),
|
||||
Power => stack.push_back(x.powf(y)),
|
||||
Floor => stack.push_back((y / x).floor()),
|
||||
Modulo => stack.push_back(y % x),
|
||||
_ => {},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user