You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/09/18 11:28:59 UTC

[PR] QUOTIENT, FACT and ROUND/ROUNDUP/ROUNDDOWN/TRUNC: no IllegalArgumentException for arguments outside the int range [poi]

pjfanning opened a new pull request, #1278:
URL: https://github.com/apache/poi/pull/1278

   Follow-up to #1275 (same shape as the subnormal-divisor `ArithmeticException` it removed).
   
   These functions converted a double argument with `MathUtil.safeDoubleToInt`, which throws `IllegalArgumentException` for values outside the int range. The exception escaped `WorkbookEvaluator` instead of becoming an error value.
   
   - **`QUOTIENT(5E9,2)`** threw; Excel returns `2500000000`. The quotient is now truncated towards zero as a double (`Math.floor`/`Math.ceil`), and an infinite quotient (`QUOTIENT(1E308,1E-10)`) is `#NUM!`.
   - **`FACT(1E10)`** threw; Excel returns `#NUM!`. `MathX.factorial(double)` now does the range check itself: `>= 171` is infinity (hence `#NUM!` via `checkValue`), `<= -1` is NaN, otherwise truncate and use the int version. `FACT(170.9)` is still `170!`.
   - **`ROUND(1.5,1E10)`, `TRUNC(1.5,-1E10)`, `ROUNDUP`/`ROUNDDOWN`** threw. Digit counts *within* the int range but in the hundreds of millions were worse: `BigDecimal.setScale` built a number with that many digits and `ROUND(1.5,100000000)` ran for minutes. Digit counts are now clamped to ±400, beyond which rounding a double (15 significant digits, decimal exponent within ±324) cannot change the result — `ROUND(x,400)` and `ROUND(x,1E10)` give the same value as before for any `x`.
   
   I couldn't verify what Excel returns for `ROUND(1.5,1E10)` specifically (the clamp makes it `1.5`, i.e. the same as any large digit count, rather than an error), so happy to change that if you know.
   
   Not touched: the other `safeDoubleToInt` call sites (`DOLLAR` digits, `DATE`, `EDATE`, `EOMONTH`, `WORKDAY`, `REPT`, `ADDRESS`, `COMBIN`, `POISSON`, ...) have the same latent exception for absurd arguments; they can go in a later PR if wanted.
   
   Tests: new `TestQuotient.testQuotientOutsideIntRange`, `TestMathX.testFactorialDouble`, `TestNumericFunction.testFACTOutOfIntRange` / `testROUNDWithHugeDigitCount`. Ran `TestNumericFunction`, `TestQuotient`, `TestQuotientFunctionsFromSpreadsheet`, `TestMathX`, `TestRoundFuncs`, `TestTrunc`, `TestMultiOperandNumericFunction` and `TestFormulasFromSpreadsheet` locally: 446 tests, 0 failures.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] QUOTIENT, FACT and ROUND/ROUNDUP/ROUNDDOWN/TRUNC: no IllegalArgumentException for arguments outside the int range [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1278:
URL: https://github.com/apache/poi/pull/1278


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org