refactor: simplify min and max digits

min and max methods are pretty confusing, this is much nicer.
This commit is contained in:
electria 2026-11-15 19:15:35 -08:00
commit 56d5f7bd06
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -11,10 +11,8 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
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 {
let display_digits = get_significant_digits(&result).clamp(
if result >= 1000 || result < 1 {
1
} else if result >= 100 {
3
@ -23,7 +21,9 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
// if result >= 1
} else {
1
});
},
max_digits,
);
Ok(format!(
"{prefix}{deliminator}{result:.display_digits$}{}",