diff --git a/internal/compiler/generator/cpp.rs b/internal/compiler/generator/cpp.rs index 2726302cc37..995f0a88443 100644 --- a/internal/compiler/generator/cpp.rs +++ b/internal/compiler/generator/cpp.rs @@ -3268,6 +3268,7 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String '&' => "&&", '|' => "||", '/' => "/(float)", + '-' => "-(float)", // conversion to float to avoid overflow between unsigned _ => op.encode_utf8(&mut buffer), }, ) diff --git a/tests/cases/elements/image.slint b/tests/cases/elements/image.slint index 61e442bac0f..01398a289c8 100644 --- a/tests/cases/elements/image.slint +++ b/tests/cases/elements/image.slint @@ -21,8 +21,9 @@ TestCase := Rectangle { property img_width: img.width; property img_height: img.height; + in-out property test_no_overflow: (21 - img.source.width) / 2; // (21 - 320)/2 = -149.5 property test: img2.source-clip-height * 1px == img2.height && img2.source-clip-width * 1px == img2.width && - img2.width/1px == img2.source.width - 20 && img3.source.width == 0 && img3.source.height == 0; + img2.width/1px == img2.source.width - 20 && img3.source.width == 0 && img3.source.height == 0 && test_no_overflow == -149.5; } /*