docs(formatting): add note

This commit is contained in:
electria 2026-11-15 21:39:59 -08:00
commit 7a1049fda9
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -13,6 +13,13 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
let result = nodes::eval(&input)?;
let display_digits = get_significant_digits(&result).clamp(1, max_digits);
// this helps improve the output formatting,
// by not using scientific notation when it doesn't make sense.
//
// it does this by parsing the string, which is unfortunate.
// ideally, this would be done by reimplementing the display code;
// but neither I nor Edeth know how to do that yet.
// (much like with `get_significant_digits`)
let mut changing_string = format!("{result:.display_digits$}");
if let Some(index) = changing_string.find('e')
&& ((changing_string.chars().nth(index + 1).unwrap() == '-'