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

   Follow-up to #1275, the last of the "same misconception as bug 65792" sites.
   
   `SQRTPI`, `DSTDEV`, `DSTDEVP`, `DVAR` and `DVARP` rounded their result to 
the 15 significant digits Excel *displays* 
(`Double.parseDouble(NumberToTextConverter.toText(result))`), and `DAVERAGE`, 
`STANDARDIZE`, `DOLLARDE` and `DOLLARFR` computed in `BigDecimal`/`DECIMAL128` 
to land on that displayed value. Excel stores the full IEEE 754 result and only 
displays 15 digits, so:
   
   - `SQRTPI(2)` was stored as `2.506628274631`; Excel (and 
`Math.sqrt(2*Math.PI)`) is `2.5066282746310002`.
   - `DAVERAGE` of 96, 105, 76.8 gave `92.6` while POI's own 
`AVERAGE(96,105,76.8)` gives `92.60000000000001` — IEEE `277.8/3`, displayed as 
`92.6`. The two now agree.
   - `DOLLARDE(1.1,16)` was `1.6250000000000007` (exact `BigDecimal` arithmetic 
applied to a fractional part that was already the inexact IEEE 
`0.10000000000000009`); plain doubles give `1.6250000000000004`. Both display 
as `1.625`.
   
   All nine now use plain double arithmetic; 53 lines out, 11 in, and the 
`BigDecimal`/`NumberToTextConverter` round trips per call are gone. All of 
these were written this way when the functions were added in 2022 (the 
bug-65792 era), so no released behaviour regressed since — the effect is at 
most a few ulps and invisible after display, which is why this is a cleanup 
rather than a bug fix.
   
   Tests: new `Utils.assertDoubleAndDisplay(fe, cell, formula, exactIeeeValue, 
excelDisplayString)` pins both the bit-exact result and the 15-digit text Excel 
shows, used in new cases in `TestSqrtpi`, `TestDStdev`, `TestDVar`, 
`TestDAverage`, `TestStandardize`, `TestDollarDe`, `TestDollarFr`. The one 
existing expectation that changed is `TestDAverage`'s exact `92.6`, now 
`277.8/3` with display `"92.6"` (plus the `AVERAGE` cross-check). Ran those 
with `TestDStarRunner`, `TestAverage` and `TestFormulasFromSpreadsheet` 
locally: 408 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: [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]

Reply via email to