Skip to content

Commit 4622025

Browse files
committed
Use less precision when comparing vaue in slint language
In rust, use f32 instead of f64 for arithmetic comparison. In the interpreter, use approx_eq The test is failling in nightly because of precision change in `log`. By using f32, it actually should work Also Revert "Disable builds with nightly Rust temporarily" This reverts commit 4afc3a2. Fixes #5722
1 parent e4cb55b commit 4622025

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ jobs:
3535
- os: windows-2022
3636
rust_version: "beta"
3737
extra_args: "--exclude ffmpeg --exclude gstreamer-player"
38-
# Disable nightly until https://github.com/rust-lang/rust/issues/128386 is resolved
39-
# - os: ubuntu-22.04
40-
# rust_version: "nightly"
38+
- os: ubuntu-22.04
39+
rust_version: "nightly"
4140
exclude:
4241
- os: macos-12
4342
rust_version: "1.73"

internal/compiler/generator/rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ fn compile_expression(expr: &Expression, ctx: &EvaluationContext) -> TokenStream
21842184
| Type::Rem
21852185
) =>
21862186
{
2187-
(Some(quote!(as f64)), Some(quote!(as f64)))
2187+
(Some(quote!(as f32)), Some(quote!(as f32)))
21882188
}
21892189
_ => (None, None),
21902190
};

internal/interpreter/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use i_slint_compiler::langtype::Type as LangType;
66
use i_slint_core::component_factory::ComponentFactory;
77
#[cfg(feature = "internal")]
88
use i_slint_core::component_factory::FactoryContext;
9+
use i_slint_core::graphics::euclid::approxeq::ApproxEq as _;
910
use i_slint_core::model::{Model, ModelRc};
1011
#[cfg(feature = "internal")]
1112
use i_slint_core::window::WindowInner;
@@ -151,7 +152,7 @@ impl PartialEq for Value {
151152
fn eq(&self, other: &Self) -> bool {
152153
match self {
153154
Value::Void => matches!(other, Value::Void),
154-
Value::Number(lhs) => matches!(other, Value::Number(rhs) if lhs == rhs),
155+
Value::Number(lhs) => matches!(other, Value::Number(rhs) if lhs.approx_eq(rhs)),
155156
Value::String(lhs) => matches!(other, Value::String(rhs) if lhs == rhs),
156157
Value::Bool(lhs) => matches!(other, Value::Bool(rhs) if lhs == rhs),
157158
Value::Image(lhs) => matches!(other, Value::Image(rhs) if lhs == rhs),

0 commit comments

Comments
 (0)