# COBCALC — Genyra

> A COBOL expression evaluator rebuilt in Rust with 34-digit decimal arithmetic, verified exactly against a decimal reference and to 2e-12 against the original.

Canonical page: https://genyra.com/engineering/lab/cobcalc

A standalone COBOL expression evaluator rebuilt in Rust with explicit decimal arithmetic: 1,000 exact-decimal cases with zero failures, 2,000 of 2,000 legacy comparisons within a stated tolerance, and a 13-expression transcript that matches byte for byte.

## Why a calculator belongs in the Lab.

Precedence, right-associative powers, signed literals that bind before powers, commas inside integers, a square root, errors with a column number: COBCALC is small enough to read in an afternoon and complete enough to carry every question a numerical migration raises. Above all it carries the question of the number type, because the original keeps its result stack in COMP-2, which is binary floating point.

The Rust reconstruction keeps the grammar and changes the arithmetic deliberately: 34 significant digits, half-even, with a 50-digit working context for the operations that cannot be exact. 0.1 + 0.2 is 0.3.

## Two standards, never confused.

Because the original is floating point, agreement with it can only ever be agreement within a tolerance. So the Lab publishes two separate results. The exact-decimal contract: 1,000 deterministic cases compared as decimals with an independent reference, zero tolerance, zero failures. Legacy compatibility: 2,000 expressions run against the real GnuCOBOL original within an absolute and relative tolerance of 2e-12, 2,000 passing, largest observed difference about 1e-7. A selected 13-expression session additionally matches the original transcript byte for byte.

The second result is numerical compatibility. It is not a financial-equivalence claim, and the repository says so in its own verification file.

## The boundary of the claim.

An algebraic evaluator, not a banking, tax or payroll engine. Migrating such a system also requires each copybook's exact scale, receiving-field rounding policy, size-error behaviour and record encodings, and those must be verified separately and compared byte for byte. Choosing a decimal library proves none of them on its own.

## Questions we are asked

**Why not make the Rust version match the COBOL output exactly?** Because the original's output is sometimes wrong in the way binary floating point is wrong: it displays 0.29999 for 0.1 + 0.2. Reproducing that would preserve an artefact rather than a rule. The reconstruction states a decimal contract instead, and measures its distance from the original honestly, within a published tolerance.

**Is there a live calculator on this page?** No. The outputs shown are recorded from the published Rust binary and the verification transcripts. A browser calculator would have to implement the documented grammar and numeric rules faithfully to be worth showing; until it does, recorded demonstrations are the honest choice.

## Related work

- [Engineering Lab](https://genyra.com/engineering/lab): Legacy system migration evidence: three COBOL applications replaced by verified Rust reconstructions, and a native Rust desktop measured against its original.
- [Legacy Ledger & Payroll](https://genyra.com/engineering/lab/legacy-ledger): 13 COBOL banking and payroll programs reconstructed in Rust with exact fixed-point arithmetic: 2,174 exact file comparisons against the originals, 0 failures.
- [Legacy system modernisation](https://genyra.com/solutions/legacy-modernisation): Legacy modernization services: COBOL and mainframe application modernization to native software, not a conversion to the JVM estate that is now the next legacy.
- [Performance engineering](https://genyra.com/solutions/performance-engineering): Application performance engineering: measure the real path, find the constraint in code, data or infrastructure, fix it and prove the change with evidence.

Contact: contact@genyra.com

Genyra LLC and the Dubai business Genyra L.L.C-FZ / Genyra.ai are distinct entities. Project scope and the contracting entity are agreed explicitly.
