feat: cap significant_digits to 10 in pretty_eval

This commit is contained in:
electria 2026-09-30 20:07:15 -07:00
commit 46c697234c
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -2,6 +2,8 @@ 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) -> 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
@ -17,7 +19,7 @@ pub fn pretty_eval(mut input: String) -> Result<String, Error> {
.is_some(); .is_some();
let result = nodes::eval(&input)?; let result = nodes::eval(&input)?;
let significant_digits = get_significant_digits(&result); let significant_digits = get_significant_digits(&result).min(MAX_DIGITS);
Ok(format!( Ok(format!(
"{}{}{result:.significant_digits$}{}", "{}{}{result:.significant_digits$}{}",