feat: also check consecutive nines

fixes `tylc "12.0096 + 15.9994 * 2"`
This commit is contained in:
electria 2026-07-20 19:32:22 -07:00
commit c8bc766e2a
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -17,6 +17,7 @@ pub fn get_significant_digits(n: &Float) -> usize {
let mut significant_digits = raw_string.len() - 1; let mut significant_digits = raw_string.len() - 1;
let mut consecutive_zeros = 0; let mut consecutive_zeros = 0;
let mut consecutive_nines = 0;
for (i, c) in raw_string.char_indices() { for (i, c) in raw_string.char_indices() {
if c == '0' { if c == '0' {
consecutive_zeros += 1; consecutive_zeros += 1;
@ -24,9 +25,18 @@ pub fn get_significant_digits(n: &Float) -> usize {
consecutive_zeros = 0; consecutive_zeros = 0;
} }
if c == '9' {
consecutive_nines += 1;
} else {
consecutive_nines = 0;
}
if consecutive_zeros >= 10 { if consecutive_zeros >= 10 {
significant_digits = i - consecutive_zeros; significant_digits = i - consecutive_zeros;
break; break;
} else if consecutive_nines >= 10 {
significant_digits = i - consecutive_nines;
break;
} }
if !raw_string[i..raw_string.len()].contains(|c| matches!(c, '1'..'9')) { if !raw_string[i..raw_string.len()].contains(|c| matches!(c, '1'..'9')) {