FA-16946 / Floating-point arithmetic / Open access
Decimal fused multiply-add uses away ties in an even context · case 01
Decimal fused multiply-add uses away ties in an even context.
ROOT CAUSE
Decimal fused multiply-add uses away ties in an even context. The faulty expression is ctx=Context(prec=precision,rounding=ROUND_HALF_UP).
VERIFIED REPAIR
Apply the contract at this fault site using ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN).
Unsuccessful approach: The attempted local correction ctx=Context(prec=precision,rounding=ROUND_DOWN) still violates the explicit regression fixtures.
Case contract
Decimal fused multiply-add rounds a*b+c once in a fresh precision-limited half-even context. Inputs are decimal strings; return final decimal string and Inexact flag.
Why this case matters
An offline floating representation model isolates a reproducible arithmetic fault.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import decimal
from decimal import Decimal, Context, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_DOWN
N = 1
observations = []
def solve(a,b,c,precision):
ctx=Context(prec=precision,rounding=ROUND_HALF_UP)
for signal in ctx.traps: ctx.traps[signal]=False
av=Decimal(a); bv=Decimal(b); cv=Decimal(c)
result=ctx.fma(av,bv,cv)
return [str(result),ctx.flags[decimal.Inexact]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('cancellation', solve("1.23","4.56","-5.61",3), ["-0.0012",False])
check('opposite cancellation', solve("-1.23","4.56","5.61",3), ["0.0012",False])
check('tiny addend', solve("1","1","0.005",3), ["1.00",True])
check('odd tie', solve("1","1","0.015",3), ["1.02",True])
check('variable exact', solve(str(N),"2","3",3), [str(2*N+3),False])
check('addend precision', solve("1.23456","1","-1.23455",3), ["0.00001",False])
check('operand precision', solve("1.23456","1","0",3), ["1.23",True])
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 |
|---|---|---|---|
| cancellation | ['-0.0012', False] | ['-0.0012', False] | Passed |
| opposite cancellation | ['0.0012', False] | ['0.0012', False] | Passed |
| tiny addend | ['1.01', True] | ['1.00', True] | Failed |
| odd tie | ['1.02', True] | ['1.02', True] | Passed |
| variable exact | ['5', False] | ['5', False] | Passed |
| addend precision | ['0.00001', False] | ['0.00001', False] | Passed |
| operand precision | ['1.23', True] | ['1.23', True] | Passed |
SHA-256 / 99dc770125d5ba4454e4de24817d3cb74bea5b0bd491aa98ee988cf3137af4af
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import decimal
from decimal import Decimal, Context, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_DOWN
N = 1
observations = []
def solve(a,b,c,precision):
ctx=Context(prec=precision,rounding=ROUND_DOWN)
for signal in ctx.traps: ctx.traps[signal]=False
av=Decimal(a); bv=Decimal(b); cv=Decimal(c)
result=ctx.fma(av,bv,cv)
return [str(result),ctx.flags[decimal.Inexact]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('cancellation', solve("1.23","4.56","-5.61",3), ["-0.0012",False])
check('opposite cancellation', solve("-1.23","4.56","5.61",3), ["0.0012",False])
check('tiny addend', solve("1","1","0.005",3), ["1.00",True])
check('odd tie', solve("1","1","0.015",3), ["1.02",True])
check('variable exact', solve(str(N),"2","3",3), [str(2*N+3),False])
check('addend precision', solve("1.23456","1","-1.23455",3), ["0.00001",False])
check('operand precision', solve("1.23456","1","0",3), ["1.23",True])
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 |
|---|---|---|---|
| cancellation | ['-0.0012', False] | ['-0.0012', False] | Passed |
| opposite cancellation | ['0.0012', False] | ['0.0012', False] | Passed |
| tiny addend | ['1.00', True] | ['1.00', True] | Passed |
| odd tie | ['1.01', True] | ['1.02', True] | Failed |
| variable exact | ['5', False] | ['5', False] | Passed |
| addend precision | ['0.00001', False] | ['0.00001', False] | Passed |
| operand precision | ['1.23', True] | ['1.23', True] | Passed |
SHA-256 / b19fd7f2d632eb0fce02e8dc99b13b310666d3ee2a923b81e4d0e36ae02b3dff
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import decimal
from decimal import Decimal, Context, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_DOWN
N = 1
observations = []
def solve(a,b,c,precision):
ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN)
for signal in ctx.traps: ctx.traps[signal]=False
av=Decimal(a); bv=Decimal(b); cv=Decimal(c)
result=ctx.fma(av,bv,cv)
return [str(result),ctx.flags[decimal.Inexact]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('cancellation', solve("1.23","4.56","-5.61",3), ["-0.0012",False])
check('opposite cancellation', solve("-1.23","4.56","5.61",3), ["0.0012",False])
check('tiny addend', solve("1","1","0.005",3), ["1.00",True])
check('odd tie', solve("1","1","0.015",3), ["1.02",True])
check('variable exact', solve(str(N),"2","3",3), [str(2*N+3),False])
check('addend precision', solve("1.23456","1","-1.23455",3), ["0.00001",False])
check('operand precision', solve("1.23456","1","0",3), ["1.23",True])
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 |
|---|---|---|---|
| cancellation | ['-0.0012', False] | ['-0.0012', False] | Passed |
| opposite cancellation | ['0.0012', False] | ['0.0012', False] | Passed |
| tiny addend | ['1.00', True] | ['1.00', True] | Passed |
| odd tie | ['1.02', True] | ['1.02', True] | Passed |
| variable exact | ['5', False] | ['5', False] | Passed |
| addend precision | ['0.00001', False] | ['0.00001', False] | Passed |
| operand precision | ['1.23', True] | ['1.23', True] | Passed |
SHA-256 / 0d52afe8b9db5d3cadaea9f6fd4c5d883b9ff4a635253fac0edc3dbc092ce339
Verification & scope
Controlled binary64 or explicitly stipulated miniature format; no hardware exception flags or platform floating environment are modeled. 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:39:41.602740+00:00.
Case digest / c44d856661e6198e1f94fcf592e357dd1087f898ba08707ed0a231000b1d04c1