Compare commits

...
Author SHA1 Message Date
2db19e7a46
feat: allow changing max_digits for pretty_eval 2026-10-04 16:27:34 -07:00
2 changed files with 3 additions and 5 deletions

View file

@ -2,9 +2,7 @@ use rug::Float;
use crate::nodes::{self, Error};
pub const MAX_DIGITS: usize = 10;
pub fn pretty_eval(mut input: String) -> Result<String, Error> {
pub fn pretty_eval(mut input: String, max_digits: usize) -> Result<String, Error> {
// no need to remove the characters here,
// as we ignore the them in all other logic already
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 display_digits =
get_significant_digits(&result)
.min(MAX_DIGITS)
.min(max_digits)
.max(if result >= 1000 || result < 1 {
1
} 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}"),
Err(e) => {