From 4941bf8da055839927eb8c0916356463a51bdcfc Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 12 Oct 2026 23:29:56 -0400 Subject: [PATCH] ROUNDUP keeps #NUM! past the number range; only toward-zero rounding returns 0 Co-Authored-By: Claude Opus 5.5 --- crates/functions/src/math.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/functions/src/math.rs b/crates/functions/src/math.rs index f7d80a0..6410918 100644 --- a/crates/functions/src/math.rs +++ b/crates/functions/src/math.rs @@ -75,10 +75,11 @@ fn round_dir(x: f64, digits: i32, up: bool) -> f64 { } let s = clean(scaled); let r = if up { s.ceil() } else { s.floor() }; - // r == 0 with an infinite scale would be 0 * inf = NaN (#NUM!); the result is simply zero. + // Toward zero, r == 0 with an infinite scale would be 0 * inf = NaN (#NUM!); the result is simply + // zero. Away from zero the true result (10^309 or more) is not a number, so ROUNDUP stays #NUM!. let out = if !neg { clean(r / f) - } else if r == 0.0 { + } else if r == 0.0 && !up { 0.0 } else { r * f