Ast: fix big float prints
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful
This commit is contained in:
parent
a1ae14934b
commit
bb34acfcfd
2 changed files with 15 additions and 3 deletions
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue