feat: also check consecutive nines
fixes `tylc "12.0096 + 15.9994 * 2"`
This commit is contained in:
parent
909bcfef6d
commit
c8bc766e2a
1 changed files with 10 additions and 0 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -17,6 +17,7 @@ pub fn get_significant_digits(n: &Float) -> usize {
|
|||
|
||||
let mut significant_digits = raw_string.len() - 1;
|
||||
let mut consecutive_zeros = 0;
|
||||
let mut consecutive_nines = 0;
|
||||
for (i, c) in raw_string.char_indices() {
|
||||
if c == '0' {
|
||||
consecutive_zeros += 1;
|
||||
|
|
@ -24,9 +25,18 @@ pub fn get_significant_digits(n: &Float) -> usize {
|
|||
consecutive_zeros = 0;
|
||||
}
|
||||
|
||||
if c == '9' {
|
||||
consecutive_nines += 1;
|
||||
} else {
|
||||
consecutive_nines = 0;
|
||||
}
|
||||
|
||||
if consecutive_zeros >= 10 {
|
||||
significant_digits = i - consecutive_zeros;
|
||||
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')) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue