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