forked from bonsai/harakit
rpn(1): added floor division
This commit is contained in:
parent
42d268319e
commit
b68f13acdc
@ -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),
|
||||
_ => &{},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user