feat: allow changing max_digits for pretty_eval

This commit is contained in:
electria 2026-10-04 16:27:34 -07:00
commit 2db19e7a46
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 3 additions and 5 deletions

View file

@ -2,9 +2,7 @@ use rug::Float;
use crate::nodes::{self, Error}; use crate::nodes::{self, Error};
pub const MAX_DIGITS: usize = 10; pub fn pretty_eval(mut input: String, max_digits: usize) -> Result<String, Error> {
pub fn pretty_eval(mut input: String) -> Result<String, Error> {
// no need to remove the characters here, // no need to remove the characters here,
// as we ignore the them in all other logic already // as we ignore the them in all other logic already
let should_add_back_alignment = input.contains('&'); let should_add_back_alignment = input.contains('&');
@ -21,7 +19,7 @@ pub fn pretty_eval(mut input: String) -> Result<String, Error> {
let result = nodes::eval(&input)?; let result = nodes::eval(&input)?;
let display_digits = let display_digits =
get_significant_digits(&result) get_significant_digits(&result)
.min(MAX_DIGITS) .min(max_digits)
.max(if result >= 1000 || result < 1 { .max(if result >= 1000 || result < 1 {
1 1
} else if result >= 100 { } else if result >= 100 {

View file

@ -17,7 +17,7 @@ fn main() -> ExitCode {
} }
}; };
match formatting::pretty_eval(input) { match formatting::pretty_eval(input, 10) {
Ok(s) => println!("{s}"), Ok(s) => println!("{s}"),
Err(e) => { Err(e) => {