Fix compilation when dividing by zero at compile time

Rust would have panicked and C++ generated wrong code.

CC #3982
This commit is contained in:
Olivier Goffart 2023-11-24 12:26:09 +01:00
parent 8a841405c8
commit 6195fc8567
3 changed files with 18 additions and 8 deletions

View file

@ -2524,7 +2524,10 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String
format!(r#"slint::SharedString(u8"{}")"#, escape_string(s.as_str()))
}
Expression::NumberLiteral(num) => {
if *num > 1_000_000_000. {
if !num.is_finite() {
// just print something
"0.0".to_string()
} else if num.abs() > 1_000_000_000. {
// If the numbers are too big, decimal notation will give too many digit
format!("{:+e}", num)
} else {