diff --git a/src/rpn.rs b/src/rpn.rs index 737325c..83af537 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -78,6 +78,10 @@ impl fmt::Display for EvaluationError { } } +// I’m no math nerd but I want the highest possible approximation of 0.9 +// repeating and it seems this can give it to me +const PRECISION_MOD: f64 = 0.9 + f64::EPSILON * 100.0; + // str_to_calc_type converts a string to an optional `CalcType`. fn str_to_calc_type(string: &str) -> Option { let as_int = string.parse::(); @@ -186,7 +190,7 @@ fn main() -> ExitCode { let argv = args().collect::>(); let mut stack = VecDeque::new(); let mut buf = String::new(); - let precision = (-f64::EPSILON.log10() * 0.999).ceil() as usize; + let precision = (-f64::EPSILON.log10() * PRECISION_MOD).ceil() as usize; if argv.get(1).is_none() { while let Ok(_) = stdin().read_line(&mut buf) {