Repository navigation
fix(functions): reject negative fractions in GCD and LCM - #2072
Conversation
Validate the original input before truncation. Add scalar and range regressions, including signed zero, positive fractions and zero-first LCM validation.
Record tested edge-case behavior and update the parity revision history. Function counts and readiness estimates remain unchanged.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
FredApps
left a comment
There was a problem hiding this comment.
Read the whole change at 570d020.
integer_args in crates/functions/src/math.rs now checks the original value x against 0.0..9.007_199_254_740_992e15 instead of the truncated t, so -0.1, -0.5 and -0.999 give #NUM! rather than truncating to 0 and passing. -0.0 is still inside the range, NaN is outside it, and the upper bound is unchanged. The conversion t as u64 still uses the truncated value, so 12.9 and 18.9 still become 12 and 18.
The new test covers the scalar form, the range form (rf(row(&[2.0, x]))), a zero beside the negative fraction, signed zero, and the positive truncation case (GCD 6, LCM 36). Those are the cases the change could break. The parity doc and revision history are updated to match.
One point I have not checked against Excel itself: that Excel returns #NUM! for a negative fraction in GCD and LCM. The PR states it and the sign check matches Excel's documented rule for negative arguments.
CI at this head: cargo xtask ci is green.
|
I checked these formulas in a new, unsaved Excel workbook through Windows PowerShell COM (each formula entered into a cell and calculated):
These Excel results agree with rejecting the negative input before truncating it to an integer. |
Move the original negative-fraction regression into the existing extracted math tests. Scalar and range cases, zero-first validation, signed zero and positive truncation coverage are unchanged.
FredApps
left a comment
There was a problem hiding this comment.
Re-reviewed current head. Checking the original argument before truncation correctly rejects negative fractions for GCD and LCM, including range inputs and a zero companion, while preserving positive truncation and signed zero. Regression coverage matches those boundaries. Hosted Ubuntu gate is green; no local tests run. No blocking finding.
|
Merged after re-review of 4e4bd75 and verification of its successful hosted CI gate. No local tests were run for this review. Thank you for the fix. |
GCD(-0.5, 2) returns 2 and LCM(-0.5, 2) returns 0 on main: the shared integer helper truncates negative fractions to negative zero before validating their sign. Check the original argument first so both return #NUM!.
The regression covers scalar and range arguments, a zero before an invalid negative value, positive fractional truncation, and signed zero. Function parity notes record this behavior; counts and estimates are unchanged.
Behavior reference: Microsoft’s public GCD and LCM documentation specifies #NUM! for negative arguments and truncation for nonintegers. No desktop Excel oracle check is claimed.
Refreshed on upstream main
632e4a1bc51ee86b3f0a55e95ee78def391aab30on 2026-11-04. The merge preserves the extractedmod tests;layout and moves the original regression verbatim intocrates/functions/src/math/tests.rs.Validation on Windows with Rust 1.99 (GNULLVM):
cargo fmt --all -- --checkpasses.coreandfunctionssources were copied into an isolated workspace with the same dependency constraints and lints, using cached dependencies. The regression fails with the original predicate (GCD(-0.1, 2)returns 2), and all 19 math tests pass with the fix.cargo clippy -p gridcraft-functions --all-targets -- -D warningsand thewasm32-unknown-unknowncheck pass.engineering::tests::complex_numbers: an expected final digit.547iis.548ion this toolchain. The failure also occurs with the original predicate.cargo --offline xtask cicannot resolve the uncached pinned egui revision6d518fc7; local workspace gates could not run.Hosted integration validation at
4e4bd75e31cd11db5c1773b34c80d253d97bb295: CI / gate / gate (ubuntu-24.04) passed, runningcargo xtask ci. SonarCloud also passed. This supplies the full workspace integration evidence beyond the local isolated checks.Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
#NUM!for negative fractional inputs, including values in ranges and inputs paired with zero.Documentation