Skip to content

fix: an Analysis ToolPak function given a logical answers #VALUE! - #682

Merged
isamu merged 6 commits into
mainfrom
fix/excel-census-20261206
Dec 6, 2026
Merged

isamu merged 6 commits into
mainfrom
fix/excel-census-20261206

Conversation

@isamu

@isamu isamu commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #681 and #680 (its row 3). An Analysis ToolPak function (TOOLPAK_FUNCTIONS) now answers #VALUE! when an argument evaluates to a logical: written (=EDATE(45000,TRUE)), from a cell, or computed (=QUOTIENT(5,1=1)). Arguments are read in order, so an error before the logical is answered instead (=EDATE(1/0,TRUE) stays #DIV/0!; =EDATE(TRUE,1/0) is #VALUE!). ACCRINT's calc_method and the .INTL weekend still take a logical.

  • src/engine/toolpakLogicalRefusal.ts: the rule as a pure function. It is given a reader per place and stops at the first error or refused logical, so later arguments are never read.
  • src/engine/evaluator.ts: before a ToolPak handler runs, its arguments are read ahead through that reader. Ranges of cells are skipped, and so are arguments that may answer differently when evaluated again (the evaluatesAlike test that range arguments already use).
  • src/engine/emptyArgumentRefusal.ts: exports isToolPakFunction, so the list stays in one place.
  • tests/engine/test_toolpakLogicalArgument.ts and tests/engine/fixtures/toolpak-logical-argument-excel.json: tests of the rule in both directions, plus every recorded case this change fixes.

Items to Confirm / Review

  • Arguments are read ahead. A ToolPak call now evaluates its scalar arguments in order before the handler runs. Each value read is kept by its text for the duration of the call, and the handler's evaluateFormula answers from that store, so an argument is not evaluated twice. That is safe because only arguments that evaluate alike are read. Reading stops at the first error. Before that rule, a generated =AMORDEGRC(#VALUE!,…,19:8) written in row 8 read its own cell through implicit intersection and answered #REF!.
  • What is not read ahead. A place that takes an array (XNPV/XIRR values and dates, holidays, the FVSCHEDULE schedule, SERIESSUM coefficients, every place of GCD/LCM/MULTINOMIAL/IMSUM/IMPRODUCT) is read ahead only when it is one cell or a written TRUE/FALSE. Anything else there could be a whole array computed for nothing, such as =XNPV(0.1,A:A+0,B:B). Ranges and draws are not read either. An argument that is not read ends the check undecided, because it might hold an error that comes first: =GCD(NA()+1,FALSE) stays #N/A. As a result, a logical after such an argument is not refused, for example =GCD(A1:A3,TRUE). The same goes for a logical computed in an array place: =WORKDAY(1,5,IF(TRUE,TRUE,FALSE)) still answers 6, while a cell or a written TRUE there answers #VALUE!.
  • The exempt places come from the recordings. Only ACCRINT index 7 and the .INTL weekend (index 2) take a logical. The recorded WORKDAY.INTL(…,TRUE) and NETWORKDAYS.INTL(…,TRUE) answers still match.
  • List functions refuse too. GCD, LCM, MULTINOMIAL and IMSUM refuse a logical in any place, following formulon's rule. Only scalar arguments are checked; a logical inside a range is not.
  • RANDBETWEEN is in the list, but its arguments are only read when they evaluate alike.

Verification

  • Recorded set (formulon Mac 365 en_US goldens plus the IronCalc workbook goldens; the census harness from Census: where the engine's answers differ from Excel's recorded answers (formulon Mac 365 en-US, IronCalc workbooks), ranked by cause #680, run on origin/main 27abdc2 and on this branch): 162 cases went from fail to pass, across 48 functions. No case went from pass to fail, and no case that still fails changed its answer. I ran it again after merging main (origin/main against this branch's merge commit), and the result was the same: 162 fixed, 0 passes lost, 0 changed failing answers. Ran with drive.py over census.mts.
  • Generated formulas (tests/engine/formulaGenerator.ts, seeds 11, 22 and 33, 1000 formulas each, on the same 8×8 grid of numbers, logicals, text and errors on three sheets):
    • Plain expression() formulas: none changed out of 3000. The generator calls no ToolPak function.
    • ToolPak calls whose arguments are generated expressions or simple literals (RANDBETWEEN left out because it draws): 530 answers changed out of 3000. Each new answer is #VALUE!, and each has a logical argument with no error before it. 529 were confirmed automatically. The remaining one, =CONVERT(B2,"#N/A"&2,LET(x,TRUE,x)) (old #N/A), has the text "#N/A2" as its second argument, which is not an error, so the logical in the third argument decides.
  • yarn format && yarn lint && yarn build && yarn typecheck && yarn test && yarn test:engine && yarn test:fixtures && yarn quality all pass.

User Prompt

  • AI時代のスプレッドシートとしてExcelやGoogle Sheetsを超えるよう、Codexと並列で改善を続けて

work in GUIChatPluginSpreadsheet

🤖 Generated with Claude Code

isamu and others added 6 commits December 6, 2026 20:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Arguments are read in order up to the first error or refused logical;
ACCRINT's calc_method and the .INTL weekend still take a logical.
Part of #681.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tead of evaluating it again

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t read leaves the logical check undecided

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isamu

isamu commented Dec 6, 2026

Copy link
Copy Markdown
Member Author

Local Codex review ledger (codex exec)

round head result
R1 3-commit head R1.1: SPARKLINE read ahead draws twice. Rejected. sparklineCells.ts keeps the last chart per cell, so drawing twice sets the same chart again. A chart is shown only where the cell answers "", which a ToolPak function never does.
R2 same R2.1: arguments read ahead are evaluated twice. Accepted in 772ad2c: values read ahead are kept for the call and the handler's evaluateFormula answers from them.
R3 772ad2c LGTM
R4 772ad2c R4.1: array expressions in array places are computed ahead (=XNPV(0.1,A:A+0,B:B)). Accepted in 96e94ea: an array place is read only when it is one cell or a written logical, and an argument that is not read leaves the check undecided.
R5 a3e78d0 LGTM
R6 a3e78d0 R6.1: a logical computed in an array place is missed. Rejected as a documented limitation (Items to Confirm). Telling one value from an array means evaluating the expression, which R4.1 asked to avoid. The recorded cases put a logical there only as a cell or written.
— 6d0c3bc merged origin/main (evaluator.ts overlap), so the count restarted. The census rerun against the new main gave the same result.
R7 6d0c3bc LGTM
R8 6d0c3bc LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant