1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Add emath::fast_midpoint (#7435)

This commit is contained in:
Emil Ernerfeldt
2025-08-08 12:04:51 +02:00
committed by GitHub
parent 3024c39eaf
commit 6fae65a3fa
5 changed files with 23 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
//! Find "simple" numbers is some range. Used by sliders.
use crate::fast_midpoint;
const NUM_DECIMALS: usize = 15;
/// Find the "simplest" number in a closed range [min, max], i.e. the one with the fewest decimal digits.
@@ -43,7 +45,7 @@ pub fn best_in_range_f64(min: f64, max: f64) -> f64 {
if min_exponent.floor() != max_exponent.floor() {
// pick the geometric center of the two:
let exponent = f64::midpoint(min_exponent, max_exponent);
let exponent = fast_midpoint(min_exponent, max_exponent);
return 10.0_f64.powi(exponent.round() as i32);
}