Skip to content

det runtime: arithmetic intermediates are not truncated as the oracle's ARITHMETIC-OSVS (IBM's fixed-point decimal places) truncates them (register C2) #4287

Closed

Description

@squid-protocol

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_dmax from the receivers and cb_walk_cond (divisors are excluded), and expr_decp per 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, and cob_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

  1. added
    bug
    legacy-modernization
    priority: high
    on Oct 8, 2026
  2. added
    scope:core
    era:2
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugera:2legacy-modernizationpriority: highscope:core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions