Repository navigation
Description
Problem
The det runtime computes arithmetic expressions in exact decimal (Cobol.divide keeps 38 extra digits; no intermediate is truncated). The oracle does not: cobc -std=ibm turns on arithmetic-osvs (/etc/gnucobol/ibm-strict.conf:115), and cobc then emits cob_decimal_align after each operation, truncating the intermediate to its decimal places. Those places follow IBM's fixed-point rules (Enterprise COBOL 6.4 Programming Guide SC27-8714-03, Appendix A, "Fixed-point data and intermediate results"): for /, the quotient keeps (d2 - d1) or dmax, whichever is greater decimal places, where dmax is the most decimal places of any operand or receiver.
So the oracle and IBM agree with each other, and the det runtime differs from both. Register C2 says "GnuCOBOL computes arithmetic in exact decimal". Under -std=ibm that is not true.
Reproducer (found 2026-10-03 working #4271)
01 A PIC 9 VALUE 1.
01 B PIC 9 VALUE 3.
01 C PIC 999 VALUE 300.
01 R PIC 999V99.
COMPUTE R = A / B * C- GnuCOBOL 3.1.2
-std=ibm:09900. A / B is aligned to dmax = 2 places (0.33), then × 300. -std=ibm -fno-arithmetic-osvs:09999.- det port (runProgram):
09999. - IBM (Appendix A rule): 2 decimal places on the quotient, so 99.00.
The same mechanism decides IBM DBB EPSMPMT's payment: the scenario maximum-principal gives 599550.79 with the aligns and 599550.51 without them.
Why no proof caught it
No proven scenario has a division or exponentiation whose result feeds another operation with fewer decimal places than the exact quotient carries. Mutation runs and new estates will reach it.
Proposal
- Model cobc's osvs scale tracking in the det translator:
expr_dmaxfrom the receivers andcb_walk_cond(divisors are excluded), andexpr_decpper operation (decimal_compute: + − max, * sum, / max(d1−d2, dmax), ** d1−d2 when smaller). - Emit an align in the runtime after each operation, with libcob's exact
cob_decimal_align. That includes its shift when the scale is below the target, andcob_decimal_pow's trimming of trailing zeros. - Do the same for conditions with arithmetic (
cb_build_cond). - Then run a full det sweep.
- Register C2 is then rewritten: the 30-digit cap of ARITH(COMPAT) is still not modelled by GnuCOBOL.
Related: #4271 (C5/C6).
🤖 Generated with Claude Code
Activity
det/oracle: NUMPROC(MIG/PFD) as IBM documents them; COMP-1/COMP-2 ref…
oracle_assumptions C2: the differential run's size as measured (#4287)
det runtime: truncate arithmetic intermediates as cobc's ARITHMETIC-O…
det runtime: a zero divisor leaves the receivers unchanged, as the or…
det parse: abbreviated 'OR NOT = x' relation; pin conditions holes 1-2 (
det: a float zero divisor is libcob's NaN; a phrase binds to the inne…
det: an unsigned binary ADD / SUBTRACT wraps as cobc's native arithme…