bevyengine / bevyengine/bevy

`bevy_core_widgets` slider precision rounding issues

Open
#20,921 3 comments 0 reactions 0 assignees View on GitHub
A-Math A-UI C-Bug D-Straightforward S-Ready-For-Implementation X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

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).
```rust
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.