Repository navigation
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…uted as 0, as Excel holds it
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…uted as 0, as Excel holds it
Split out of #1462 (part 2 of 5).
Problem
Excel holds any number smaller than 2.2250738585072014E-308 in size as 0, whether typed, read from a file or computed. GridCraft kept the IEEE 754 subnormal.
Why the subnormal case? Isn't Excel objectively worse than an IEEE 754 subnormal (gradual underflow)?
Well... yes, it technically is numerically, 2^-1074 is exactly representable as a double, so 5E-324 is the true answer and 0 is wrong however:
5E-324in a cell, but formulas that depend on it come out differently:A workbook built in Excel that guards against zero would branch differently in GridCraft. Its results would then differ from Excel's in ordinary-looking cells.
2^-1074has exactly one bit, so it says "roughly 5E-324" and little more. Real spreadsheets don't get there except through underflow, and Excel's display wouldn't show it anyway.Measured black-box in Windows Excel (Microsoft 365, 16.0.20430.20146, 64-bit) with synthetic workbooks; Mac Excel 16.113 agrees. Raw output: Spreadsheet Accuracy Suite, request 5.
Fix
Value::number(crates/core/src/value.rs) returns 0 for a subnormal result.CellStore::set(crates/model/src/store.rs) stores a subnormal number as 0. This also changes what a file load stores: a subnormal read from a workbook becomes 0, as Excel reads it.f64::MIN_POSITIVEitself and everything larger are unchanged.Testing
crates/calc/src/tests.rs:a_subnormal_number_is_zero(fails without the fix).crates/functions/src/stat/tests.rs:median_midpoint_keeps_small_values_and_argument_semanticsnow expects 0 for a subnormal MEDIAN and still expectsf64::MIN_POSITIVEto survive.cargo fmt --all -- --checkandcargo test -p gridcraft-calc -p gridcraft-functions(pass). I did not run the fullcargo xtask cion this branch.Summary by CodeRabbit