FA-61996 / Currency rounding and FX conversion / Open access
The amount-rate product is formed in binary floating point · case 01
115 cents at 1.1 becomes 127 instead of the half-even 126.
ROOT CAUSE
amount_minor * float(rate) introduces binary error that decides ties.
THE FAILURE
amount_minor * float(rate) introduces binary error that decides ties.
Unsuccessful approach: Formatting the float product with repr before Decimal still carries the binary error.
Case contract
solve(amount_minor, from_exp, to_exp, rate): amount_minor is an integer count of source minor units, rate a decimal string giving target major units per source major unit. The target minor amount is amount_minor * rate * 10**(to_exp - from_exp), computed exactly and rounded half-even to an integer.
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_minor, from_exp, to_exp, rate):
scale = Decimal(10) ** (to_exp - from_exp)
v = Decimal(amount_minor * float(rate)) * scale
return int(v.quantize(Decimal(1), rounding=ROUND_HALF_EVEN))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: cents to yen', (1000, 2, 0, '151.37'), 1514), ('control: negative exact', (-250, 2, 2, '0.5'), -125),
('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2),
('control: zero', (0, 2, 0, '151.37'), 0), ('control: precise rate', (123456, 2, 2, '1.08347'), 133761)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
('control: large', (987654321, 2, 3, '0.30712'), 3033283951), ('control: cents to yen', (1000, 2, 0, '151.37'), 1514),
('control: negative exact', (-250, 2, 2, '0.5'), -125)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: negative exact', (-250, 2, 2, '0.5'), -125), ('control: yen to dinar', (1, 0, 3, '0.3071'), 307),
('control: negative tie', (-3, 2, 2, '0.5'), -2), ('control: zero', (0, 2, 0, '151.37'), 0)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: negative tie', (-3, 2, 2, '0.5'), -2), ('control: zero', (0, 2, 0, '151.37'), 0),
('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
('control: large', (987654321, 2, 3, '0.30712'), 3033283951)]]
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 binary-product 1 | 127 | 126 | Failed |
| regression binary-product 2 | 3516385193 | 3516385194 | Failed |
| control: cents to yen | 1514 | 1514 | Passed |
| control: negative exact | -125 | -125 | Passed |
| control: yen to dinar | 307 | 307 | Passed |
| control: negative tie | -2 | -2 | Passed |
SHA-256 / 67b14ae9abc1b52660424b04fc92588347bb7c11e53ba0507bd6fd0691671724
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_minor, from_exp, to_exp, rate):
scale = Decimal(10) ** (to_exp - from_exp)
v = Decimal(repr(amount_minor * float(rate))) * scale
return int(v.quantize(Decimal(1), rounding=ROUND_HALF_EVEN))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: cents to yen', (1000, 2, 0, '151.37'), 1514), ('control: negative exact', (-250, 2, 2, '0.5'), -125),
('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2),
('control: zero', (0, 2, 0, '151.37'), 0), ('control: precise rate', (123456, 2, 2, '1.08347'), 133761)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
('control: large', (987654321, 2, 3, '0.30712'), 3033283951), ('control: cents to yen', (1000, 2, 0, '151.37'), 1514),
('control: negative exact', (-250, 2, 2, '0.5'), -125)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: negative exact', (-250, 2, 2, '0.5'), -125), ('control: yen to dinar', (1, 0, 3, '0.3071'), 307),
('control: negative tie', (-3, 2, 2, '0.5'), -2), ('control: zero', (0, 2, 0, '151.37'), 0)],
[('regression binary-product 1', (115, 2, 2, '1.1'), 126),
('regression binary-product 2', (238181, 0, 2, '147.6350'), 3516385194),
('control: negative tie', (-3, 2, 2, '0.5'), -2), ('control: zero', (0, 2, 0, '151.37'), 0),
('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
('control: large', (987654321, 2, 3, '0.30712'), 3033283951)]]
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 binary-product 1 | 127 | 126 | Failed |
| regression binary-product 2 | 3516385193 | 3516385194 | Failed |
| control: cents to yen | 1514 | 1514 | Passed |
| control: negative exact | -125 | -125 | Passed |
| control: yen to dinar | 307 | 307 | Passed |
| control: negative tie | -2 | -2 | Passed |
SHA-256 / 687f43d4537bab093930666fb74526df83d0e2ee80c75cb135f8aa3d0a784b93
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 6 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗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.486753+00:00.
Case digest / 8bf123c2bdf9cca9c1b8fe7356902652f1402e14a04e554fe09883d1d755bfd0