-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
A-MathFundamental domain-agnostic mathematical operationsFundamental domain-agnostic mathematical operationsA-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed uponThis work is generally agreed upon
Description
Bevy version and features
eed2e0ebe
[Optional] Relevant system information
rustc 1.91.0-nightly (523d3999d 2025-08-30)
6.12.44 x86_64
12th Gen Intel i5-12600K
What went wrong
negative exponents in SliderPrecision
result in inaccurate numbers (e.g. 3999.999998 instead of 4000).
This can be fixed by multiplying by the reciprocal instead of dividing by the factor again, but then the same issue appears for positive exponents (e.g. 5.319999996 instead of 5.32).
fn round(&self, value: f32) -> f32 {
let factor = ops::powf(10.0_f32, self.0 as f32);
let rounded = (value * factor).round();
if self.0.is_positive() {
rounded / factor
} else {
let recip = ops::powf(10.0_f32, -self.0 as f32);
rounded * recip
}
}
this results in the right apparent numbers for both positive and negative exponents, but I'm not sure if this is in any way dependent on my machine/rustc/libm.
Metadata
Metadata
Assignees
Labels
A-MathFundamental domain-agnostic mathematical operationsFundamental domain-agnostic mathematical operationsA-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed uponThis work is generally agreed upon