FAILURE MAP
← Case archive

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

The cumulative total is truncated toward zero · case 01

A day that starts with reversals posts converted amounts that do not sum to the floor of the total.

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

ROOT CAUSE

int(cum) truncates negative cumulative totals toward zero instead of flooring.

VERIFIED REPAIR

Floor the cumulative total with ROUND_FLOOR.

Unsuccessful approach: Rounding the cumulative total half-even replaces the stipulated floor rule.

Case contract

solve(items, rate): items are [day, amount] with integer source minor units (reversals negative) in posting order; rate is target minor units per source minor unit. Within a day, each posting's converted amount is floor(cumulative_exact) - floor(previous cumulative_exact), so daily converted postings sum to floor of the day's exact converted total. The carry (cumulative total and previous floor) resets whenever the day changes. Return the list of integer converted postings.

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(items, rate):
    out, cum, prev_floor, day = [], Decimal(0), 0, None
    r = Decimal(rate)
    for d, a in items:
        if d != day:
            day, cum, prev_floor = d, Decimal(0), 0
        cum += Decimal(a) * r
        f = int(cum)
        out.append(f - prev_floor)
        prev_floor = f
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-floor 1', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('regression negative-floor 2',
   ([['2026-03-01', -18], ['2026-03-01', 240], ['2026-03-02', -19], ['2026-03-02', 81], ['2026-03-02', 129],
     ['2026-03-02', 231]],
    '0.2472'),
   [-5, 59, -5, 20, 32, 57]),
  ('partial repair guard 2', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1]),
  ('control: single large', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1])],
 [('regression negative-floor 1',
   ([['2026-03-01', -26], ['2026-03-01', 4], ['2026-03-01', -3], ['2026-03-02', 57], ['2026-03-02', 131]], '5.53'),
   [-144, 22, -17, 315, 724]),
  ('regression negative-floor 2', ([['2026-03-01', -7]], '17.81'), [-125]),
  ('partial repair guard 1', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('partial repair guard 2', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1]),
  ('control: empty', ([], '1.5'), []),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1])],
 [('regression negative-floor 1', ([['2026-03-01', -26], ['2026-03-02', 215]], '27.52'), [-716, 5916]),
  ('regression negative-floor 2', ([['2026-03-02', -10], ['2026-03-02', 101], ['2026-03-02', 1]], '0.4523'),
   [-5, 46, 0]),
  ('partial repair guard 1',
   ([['2026-03-01', 286], ['2026-03-01', 294], ['2026-03-01', 293], ['2026-03-01', 194], ['2026-03-01', 25],
     ['2026-03-01', 203]],
    '4.921'),
   [1407, 1447, 1442, 954, 123, 999]),
  ('partial repair guard 2',
   ([['2026-03-01', 186], ['2026-03-01', -5], ['2026-03-02', 8], ['2026-03-02', 154]], '0.3542'), [65, -1, 2, 55]),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1])],
 [('regression negative-floor 1', ([['2026-03-01', -27], ['2026-03-02', 58]], '1.09'), [-30, 63]),
  ('regression negative-floor 2', ([['2026-03-02', 92], ['2026-03-03', -4]], '0.560'), [51, -3]),
  ('partial repair guard 1',
   ([['2026-03-01', 263], ['2026-03-01', 239], ['2026-03-01', 228], ['2026-03-01', -26], ['2026-03-02', 231]], '29.57'),
   [7776, 7068, 6742, -769, 6830]),
  ('partial repair guard 2',
   ([['2026-03-01', -18], ['2026-03-01', 240], ['2026-03-02', -19], ['2026-03-02', 81], ['2026-03-02', 129],
     ['2026-03-02', 231]],
    '0.2472'),
   [-5, 59, -5, 20, 32, 57]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1]),
  ('control: single large', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1]),
  ('control: empty', ([], '1.5'), [])],
 [('regression negative-floor 1', ([['2026-03-02', -3]], '0.634'), [-2]),
  ('regression negative-floor 2', ([['2026-03-02', -7], ['2026-03-02', 158], ['2026-03-02', 260]], '0.4655'),
   [-4, 74, 121]),
  ('partial repair guard 1', ([['2026-03-02', 74]], '39.43'), [2917]),
  ('partial repair guard 2',
   ([['2026-03-02', 92], ['2026-03-03', 36], ['2026-03-03', -15], ['2026-04-01', 46], ['2026-04-01', 50],
     ['2026-04-01', 95]],
    '4.346'),
   [399, 156, -65, 199, 218, 413]),
  ('control: empty', ([], '1.5'), []),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 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 fixtureActualExpectedOutcome
regression negative-floor 1[0, 0, 0][-1, 0, 1]Failed
regression negative-floor 2[-4, 58, -4, 19, 32, 57][-5, 59, -5, 20, 32, 57]Failed
partial repair guard 2[0, 0, 1][0, 0, 1]Passed
control: day reset[0, 0, 1][0, 0, 1]Passed
control: reversal[2, -1][2, -1]Passed
control: single large[11375][11375]Passed
control: month change[1, 1][1, 1]Passed

SHA-256 / 2767d3f8db80179e691d303ef6134969e18b3d07e0d89bf37abae52fcb038a03

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(items, rate):
    out, cum, prev_floor, day = [], Decimal(0), 0, None
    r = Decimal(rate)
    for d, a in items:
        if d != day:
            day, cum, prev_floor = d, Decimal(0), 0
        cum += Decimal(a) * r
        f = int(cum.to_integral_value(rounding=ROUND_HALF_EVEN))
        out.append(f - prev_floor)
        prev_floor = f
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-floor 1', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('regression negative-floor 2',
   ([['2026-03-01', -18], ['2026-03-01', 240], ['2026-03-02', -19], ['2026-03-02', 81], ['2026-03-02', 129],
     ['2026-03-02', 231]],
    '0.2472'),
   [-5, 59, -5, 20, 32, 57]),
  ('partial repair guard 2', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1]),
  ('control: single large', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1])],
 [('regression negative-floor 1',
   ([['2026-03-01', -26], ['2026-03-01', 4], ['2026-03-01', -3], ['2026-03-02', 57], ['2026-03-02', 131]], '5.53'),
   [-144, 22, -17, 315, 724]),
  ('regression negative-floor 2', ([['2026-03-01', -7]], '17.81'), [-125]),
  ('partial repair guard 1', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('partial repair guard 2', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1]),
  ('control: empty', ([], '1.5'), []),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1])],
 [('regression negative-floor 1', ([['2026-03-01', -26], ['2026-03-02', 215]], '27.52'), [-716, 5916]),
  ('regression negative-floor 2', ([['2026-03-02', -10], ['2026-03-02', 101], ['2026-03-02', 1]], '0.4523'),
   [-5, 46, 0]),
  ('partial repair guard 1',
   ([['2026-03-01', 286], ['2026-03-01', 294], ['2026-03-01', 293], ['2026-03-01', 194], ['2026-03-01', 25],
     ['2026-03-01', 203]],
    '4.921'),
   [1407, 1447, 1442, 954, 123, 999]),
  ('partial repair guard 2',
   ([['2026-03-01', 186], ['2026-03-01', -5], ['2026-03-02', 8], ['2026-03-02', 154]], '0.3542'), [65, -1, 2, 55]),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1])],
 [('regression negative-floor 1', ([['2026-03-01', -27], ['2026-03-02', 58]], '1.09'), [-30, 63]),
  ('regression negative-floor 2', ([['2026-03-02', 92], ['2026-03-03', -4]], '0.560'), [51, -3]),
  ('partial repair guard 1',
   ([['2026-03-01', 263], ['2026-03-01', 239], ['2026-03-01', 228], ['2026-03-01', -26], ['2026-03-02', 231]], '29.57'),
   [7776, 7068, 6742, -769, 6830]),
  ('partial repair guard 2',
   ([['2026-03-01', -18], ['2026-03-01', 240], ['2026-03-02', -19], ['2026-03-02', 81], ['2026-03-02', 129],
     ['2026-03-02', 231]],
    '0.2472'),
   [-5, 59, -5, 20, 32, 57]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1]),
  ('control: single large', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1]),
  ('control: empty', ([], '1.5'), [])],
 [('regression negative-floor 1', ([['2026-03-02', -3]], '0.634'), [-2]),
  ('regression negative-floor 2', ([['2026-03-02', -7], ['2026-03-02', 158], ['2026-03-02', 260]], '0.4655'),
   [-4, 74, 121]),
  ('partial repair guard 1', ([['2026-03-02', 74]], '39.43'), [2917]),
  ('partial repair guard 2',
   ([['2026-03-02', 92], ['2026-03-03', 36], ['2026-03-03', -15], ['2026-04-01', 46], ['2026-04-01', 50],
     ['2026-04-01', 95]],
    '4.346'),
   [399, 156, -65, 199, 218, 413]),
  ('control: empty', ([], '1.5'), []),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 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 fixtureActualExpectedOutcome
regression negative-floor 1[0, -1, 1][-1, 0, 1]Failed
regression negative-floor 2[-4, 59, -5, 20, 32, 57][-5, 59, -5, 20, 32, 57]Failed
partial repair guard 2[0, 1, 0][0, 0, 1]Failed
control: day reset[1, 1, 0][0, 0, 1]Failed
control: reversal[2, -1][2, -1]Passed
control: single large[11376][11375]Failed
control: month change[1, 1][1, 1]Passed

SHA-256 / fcdff6dbed703b821c36eecbcea2de85087a211e4ae27c531f7342bb5f02e40c

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(items, rate):
    out, cum, prev_floor, day = [], Decimal(0), 0, None
    r = Decimal(rate)
    for d, a in items:
        if d != day:
            day, cum, prev_floor = d, Decimal(0), 0
        cum += Decimal(a) * r
        f = int(cum.to_integral_value(rounding=ROUND_FLOOR))
        out.append(f - prev_floor)
        prev_floor = f
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-floor 1', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('regression negative-floor 2',
   ([['2026-03-01', -18], ['2026-03-01', 240], ['2026-03-02', -19], ['2026-03-02', 81], ['2026-03-02', 129],
     ['2026-03-02', 231]],
    '0.2472'),
   [-5, 59, -5, 20, 32, 57]),
  ('partial repair guard 2', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1]),
  ('control: single large', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1])],
 [('regression negative-floor 1',
   ([['2026-03-01', -26], ['2026-03-01', 4], ['2026-03-01', -3], ['2026-03-02', 57], ['2026-03-02', 131]], '5.53'),
   [-144, 22, -17, 315, 724]),
  ('regression negative-floor 2', ([['2026-03-01', -7]], '17.81'), [-125]),
  ('partial repair guard 1', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('partial repair guard 2', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1]),
  ('control: empty', ([], '1.5'), []),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1])],
 [('regression negative-floor 1', ([['2026-03-01', -26], ['2026-03-02', 215]], '27.52'), [-716, 5916]),
  ('regression negative-floor 2', ([['2026-03-02', -10], ['2026-03-02', 101], ['2026-03-02', 1]], '0.4523'),
   [-5, 46, 0]),
  ('partial repair guard 1',
   ([['2026-03-01', 286], ['2026-03-01', 294], ['2026-03-01', 293], ['2026-03-01', 194], ['2026-03-01', 25],
     ['2026-03-01', 203]],
    '4.921'),
   [1407, 1447, 1442, 954, 123, 999]),
  ('partial repair guard 2',
   ([['2026-03-01', 186], ['2026-03-01', -5], ['2026-03-02', 8], ['2026-03-02', 154]], '0.3542'), [65, -1, 2, 55]),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 1]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1])],
 [('regression negative-floor 1', ([['2026-03-01', -27], ['2026-03-02', 58]], '1.09'), [-30, 63]),
  ('regression negative-floor 2', ([['2026-03-02', 92], ['2026-03-03', -4]], '0.560'), [51, -3]),
  ('partial repair guard 1',
   ([['2026-03-01', 263], ['2026-03-01', 239], ['2026-03-01', 228], ['2026-03-01', -26], ['2026-03-02', 231]], '29.57'),
   [7776, 7068, 6742, -769, 6830]),
  ('partial repair guard 2',
   ([['2026-03-01', -18], ['2026-03-01', 240], ['2026-03-02', -19], ['2026-03-02', 81], ['2026-03-02', 129],
     ['2026-03-02', 231]],
    '0.2472'),
   [-5, 59, -5, 20, 32, 57]),
  ('control: reversal', ([['d1', 5], ['d1', -3]], '0.5'), [2, -1]),
  ('control: single large', ([['2026-03-01', 12345]], '0.9215'), [11375]),
  ('control: month change', ([['2026-03-31', 3], ['2026-04-01', 3]], '0.35'), [1, 1]),
  ('control: empty', ([], '1.5'), [])],
 [('regression negative-floor 1', ([['2026-03-02', -3]], '0.634'), [-2]),
  ('regression negative-floor 2', ([['2026-03-02', -7], ['2026-03-02', 158], ['2026-03-02', 260]], '0.4655'),
   [-4, 74, 121]),
  ('partial repair guard 1', ([['2026-03-02', 74]], '39.43'), [2917]),
  ('partial repair guard 2',
   ([['2026-03-02', 92], ['2026-03-03', 36], ['2026-03-03', -15], ['2026-04-01', 46], ['2026-04-01', 50],
     ['2026-04-01', 95]],
    '4.346'),
   [399, 156, -65, 199, 218, 413]),
  ('control: empty', ([], '1.5'), []),
  ('control: negative first', ([['d1', -1], ['d1', -1], ['d1', 2]], '0.3'), [-1, 0, 1]),
  ('control: three micro postings', ([['d1', 1], ['d1', 1], ['d1', 1]], '0.4'), [0, 0, 1]),
  ('control: day reset', ([['d1', 1], ['d2', 1], ['d2', 1]], '0.6'), [0, 0, 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 fixtureActualExpectedOutcome
regression negative-floor 1[-1, 0, 1][-1, 0, 1]Passed
regression negative-floor 2[-5, 59, -5, 20, 32, 57][-5, 59, -5, 20, 32, 57]Passed
partial repair guard 2[0, 0, 1][0, 0, 1]Passed
control: day reset[0, 0, 1][0, 0, 1]Passed
control: reversal[2, -1][2, -1]Passed
control: single large[11375][11375]Passed
control: month change[1, 1][1, 1]Passed

SHA-256 / 2e307f05f033a6b9582b9bebd64e11c1c793a7a05b1fe92b029ed1a06b04d88b

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

Case digest / ac6e8f3bc4bd0ac976b2057d50b8a57e623fa56c2f5ce8bd86985497fe0d526f