FAILURE MAP
← Case archive

FA-61871 / Currency rounding and FX conversion / Open access

The USD pivot amount is rounded to cents before the second leg · case 01

Won or yen targets drift by one unit because an intermediate cent rounding is scaled by a large rate.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The intermediate USD value is quantized to 0.01 before multiplication by the target rate.

VERIFIED REPAIR

Keep the pivot amount exact and round only once, at the target currency exponent.

Unsuccessful approach: Rounding the pivot to four decimals shrinks the error but still flips results near a target half-unit.

Case contract

solve(amount, frm, to, rates): rates maps a currency to units of that currency per 1 USD (decimal strings); USD is implicitly 1 when absent. Convert exactly as amount / rate[frm] * rate[to] with no intermediate rounding, then round half-even to the target exponent (USD/EUR/GBP/CHF/SEK/NOK 2, JPY/KRW 0, KWD 3, CLF 4) and return a plain string. A missing rate returns 'ERR:no-rate:<code>', a zero or negative rate 'ERR:bad-rate:<code>' (source checked first).

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):
    exps = {'USD': 2, 'EUR': 2, 'GBP': 2, 'CHF': 2, 'SEK': 2, 'NOK': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'CLF': 4}
    def rate(c):
        if c == 'USD' and c not in rates: return Decimal(1)
        if c not in rates: return None
        return Decimal(rates[c])
    rf, rt = rate(frm), rate(to)
    for c, r in ((frm, rf), (to, rt)):
        if r is None: return 'ERR:no-rate:' + c
        if r <= 0: return 'ERR:bad-rate:' + c
    usd = Decimal(amount) / rf
    out = usd.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN) * rt
    return format(out.quantize(Decimal(1).scaleb(-exps[to]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression pivot-leg-rounding 1',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453'),
  ('regression pivot-leg-rounding 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('control: usd to dinar',
   ('100.00', 'USD', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '30.710'),
  ('control: pound to usd',
   ('5', 'GBP', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '6.33'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68')],
 [('regression pivot-leg-rounding 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression pivot-leg-rounding 2',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68'),
  ('control: yen to unit of account',
   ('99999', 'JPY', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16.1920'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')],
 [('regression pivot-leg-rounding 1',
   ('24340', 'KRW', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '5.527'),
  ('regression pivot-leg-rounding 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('partial repair guard 1',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('partial repair guard 2',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
  ('control: usd absent', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('control: euro to yen',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453')],
 [('regression pivot-leg-rounding 1',
   ('41394.40', 'KWD', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '3303.7341'),
  ('regression pivot-leg-rounding 2',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('control: euro to yen',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453'),
  ('control: usd to dinar',
   ('100.00', 'USD', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '30.710'),
  ('control: pound to usd',
   ('5', 'GBP', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '6.33'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK')],
 [('regression pivot-leg-rounding 1',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('regression pivot-leg-rounding 2',
   ('74016', 'JPY', 'EUR',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '449.86'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68'),
  ('control: yen to unit of account',
   ('99999', 'JPY', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16.1920'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')]]
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 fixtureActualExpectedOutcome
regression pivot-leg-rounding 11645416453Failed
regression pivot-leg-rounding 216420.708116420.7080Failed
partial repair guard 13394.23523394.2354Failed
partial repair guard 261971.4461971.44Passed
control: usd to dinar30.71030.710Passed
control: pound to usd6.336.33Passed
control: missing targetERR:no-rate:SEKERR:no-rate:SEKPassed
control: won to franc162.68162.68Passed

SHA-256 / b08120fc3e367193d79358d72308375285de628fadf253c8de3e62f2ef117761

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):
    exps = {'USD': 2, 'EUR': 2, 'GBP': 2, 'CHF': 2, 'SEK': 2, 'NOK': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'CLF': 4}
    def rate(c):
        if c == 'USD' and c not in rates: return Decimal(1)
        if c not in rates: return None
        return Decimal(rates[c])
    rf, rt = rate(frm), rate(to)
    for c, r in ((frm, rf), (to, rt)):
        if r is None: return 'ERR:no-rate:' + c
        if r <= 0: return 'ERR:bad-rate:' + c
    usd = Decimal(amount) / rf
    out = usd.quantize(Decimal('0.0001'), rounding=ROUND_HALF_EVEN) * rt
    return format(out.quantize(Decimal(1).scaleb(-exps[to]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression pivot-leg-rounding 1',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453'),
  ('regression pivot-leg-rounding 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('control: usd to dinar',
   ('100.00', 'USD', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '30.710'),
  ('control: pound to usd',
   ('5', 'GBP', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '6.33'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68')],
 [('regression pivot-leg-rounding 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression pivot-leg-rounding 2',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68'),
  ('control: yen to unit of account',
   ('99999', 'JPY', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16.1920'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')],
 [('regression pivot-leg-rounding 1',
   ('24340', 'KRW', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '5.527'),
  ('regression pivot-leg-rounding 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('partial repair guard 1',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('partial repair guard 2',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
  ('control: usd absent', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('control: euro to yen',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453')],
 [('regression pivot-leg-rounding 1',
   ('41394.40', 'KWD', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '3303.7341'),
  ('regression pivot-leg-rounding 2',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('control: euro to yen',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453'),
  ('control: usd to dinar',
   ('100.00', 'USD', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '30.710'),
  ('control: pound to usd',
   ('5', 'GBP', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '6.33'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK')],
 [('regression pivot-leg-rounding 1',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('regression pivot-leg-rounding 2',
   ('74016', 'JPY', 'EUR',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '449.86'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68'),
  ('control: yen to unit of account',
   ('99999', 'JPY', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16.1920'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')]]
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 fixtureActualExpectedOutcome
regression pivot-leg-rounding 11645316453Passed
regression pivot-leg-rounding 216420.708016420.7080Passed
partial repair guard 13394.23533394.2354Failed
partial repair guard 261971.4561971.44Failed
control: usd to dinar30.71030.710Passed
control: pound to usd6.336.33Passed
control: missing targetERR:no-rate:SEKERR:no-rate:SEKPassed
control: won to franc162.68162.68Passed

SHA-256 / a32126045d03cc981127223a096f829844c49b70f01d9adc2028981af827c832

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):
    exps = {'USD': 2, 'EUR': 2, 'GBP': 2, 'CHF': 2, 'SEK': 2, 'NOK': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'CLF': 4}
    def rate(c):
        if c == 'USD' and c not in rates: return Decimal(1)
        if c not in rates: return None
        return Decimal(rates[c])
    rf, rt = rate(frm), rate(to)
    for c, r in ((frm, rf), (to, rt)):
        if r is None: return 'ERR:no-rate:' + c
        if r <= 0: return 'ERR:bad-rate:' + c
    usd = Decimal(amount) / rf
    out = usd * rt
    return format(out.quantize(Decimal(1).scaleb(-exps[to]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression pivot-leg-rounding 1',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453'),
  ('regression pivot-leg-rounding 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('control: usd to dinar',
   ('100.00', 'USD', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '30.710'),
  ('control: pound to usd',
   ('5', 'GBP', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '6.33'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68')],
 [('regression pivot-leg-rounding 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression pivot-leg-rounding 2',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68'),
  ('control: yen to unit of account',
   ('99999', 'JPY', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16.1920'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')],
 [('regression pivot-leg-rounding 1',
   ('24340', 'KRW', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '5.527'),
  ('regression pivot-leg-rounding 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('partial repair guard 1',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('partial repair guard 2',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
  ('control: usd absent', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('control: euro to yen',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453')],
 [('regression pivot-leg-rounding 1',
   ('41394.40', 'KWD', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '3303.7341'),
  ('regression pivot-leg-rounding 2',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('control: euro to yen',
   ('100', 'EUR', 'JPY',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16453'),
  ('control: usd to dinar',
   ('100.00', 'USD', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '30.710'),
  ('control: pound to usd',
   ('5', 'GBP', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '6.33'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK')],
 [('regression pivot-leg-rounding 1',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('regression pivot-leg-rounding 2',
   ('74016', 'JPY', 'EUR',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '449.86'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('control: missing target',
   ('1', 'EUR', 'SEK',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:SEK'),
  ('control: won to franc',
   ('250000', 'KRW', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '162.68'),
  ('control: yen to unit of account',
   ('99999', 'JPY', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16.1920'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')]]
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 fixtureActualExpectedOutcome
regression pivot-leg-rounding 11645316453Passed
regression pivot-leg-rounding 216420.708016420.7080Passed
partial repair guard 13394.23543394.2354Passed
partial repair guard 261971.4461971.44Passed
control: usd to dinar30.71030.710Passed
control: pound to usd6.336.33Passed
control: missing targetERR:no-rate:SEKERR:no-rate:SEKPassed
control: won to franc162.68162.68Passed

SHA-256 / 8f5ca71a24179e61cbd507e52e4818678488ce4e6a37cf55ee2dc584c86b9df4

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.350891+00:00.

Case digest / 8d9e6d7ffc641e59a00b3bff4c333fef06943144baafdd31ce7f11acf8d40f3d