Repository navigation
det runtime: a zero divisor leaves the receivers unchanged, as the oracle (#4655) - #4677
Merged
Merged
Conversation
…SVS does (#4287) The det translator replays cobc -std=ibm's compile-time ARITHMETIC-OSVS decision (det/osvs.py, from GnuCOBOL 3.1.2 typeck.c / tree.c): dmax from receivers and cb_walk_cond, the expr_decp stack with its pushes, pending aligns flushed on the next load, constant folding, conditions built right to left, the state an EVALUATE leaves to its sentence. It emits Cobol.align (libcob's cob_decimal_align, its downward shift included) where cobc emits cob_decimal_align, and a literal on the right of an operation as a Cobol.Dc (libcob's decimal constant, whose scale its uses change). Cobol.divide keeps cob_decimal_div's places and Cobol.power cob_decimal_pow's trimming. Register C2 rewritten: the det runtime matches the oracle; the oracle's departures from IBM's rule are listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The oracle (GnuCOBOL 3.1.2 -std=ibm) leaves every receiver unchanged on a zero divisor, with or without ON SIZE ERROR; the det port threw ArithmeticException. Cobol.divide now returns libcob's NaN (scale -32768) and raises the statement's size error; add/subtract/multiply/negate/power carry it where the translator sees a division or exponent below; store/storeChecked leave the receiver (lifted receivers guarded with isNan); Cobol.align truncates a NaN to 0 as libcob does. A division in a function argument is 0 (cob_intr_binop); FUNCTION MOD/REM by zero are 0. 0 ** 0 raises the size error; a non-finite exponent is NaN. Statements with ON SIZE ERROR clear and read the size-error state. DIVIDE REMAINDER now uses the quotient truncated to the receiver's places (cob_div_quotient), not the stored quotient. Register entry oracle_assumptions C14 (IBM: undefined / S0CB on z/OS). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…4655) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
This was referenced Oct 8, 2026
expr imported det.cics (for DFHRESP) and det.cvda lazily, and det.cics imported det.gen, which imports det.osvs, which imports expr. expr now imports DFHRESP from gitgalaxy.standards.cics.resp (its home) and CVDA from det.cvda (no imports) at module level, so expr no longer reaches gen. Also one import form for test_det_programs in test_det_osvs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D
# Conflicts: # gitgalaxy/tools/cobol_to_java/det/expr.py
…CodeQL) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D
Conflicts in oracle_assumptions.md, Cobol.java and gen.py came from #4654's pre-squash commits: main's side taken, then this PR's own changes (6e1de82..f6da8e4) re-applied on top. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D
oracle_assumptions.md: both register entries kept, C13 (#4668) then C14 (this PR), in the table and the sections. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D
7 of 8 tasks
squid-protocol
marked this pull request as ready for review
October 8, 2026 20:57
squid-protocol
added a commit
that referenced
this pull request
Oct 8, 2026
#4681) (#4683) * det runtime: truncate arithmetic intermediates as cobc's ARITHMETIC-OSVS does (#4287) The det translator replays cobc -std=ibm's compile-time ARITHMETIC-OSVS decision (det/osvs.py, from GnuCOBOL 3.1.2 typeck.c / tree.c): dmax from receivers and cb_walk_cond, the expr_decp stack with its pushes, pending aligns flushed on the next load, constant folding, conditions built right to left, the state an EVALUATE leaves to its sentence. It emits Cobol.align (libcob's cob_decimal_align, its downward shift included) where cobc emits cob_decimal_align, and a literal on the right of an operation as a Cobol.Dc (libcob's decimal constant, whose scale its uses change). Cobol.divide keeps cob_decimal_div's places and Cobol.power cob_decimal_pow's trimming. Register C2 rewritten: the det runtime matches the oracle; the oracle's departures from IBM's rule are listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * oracle_assumptions C2: the differential run's size as measured (#4287) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * det runtime: a zero divisor is libcob's NaN, receivers unchanged (#4655) The oracle (GnuCOBOL 3.1.2 -std=ibm) leaves every receiver unchanged on a zero divisor, with or without ON SIZE ERROR; the det port threw ArithmeticException. Cobol.divide now returns libcob's NaN (scale -32768) and raises the statement's size error; add/subtract/multiply/negate/power carry it where the translator sees a division or exponent below; store/storeChecked leave the receiver (lifted receivers guarded with isNan); Cobol.align truncates a NaN to 0 as libcob does. A division in a function argument is 0 (cob_intr_binop); FUNCTION MOD/REM by zero are 0. 0 ** 0 raises the size error; a non-finite exponent is NaN. Statements with ON SIZE ERROR clear and read the size-error state. DIVIDE REMAINDER now uses the quotient truncated to the receiver's places (cob_div_quotient), not the stored quotient. Register entry oracle_assumptions C14 (IBM: undefined / S0CB on z/OS). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * det gen: a distinct name for the lifted DIVIDE INTO quotient (mypy) (#4655) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * det parse: the abbreviated 'OR NOT = x' / 'AND NOT = x' relation parses (#4681) Holes 1 and 2 (D0 + 1 > Q3, S3 NOT < 3 + B0 * - D0) already agree with cobc on this base (#4654/#4677); an end-to-end test pins them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: break det osvs/expr import cycle (CodeQL) expr imported det.cics (for DFHRESP) and det.cvda lazily, and det.cics imported det.gen, which imports det.osvs, which imports expr. expr now imports DFHRESP from gitgalaxy.standards.cics.resp (its home) and CVDA from det.cvda (no imports) at module level, so expr no longer reaches gen. Also one import form for test_det_programs in test_det_osvs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D * chore: one import form for test_det_programs in test_det_size_error (CodeQL) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
squid-protocol
added a commit
that referenced
this pull request
Oct 8, 2026
…merged) The conflicts were #4677's pre-squash commits against its squash (identical trees): this branch's side kept; #4683's stmt.py / test_det_conditions.py merged as main has them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D
squid-protocol
added a commit
that referenced
this pull request
Oct 8, 2026
Takes main's side of #4677 / #4654's pre-squash hunks and keeps #4689's own changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MQNoe4wPJgr7dbUvs3DG6D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #4654 — merge that first.
Fixes #4655
What the oracle does (GnuCOBOL 3.1.2
-std=ibm, measured 2026-10-07)A zero divisor makes libcob's NaN intermediate (
cob_decimal_div), NaN in → NaN out, and storing a NaN leaves the receiver unchanged. With or without ON SIZE ERROR:COMPUTE R R2 = A / Z: whole statement, no receiver changes;A / Z + 1,(A / Z) * 0 + 7,Z / Zchange nothing either.DIVIDE Z INTO R R2: per receiver, each unchanged;DIVIDE A BY Z GIVING Q REMAINDER RM: Q and RM unchanged.cob_decimal_alignturns NaN into 0:COMPUTE R = A / Z * Cstores 0, and with ON SIZE ERROR the phrase still runs. In conditions an aligned NaN is 0 (A / Z = 0true) and an unaligned one compares as dividend×10^32768 (0 = A / Zfalse).cob_intr_binop) and raises the size error; FUNCTION MOD / REM by zero give 0 with no size error.0 ** 0= 1 with the size error raised;0 ** -n= 0 with no size error; a negative ** fraction, or an overflowing exponent, leaves the receiver unchanged with the size error.Changes (arithmetic / divide path only)
Cobol.java:NAN_SCALE,isNan,nan, a per-thread size-error state (sizeClear/sizeRaised/ privateraiseSize), NaN-awareadd/subtract/multiply/negate(BigDecimal overloads),divide(NaN, no throw),divideIntr,remainder, NaN guards in theDcvariants andpower(0 ** 0, non-finite double),store/storeChecked(NaN → unchanged / true).Cobol.alignunchanged: it already truncates a NaN to 0 as libcob does.Funcs.java:mod,rem— zero divisor → 0.Hfp.java: comment only.gen.py:num_op(NaN-aware ops only where_may_nan: a/or**below;divideIntrinside function args viaintr_func),store_all(lifted receivers guarded withisNan; ON SIZE ERROR statements with/or**clear and read the size-error state;afterlines before the phrases),arith(REMAINDER viaCobol.remainderbefore the SIZE ERROR phrases; lifted DIVIDE INTO guarded), new_may_nan/_raises_size. Not touched:move, edit/num, compare paths (equivalence: model the oracle's MOVE of a non-digit zoned item to a binary item (#4652) #4663 / det translator: model DECIMAL-POINT IS COMMA; document the refusals #4462 keeps (#4462) #4666 / det: a numeric-edited item compared with a number is a text comparison (#4665) #4668).DIVIDE 6 INTO 59 GIVING Q ROUNDED REMAINDER RM→ RM 5).oracle_assumptions.mdC14 (C13 is taken on det runtime: numeric-edited item compared with a numeric literal numerically; GnuCOBOL compares it as text #4665's branch) with IBM's rule (paraphrased, marked to confirm against the Language Reference page: the page could not be fetched from the box) — undefined result / S0CB on z/OS without ON SIZE ERROR; DIFFERS:0 ** -nis a size error on IBM, 0 in the oracle.det_port_design.mdnotes.Evidence
tests/cobol_mainframe/test_det_size_error.py: codegen unit tests + one e2e program (48 output lines, every shape above, bytes and typed modes) — cobc vs det port equal, WANT pinned to the measured oracle values. Ran with EQUIVALENCE_E2E=1: 4 passed.det_port.py checkvsorigin/fix/4287-arith-osvs: 68/68 ports change through the runtime (Cobol.java / Funcs.java); 4 also change service code (carddemo-acctupdate: REMAINDER viaCobol.remainder; carddemo-intcalc(-generated), mortgage-mpmt: anisNanguard on a lifted COMPUTE receiver).proof_sweep.py --det-only(all cases): 65 PROVED, 3 NOT PROVEN, all three in the baseline (carddemo-cardupdate, carddemo-intcalc-generated, mortgage-mpmt) — "sweep: as expected", no verdict regression.evidence.py status --circ 0 (records were already stale on harness/oracle/generator only, which the scheduled refresh handles; no port/case/pin staleness);evidence_report.py --checkrc 0; test_evidence.py + test_evidence_report.py 71 passed. No evidence records changed.pr_gates.py --fast: 5/5 pass.pr_gates.py --ratchets: 7 pass, 0 fail, 0 skipped.Follow-ups filed
🤖 Generated with Claude Code