From 3b5de555876ccb8d2f9d9a4ce9468dbf4632a980 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:37:05 +0100 Subject: [PATCH] Keep huge finite values finite when stepping number fields (#1753) Found while testing crates/ui-egui/src/widgets/field_math.rs:168 (stepped, used by widgets.rs:131 scrubbed) Co-authored-by: Claude Haiku 5.5 --- crates/ui-egui/src/widgets/field_math.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/widgets/field_math.rs b/crates/ui-egui/src/widgets/field_math.rs index f81500e67..9de90e278 100644 --- a/crates/ui-egui/src/widgets/field_math.rs +++ b/crates/ui-egui/src/widgets/field_math.rs @@ -167,7 +167,12 @@ pub fn eval(text: &str, cur: Option) -> Option { /// (0.1 + 0.2). pub fn stepped(from: f64, steps: f64, step: f64) -> f64 { let v = from + steps * step; - if v.is_finite() { (v * 1e6).round() / 1e6 } else { from } + if !v.is_finite() { + return from; + } + let rounded = (v * 1e6).round() / 1e6; + // Past ~1.8e302 the scaling overflows; such a value has no dust to remove. + if rounded.is_finite() { rounded } else { v } } #[cfg(test)] @@ -182,4 +187,10 @@ mod tests { assert_eq!(parse("50 %", true), Some(Typed::Value(50.0))); assert_eq!(parse("3 px + 2 px", true), Some(Typed::Value(5.0))); } + + #[test] + fn stepped_keeps_a_huge_finite_value_finite() { + assert_eq!(stepped(1e305, 1.0, 1.0), 1e305); + assert!(stepped(f64::MAX / 2.0, 0.0, 1.0).is_finite()); + } }