FAILURE MAP
← Case archive

FA-16926 / Floating-point arithmetic / Open access

Decimal fused multiply-add rounds the product before cancellation · case 01

Decimal fused multiply-add rounds the product before cancellation.

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

ROOT CAUSE

Decimal fused multiply-add rounds the product before cancellation. The faulty expression is result=ctx.add(ctx.multiply(av,bv),cv).

VERIFIED REPAIR

Apply the contract at this fault site using result=ctx.fma(av,bv,cv).

Unsuccessful approach: The attempted local correction result=ctx.add(ctx.multiply(av,bv),ctx.plus(cv)) 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_EVEN)
    for signal in ctx.traps: ctx.traps[signal]=False
    av=Decimal(a); bv=Decimal(b); cv=Decimal(c)
    result=ctx.add(ctx.multiply(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 fixtureActualExpectedOutcome
cancellation['0.00', True]['-0.0012', False]Failed
opposite cancellation['0.00', True]['0.0012', False]Failed
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.00455', True]['0.00001', False]Failed
operand precision['1.23', True]['1.23', True]Passed

SHA-256 / b92a9de39bb50d5f7ef2e0eff61de17fb20154d1ae41db2ca15795369617e2dc

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_HALF_EVEN)
    for signal in ctx.traps: ctx.traps[signal]=False
    av=Decimal(a); bv=Decimal(b); cv=Decimal(c)
    result=ctx.add(ctx.multiply(av,bv),ctx.plus(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 fixtureActualExpectedOutcome
cancellation['0.00', True]['-0.0012', False]Failed
opposite cancellation['0.00', True]['0.0012', False]Failed
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.00', True]['0.00001', False]Failed
operand precision['1.23', True]['1.23', True]Passed

SHA-256 / 6182be49a6b4909cbced1aa7f7a7be554ff45ecfd5af645d3f7268fc84193696

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

Case digest / ec9ea3a195c909d74f604697a7e41c544b5646f47b676d62d65b2380eaa4eb6d