Keep huge finite values finite in round_to (#2309)

Found while testing crates/geom/src/transform.rs:58 (round_to), used by crates/engine/src/automation/inspect.rs:517 (round)

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilverandClaude Haiku 5.5 authored and GitHub committed 2026-11-13 01:42:15 +01:00
1 parent 40360c4a2a
commit c47de279a7
2 files changed
+12 -1

No files matched your search

+6
View File
@@ -306,6 +306,12 @@ fn round_to_handles_large_precision_without_changing_finite_values() {
assert_eq!(round_to(1.23456, 2), 1.23);
}
#[test]
fn round_to_keeps_huge_finite_values_finite() {
assert_eq!(round_to(1e307, 2), 1e307);
assert_eq!(round_to(-1e307, 2), -1e307);
}
#[test]
fn reverse_subpaths_preserves_open_and_closed() {
let mut open = BezPath::new();
+6 -1
View File
@@ -60,6 +60,11 @@ pub fn round_to(v: f64, digits: i32) -> f64 {
if v.is_finite() && !f.is_finite() {
return v;
}
let r = (v * f).round() / f;
let scaled = v * f;
if v.is_finite() && !scaled.is_finite() {
// Too large to have a fractional part at this scale; already whole.
return v;
}
let r = scaled.round() / f;
if r == 0.0 { 0.0 } else { r }
}