From 0d97f81f49b886038873cf7000f9bf7f75e31ded Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 1 Feb 2024 13:06:46 -0700 Subject: [PATCH] rpn(1): unicode subtraction, multiplication, division & code cleanup --- src/rpn.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/rpn.rs b/src/rpn.rs index c7a261d..16ba94f 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -94,9 +94,9 @@ fn str_to_calc_type(string: &str) -> Option { 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), + _ => {}, }; }, };