FAILURE MAP
← Case archive

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

The rounding plug lands on the largest signed converted line · case 01

When the largest line is a credit, the difference is booked to a small debit line instead.

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

ROOT CAUSE

The plug line is chosen by the signed converted value rather than the absolute source amount.

VERIFIED REPAIR

Choose the line with the largest absolute source amount, earliest index on ties.

Unsuccessful approach: Using absolute source amounts but breaking ties toward the last line still moves the plug on equal lines.

Case contract

solve(lines, rate, exp): lines are source-currency decimal strings (credits negative), rate a decimal string, exp the target exponent. The converted total is round_half_even(sum(lines)*rate) at exp. Each line is converted and rounded half-even individually; the difference between the converted total and the sum of converted lines is posted in full to the line with the largest absolute source amount (earliest on ties). Return the converted lines as plain strings; zero lines are unsigned. An empty invoice returns [].

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(lines, rate, exp):
    r = Decimal(rate)
    qt = Decimal(1).scaleb(-exp)
    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)
    src = [Decimal(l) for l in lines]
    if not src: return []
    conv = [q(v * r) for v in src]
    total = q(sum(src, Decimal(0)) * r)
    diff = total - sum(conv, Decimal(0))
    i = max(range(len(conv)), key=lambda k: conv[k])
    conv[i] += diff
    return [format(abs(c) if c == 0 else c, 'f') for c in conv]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]
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 plug-line-selection 1['800.275', '-1571.630']['800.274', '-1571.629']Failed
partial repair guard 1['5.02', '5.00', '5.00']['5.02', '5.00', '5.00']Passed
control: credit and debit['-5.00', '5.00']['-5.00', '5.00']Passed
control: tiny credit['30.00', '0.00']['30.00', '0.00']Passed
control: empty invoice[][]Passed
control: yen target['3026', '758', '150']['3026', '758', '150']Passed

SHA-256 / c31bbbc9061d1be0da448f5ef467cfbde2e628850713cd31dd13c01f731a7be7

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(lines, rate, exp):
    r = Decimal(rate)
    qt = Decimal(1).scaleb(-exp)
    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)
    src = [Decimal(l) for l in lines]
    if not src: return []
    conv = [q(v * r) for v in src]
    total = q(sum(src, Decimal(0)) * r)
    diff = total - sum(conv, Decimal(0))
    i = max(range(len(conv)), key=lambda k: (abs(src[k]), k))
    conv[i] += diff
    return [format(abs(c) if c == 0 else c, 'f') for c in conv]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]
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 plug-line-selection 1['800.274', '-1571.629']['800.274', '-1571.629']Passed
partial repair guard 1['5.00', '5.00', '5.02']['5.02', '5.00', '5.00']Failed
control: credit and debit['-5.00', '5.00']['-5.00', '5.00']Passed
control: tiny credit['30.00', '0.00']['30.00', '0.00']Passed
control: empty invoice[][]Passed
control: yen target['3026', '758', '150']['3026', '758', '150']Passed

SHA-256 / d53de30810b1175404db19a139c70896b555f8a498abf80b8524d21f7c5c6c83

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(lines, rate, exp):
    r = Decimal(rate)
    qt = Decimal(1).scaleb(-exp)
    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)
    src = [Decimal(l) for l in lines]
    if not src: return []
    conv = [q(v * r) for v in src]
    total = q(sum(src, Decimal(0)) * r)
    diff = total - sum(conv, Decimal(0))
    i = max(range(len(conv)), key=lambda k: (abs(src[k]), -k))
    conv[i] += diff
    return [format(abs(c) if c == 0 else c, 'f') for c in conv]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],
 [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),
  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]
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 plug-line-selection 1['800.274', '-1571.629']['800.274', '-1571.629']Passed
partial repair guard 1['5.02', '5.00', '5.00']['5.02', '5.00', '5.00']Passed
control: credit and debit['-5.00', '5.00']['-5.00', '5.00']Passed
control: tiny credit['30.00', '0.00']['30.00', '0.00']Passed
control: empty invoice[][]Passed
control: yen target['3026', '758', '150']['3026', '758', '150']Passed

SHA-256 / 3db9a4b210d333570648b1aeefecbf798e58b4bfd8a395bf306efec4fa59b1e1

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

Case digest / 0addd1324cdcff6d01a95cc9bbb448a993738cde040429325caecc38e586dd80