From 5debb9d9549a456712d8147d71e7830f6d6852e6 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 1 Feb 2024 01:18:13 -0700 Subject: [PATCH] rpn(1): highest possible precision --- src/rpn.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) {