rpn(1): added floor division

This commit is contained in:
Emma Tebibyte 2024-02-01 12:38:12 -07:00
parent 42d268319e
commit b68f13acdc
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

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