FA-61921 / Currency rounding and FX conversion / Open access
Triangulation multiplies by a pre-rounded inverse of the legacy rate · case 01
Large lira amounts convert to a EUR intermediate that is off by a few thousandths.
ROOT CAUSE
The source leg multiplies by 1/rate rounded to six decimals instead of dividing by the fixed rate.
VERIFIED REPAIR
Always divide by the published units-per-EUR rate; inverse rates are not permitted.
Unsuccessful approach: Rounding the inverse to ten decimals reduces but does not remove the error for large amounts.
Case contract
solve(amount, frm, to): stipulated legacy-currency triangulation. Fixed rates are units per 1 EUR (DEM 1.95583, FRF 6.55957, ITL 1936.27, ESP 166.386, IEP 0.787564, NLG 2.20371, BEF 40.3399, PTE 200.482, ATS 13.7603, FIM 5.94573). Exponents: ITL, ESP, BEF, PTE 0; others and EUR 2. Legacy to legacy: divide by the source rate, round the EUR intermediate half-up to 3 decimals, multiply by the target rate, round half-up to the target exponent. Legacy to EUR: divide and round half-up to 2 decimals. EUR to legacy: multiply and round half-up to the target exponent. Same currency: round the amount half-up to its exponent. Inverse rates are never used. Unknown codes return 'ERR:currency'.
Why this case matters
Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, frm, to):
rates = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
zero = ('ITL', 'ESP', 'BEF', 'PTE')
if frm not in rates or to not in rates: return 'ERR:currency'
def q(v, c):
return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
x = Decimal(amount)
if frm == to: return format(q(x, to), 'f')
if frm == 'EUR':
eur = x
elif to == 'EUR':
return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
else:
eur = (x * (Decimal(1) / Decimal(rates[frm])).quantize(Decimal('1e-6'))).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-rate 1', ('987654321', 'ITL', 'DEM'), '997631.50'),
('regression inverse-rate 2', ('123456789', 'ESP', 'FRF'), '4867136.96'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
[('regression inverse-rate 1', ('99999999', 'PTE', 'NLG'), '1099205.90'),
('regression inverse-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75')],
[('regression inverse-rate 1', ('2542824', 'FRF', 'ESP'), '64499703'),
('regression inverse-rate 2', ('204024', 'ESP', 'PTE'), '245833'),
('partial repair guard 1', ('2898066', 'FRF', 'ATS'), '6079401.18'),
('partial repair guard 2', ('1936907', 'ESP', 'FRF'), '76360.26'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
[('regression inverse-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
('regression inverse-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
('partial repair guard 1', ('3124364', 'BEF', 'FRF'), '508044.99'),
('partial repair guard 2', ('3838340.18', 'IEP', 'ATS'), '67063390.89'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
[('regression inverse-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
('regression inverse-rate 2', ('2414493', 'DEM', 'PTE'), '247497168'),
('partial repair guard 1', ('3438237', 'IEP', 'FRF'), '28636855.27'),
('partial repair guard 2', ('987654321', 'ITL', 'DEM'), '997631.50'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
for label, args, expected in cases[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression inverse-rate 1 | 996748.92 | 997631.50 | Failed |
| regression inverse-rate 2 | 4867038.93 | 4867136.96 | Failed |
| control: mark to franc | 335.38 | 335.38 | Passed |
| control: lira to euro | 516.46 | 516.46 | Passed |
| control: euro to lira | 19363 | 19363 | Passed |
| control: same currency rounding | 101 | 101 | Passed |
SHA-256 / 8979be4c2040c93433cd401b72e49ca296ff428a17fb6d3629aaaf49f6faf1a1
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, frm, to):
rates = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
zero = ('ITL', 'ESP', 'BEF', 'PTE')
if frm not in rates or to not in rates: return 'ERR:currency'
def q(v, c):
return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
x = Decimal(amount)
if frm == to: return format(q(x, to), 'f')
if frm == 'EUR':
eur = x
elif to == 'EUR':
return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
else:
eur = (x * (Decimal(1) / Decimal(rates[frm])).quantize(Decimal('1e-10'))).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-rate 1', ('987654321', 'ITL', 'DEM'), '997631.50'),
('regression inverse-rate 2', ('123456789', 'ESP', 'FRF'), '4867136.96'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
[('regression inverse-rate 1', ('99999999', 'PTE', 'NLG'), '1099205.90'),
('regression inverse-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75')],
[('regression inverse-rate 1', ('2542824', 'FRF', 'ESP'), '64499703'),
('regression inverse-rate 2', ('204024', 'ESP', 'PTE'), '245833'),
('partial repair guard 1', ('2898066', 'FRF', 'ATS'), '6079401.18'),
('partial repair guard 2', ('1936907', 'ESP', 'FRF'), '76360.26'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
[('regression inverse-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
('regression inverse-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
('partial repair guard 1', ('3124364', 'BEF', 'FRF'), '508044.99'),
('partial repair guard 2', ('3838340.18', 'IEP', 'ATS'), '67063390.89'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
[('regression inverse-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
('regression inverse-rate 2', ('2414493', 'DEM', 'PTE'), '247497168'),
('partial repair guard 1', ('3438237', 'IEP', 'FRF'), '28636855.27'),
('partial repair guard 2', ('987654321', 'ITL', 'DEM'), '997631.50'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
for label, args, expected in cases[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression inverse-rate 1 | 997631.51 | 997631.50 | Failed |
| regression inverse-rate 2 | 4867136.92 | 4867136.96 | Failed |
| control: mark to franc | 335.38 | 335.38 | Passed |
| control: lira to euro | 516.46 | 516.46 | Passed |
| control: euro to lira | 19363 | 19363 | Passed |
| control: same currency rounding | 101 | 101 | Passed |
SHA-256 / e9e230f2689ca966f37bc3e290e4e2912bcc89b00aa56fbff52b317249867351
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, frm, to):
rates = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
zero = ('ITL', 'ESP', 'BEF', 'PTE')
if frm not in rates or to not in rates: return 'ERR:currency'
def q(v, c):
return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
x = Decimal(amount)
if frm == to: return format(q(x, to), 'f')
if frm == 'EUR':
eur = x
elif to == 'EUR':
return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
else:
eur = (x / Decimal(rates[frm])).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-rate 1', ('987654321', 'ITL', 'DEM'), '997631.50'),
('regression inverse-rate 2', ('123456789', 'ESP', 'FRF'), '4867136.96'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
[('regression inverse-rate 1', ('99999999', 'PTE', 'NLG'), '1099205.90'),
('regression inverse-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75')],
[('regression inverse-rate 1', ('2542824', 'FRF', 'ESP'), '64499703'),
('regression inverse-rate 2', ('204024', 'ESP', 'PTE'), '245833'),
('partial repair guard 1', ('2898066', 'FRF', 'ATS'), '6079401.18'),
('partial repair guard 2', ('1936907', 'ESP', 'FRF'), '76360.26'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
[('regression inverse-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
('regression inverse-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
('partial repair guard 1', ('3124364', 'BEF', 'FRF'), '508044.99'),
('partial repair guard 2', ('3838340.18', 'IEP', 'ATS'), '67063390.89'),
('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
[('regression inverse-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
('regression inverse-rate 2', ('2414493', 'DEM', 'PTE'), '247497168'),
('partial repair guard 1', ('3438237', 'IEP', 'FRF'), '28636855.27'),
('partial repair guard 2', ('987654321', 'ITL', 'DEM'), '997631.50'),
('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
for label, args, expected in cases[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression inverse-rate 1 | 997631.50 | 997631.50 | Passed |
| regression inverse-rate 2 | 4867136.96 | 4867136.96 | Passed |
| control: mark to franc | 335.38 | 335.38 | Passed |
| control: lira to euro | 516.46 | 516.46 | Passed |
| control: euro to lira | 19363 | 19363 | Passed |
| control: same currency rounding | 101 | 101 | Passed |
SHA-256 / d6c369a5768e2271bd62a82e45e100573d89e7e597ddf58192afa0d5102c4941
Verification & scope
A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:59.753866+00:00.
Case digest / 429d52eae16078ab069ed35ee8a0d7792fe26327c01577baed467680b812fb9c