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 {
|
match string {
|
||||||
"+" => Some(Add),
|
"+" => Some(Add),
|
||||||
"-" => Some(Subtract),
|
"-" | "−" => Some(Subtract),
|
||||||
"*" => Some(Multiply),
|
"*" | "×" => Some(Multiply),
|
||||||
"/" => Some(Divide),
|
"/" | "÷" => Some(Divide),
|
||||||
"^" => Some(Power),
|
"^" => Some(Power),
|
||||||
"//" => Some(Floor),
|
"//" => Some(Floor),
|
||||||
"%" => Some(Modulo),
|
"%" => Some(Modulo),
|
||||||
@ -145,19 +145,19 @@ fn eval(
|
|||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let (x, y) = (
|
let (x, y) = (
|
||||||
&stack.pop_back().unwrap(),
|
stack.pop_back().unwrap(),
|
||||||
&stack.pop_back().unwrap(),
|
stack.pop_back().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
match op {
|
match op {
|
||||||
Add => &stack.push_back(y + x),
|
Add => stack.push_back(y + x),
|
||||||
Subtract => &stack.push_back(y - x),
|
Subtract => stack.push_back(y - x),
|
||||||
Multiply => &stack.push_back(y * x),
|
Multiply => stack.push_back(y * x),
|
||||||
Divide => &stack.push_back(y / x),
|
Divide => stack.push_back(y / x),
|
||||||
Power => &stack.push_back(x.powf(*y)),
|
Power => stack.push_back(x.powf(y)),
|
||||||
Floor => &stack.push_back((y / x).floor()),
|
Floor => stack.push_back((y / x).floor()),
|
||||||
Modulo => &stack.push_back(y % x),
|
Modulo => stack.push_back(y % x),
|
||||||
_ => &{},
|
_ => {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user