From 56d5f7bd063926db37ae3e6186779a7e200d34a3 Mon Sep 17 00:00:00 2001 From: electria Date: Sun, 15 Nov 2026 19:15:35 -0800 Subject: [PATCH] refactor: simplify min and max digits min and max methods are pretty confusing, this is much nicer. --- src/formatting.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index b7b6a58..fa7aed7 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -11,19 +11,19 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result { let should_add_back_backslash = input.contains('\\'); let result = nodes::eval(&input)?; - let display_digits = - get_significant_digits(&result) - .min(max_digits) - .max(if result >= 1000 || result < 1 { - 1 - } else if result >= 100 { - 3 - } else if result >= 10 { - 2 - // if result >= 1 - } else { - 1 - }); + let display_digits = get_significant_digits(&result).clamp( + if result >= 1000 || result < 1 { + 1 + } else if result >= 100 { + 3 + } else if result >= 10 { + 2 + // if result >= 1 + } else { + 1 + }, + max_digits, + ); Ok(format!( "{prefix}{deliminator}{result:.display_digits$}{}",