From b68f13acdc7430fd2aa0cfc235fef246bc0b6b4a Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 1 Feb 2024 12:38:12 -0700 Subject: [PATCH] rpn(1): added floor division --- src/rpn.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpn.rs b/src/rpn.rs index 5322ee6..c7a261d 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -50,7 +50,7 @@ use std::{ process::ExitCode, }; -use CalcType::{ Add, Divide, Modulo, Multiply, Power, Subtract, Val }; +use CalcType::{ Add, Divide, Floor, Modulo, Multiply, Power, Subtract, Val }; extern crate sysexits; @@ -64,6 +64,7 @@ enum CalcType { Multiply, Divide, Power, + Floor, Modulo, Val(f64), } @@ -97,6 +98,7 @@ fn str_to_calc_type(string: &str) -> Option { "*" => Some(Multiply), "/" => Some(Divide), "^" => Some(Power), + "//" => Some(Floor), "%" => Some(Modulo), _ => None, } @@ -153,6 +155,7 @@ fn eval( 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), _ => &{}, };