pjfanning opened a new pull request, #1288:
URL: https://github.com/apache/poi/pull/1288
Same defect as #1278, fixed centrally. Functions taking an integer argument
converted it with `MathUtil.safeDoubleToInt`, whose `IllegalArgumentException`
escaped the evaluator for values like `1E10`; Excel reports an error value.
| Formula | Before | After (Excel) |
|---|---|---|
| `=DAY(1E308)`, `=DATE(1E10,1,1)`, `=EDATE(1,1E10)`, `=EOMONTH(1,1E10)`,
`=YEARFRAC(1E10,1)`, `=TIME(1E10,0,0)` | `IllegalArgumentException` | `#NUM!` |
| `=LARGE({1,2,3},1E10)`, `=RANK(1,{1,2,3},1E10)`, `=POISSON(1E10,1,TRUE)`,
`=ADDRESS(1E10,1)`, `=SUBTOTAL(1E10,{1,2})`, `=FIXED(1,1E10)` |
`IllegalArgumentException` | `#NUM!` |
| `=CHAR(1E308)`, `=LEFT("abc",1E10)`, `=MID("abc",1,1E10)`,
`=FIND("a","abc",1E10)`, `=REPT("x",1E10)`, `=CHOOSE(1E10,1,2)`, `=ROMAN(1E10)`
| `IllegalArgumentException` | `#VALUE!` |
| `=COMPLEX(1E10,1)` | `IllegalArgumentException` | `10000000000+i` |
- New `OperandResolver.coerceDoubleToInt(double)` (`@since 6.0.0`):
truncates toward zero, throws `EvaluationException(#NUM!)` for NaN or
out-of-range. `coerceValueToInt` now uses it, and the direct `safeDoubleToInt`
callers in `ss.formula` are switched over (`MathUtil.safeDoubleToInt` itself is
unchanged — its other callers are in the drawing code where an exception is the
right outcome).
- `TextFunction.evaluateIntArg` and `Choose.evaluateFirstArg` translate the
`#NUM!` to `#VALUE!`, which is what Excel gives for an unusable count, position
or index.
- `COMPLEX` renders its parts with `NumberToTextConverter` instead of
`safeDoubleToInt`/`Double.toString`, so large integers work and
`COMPLEX(0.1+0.2,0.5)` is `0.3+0.5i` as in Excel rather than
`0.30000000000000004+0.5i`.
Left alone: `WorkdayCalculator`/`DateUtil.getJavaCalendar` still throw for a
*date* serial beyond the int range (`WEEKDAY(1E10)`, `NETWORKDAYS(1E10,1)`);
that is a date-range check rather than an int-conversion one and comes with the
date PR.
Tests: new `TestIntegerArguments` plus
`TestOperandResolver.testCoerceDoubleToInt`; `org.apache.poi.ss.formula.*` and
`ss.usermodel.*` pass.
🤖 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]