Ast: fix big float prints
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful

This commit is contained in:
Akemi Izuko 2023-11-18 00:49:26 -07:00
parent a1ae14934b
commit bb34acfcfd
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 15 additions and 3 deletions

View file

@ -1,7 +1,7 @@
[global_flow]
gen_decl = 0.5
gen_decl = 0.6
gen_subroutine = 0.0
gen_typedef = 0.4
gen_typedef = 0.3
end_generation = 0.1
[statements]

View file

@ -56,7 +56,19 @@ impl ToString for Literal {
fn to_string(&self) -> String {
match *self {
Literal::Int(x) => x.to_string(),
Literal::Real(x) => x.to_string(),
Literal::Real(x) => {
let mut s = x.to_string();
let nb_zeros = s.chars().rev().position(|x| x != '0').unwrap_or(0);
if nb_zeros > 3 {
s = String::from(&s[..s.len()-nb_zeros]);
s.push('e');
s.push('+');
s.push_str(&nb_zeros.to_string());
}
s
}
}
}
}