mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Change mod()
to always return positive number (#6179)
* Change `mod()` to always return positive number Closes #6178 ChangeLog: The mod function was changed to always return a positive value (#6178)
This commit is contained in:
parent
ca64212369
commit
02467bd4cc
6 changed files with 30 additions and 10 deletions
|
@ -3297,7 +3297,7 @@ fn compile_builtin_function_call(
|
|||
}
|
||||
BuiltinFunction::Mod => {
|
||||
ctx.generator_state.conditional_includes.cmath.set(true);
|
||||
format!("std::fmod({}, {})", a.next().unwrap(), a.next().unwrap())
|
||||
format!("([](float a, float b) {{ return a >= 0 ? std::fmod(a, b) : std::fmod(a, b) + std::abs(b); }})({},{})", a.next().unwrap(), a.next().unwrap())
|
||||
}
|
||||
BuiltinFunction::Round => {
|
||||
ctx.generator_state.conditional_includes.cmath.set(true);
|
||||
|
|
|
@ -2713,7 +2713,10 @@ fn compile_builtin_function_call(
|
|||
quote!(sp::animation_tick())
|
||||
}
|
||||
BuiltinFunction::Debug => quote!(slint::private_unstable_api::debug(#(#a)*)),
|
||||
BuiltinFunction::Mod => quote!((#(#a as f64)%*)),
|
||||
BuiltinFunction::Mod => {
|
||||
let (a1, a2) = (a.next().unwrap(), a.next().unwrap());
|
||||
quote!(sp::Euclid::rem_euclid(&(#a1 as f64), &(#a2 as f64)))
|
||||
}
|
||||
BuiltinFunction::Round => quote!((#(#a)* as f64).round()),
|
||||
BuiltinFunction::Ceil => quote!((#(#a)* as f64).ceil()),
|
||||
BuiltinFunction::Floor => quote!((#(#a)* as f64).floor()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue