1
0
forked from bonsai/harakit

rpn(1): unicode subtraction, multiplication, division & code cleanup

This commit is contained in:
Emma Tebibyte 2024-02-01 13:06:46 -07:00
parent b68f13acdc
commit 0d97f81f49
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -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),
_ => {},
};
},
};