FA-16921 / Floating-point arithmetic / Open access
Decimal quantization creates a context but uses the ambient one · case 01
Decimal quantization creates a context but uses the ambient one.
ROOT CAUSE
Decimal quantization creates a context but uses the ambient one. The faulty expression is result=value.quantize(quantum).
THE FAILURE
Decimal quantization creates a context but uses the ambient one. The faulty expression is result=value.quantize(quantum).
Unsuccessful approach: The attempted local correction result=value.quantize(quantum,rounding=ROUND_HALF_EVEN) still violates the explicit regression fixtures.
Case contract
Quantize a decimal text to 10**exponent using a fresh precision-limited decimal context, half-even rounding, Emin=-9 and Emax=9. All traps are disabled; return result string and raised flag names. The coefficient precision includes trailing zeros imposed by the target quantum.
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(text, exponent, precision):
ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN,Emin=-9,Emax=9)
for signal in ctx.traps: ctx.traps[signal]=False
ctx.clear_flags()
value=Decimal(text)
quantum=Decimal((0,(1,),exponent))
result=value.quantize(quantum)
flags=sorted(signal.__name__ for signal,raised in ctx.flags.items() if raised)
return [str(result),flags]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie odd', solve(str(N)+".255",-2,6), [str(N)+".26",["Inexact","Rounded"]])
check('tie even', solve(str(N)+".245",-2,6), [str(N)+".24",["Inexact","Rounded"]])
check('rounded exact', solve(str(N)+".200",-2,6), [str(N)+".20",["Rounded"]])
check('already exact', solve(str(N)+".20",-2,6), [str(N)+".20",[]])
check('one excess digit', solve("123.45",-2,4), ["NaN",["InvalidOperation"]])
check('coefficient too large', solve("12345.67",-2,4), ["NaN",["InvalidOperation"]])
check('subnormal exact', solve("1e-10",-10,6), ["1E-10",["Subnormal"]])
check('negative zero', solve("-0.004",-2,6), ["-0.00",["Inexact","Rounded"]])
check('positive zero', solve("0.004",-2,6), ["0.00",["Inexact","Rounded"]])
check('integer quantum', solve("123.4",1,6), ["1.2E+2",["Inexact","Rounded"]])
check('overflow exponent', solve("1e10",0,6), ["NaN",["InvalidOperation"]])
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 |
|---|---|---|---|
| tie odd | ['1.26', []] | ['1.26', ['Inexact', 'Rounded']] | Failed |
| tie even | ['1.24', []] | ['1.24', ['Inexact', 'Rounded']] | Failed |
| rounded exact | ['1.20', []] | ['1.20', ['Rounded']] | Failed |
| already exact | ['1.20', []] | ['1.20', []] | Passed |
| one excess digit | ['123.45', []] | ['NaN', ['InvalidOperation']] | Failed |
| coefficient too large | ['12345.67', []] | ['NaN', ['InvalidOperation']] | Failed |
| subnormal exact | ['1E-10', []] | ['1E-10', ['Subnormal']] | Failed |
| negative zero | ['-0.00', []] | ['-0.00', ['Inexact', 'Rounded']] | Failed |
| positive zero | ['0.00', []] | ['0.00', ['Inexact', 'Rounded']] | Failed |
| integer quantum | ['1.2E+2', []] | ['1.2E+2', ['Inexact', 'Rounded']] | Failed |
| overflow exponent | ['10000000000', []] | ['NaN', ['InvalidOperation']] | Failed |
SHA-256 / de3a21b50baa784365b3bfaacb590509b09e0c690c02d7fa648c019d352c2e62
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(text, exponent, precision):
ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN,Emin=-9,Emax=9)
for signal in ctx.traps: ctx.traps[signal]=False
ctx.clear_flags()
value=Decimal(text)
quantum=Decimal((0,(1,),exponent))
result=value.quantize(quantum,rounding=ROUND_HALF_EVEN)
flags=sorted(signal.__name__ for signal,raised in ctx.flags.items() if raised)
return [str(result),flags]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie odd', solve(str(N)+".255",-2,6), [str(N)+".26",["Inexact","Rounded"]])
check('tie even', solve(str(N)+".245",-2,6), [str(N)+".24",["Inexact","Rounded"]])
check('rounded exact', solve(str(N)+".200",-2,6), [str(N)+".20",["Rounded"]])
check('already exact', solve(str(N)+".20",-2,6), [str(N)+".20",[]])
check('one excess digit', solve("123.45",-2,4), ["NaN",["InvalidOperation"]])
check('coefficient too large', solve("12345.67",-2,4), ["NaN",["InvalidOperation"]])
check('subnormal exact', solve("1e-10",-10,6), ["1E-10",["Subnormal"]])
check('negative zero', solve("-0.004",-2,6), ["-0.00",["Inexact","Rounded"]])
check('positive zero', solve("0.004",-2,6), ["0.00",["Inexact","Rounded"]])
check('integer quantum', solve("123.4",1,6), ["1.2E+2",["Inexact","Rounded"]])
check('overflow exponent', solve("1e10",0,6), ["NaN",["InvalidOperation"]])
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 |
|---|---|---|---|
| tie odd | ['1.26', []] | ['1.26', ['Inexact', 'Rounded']] | Failed |
| tie even | ['1.24', []] | ['1.24', ['Inexact', 'Rounded']] | Failed |
| rounded exact | ['1.20', []] | ['1.20', ['Rounded']] | Failed |
| already exact | ['1.20', []] | ['1.20', []] | Passed |
| one excess digit | ['123.45', []] | ['NaN', ['InvalidOperation']] | Failed |
| coefficient too large | ['12345.67', []] | ['NaN', ['InvalidOperation']] | Failed |
| subnormal exact | ['1E-10', []] | ['1E-10', ['Subnormal']] | Failed |
| negative zero | ['-0.00', []] | ['-0.00', ['Inexact', 'Rounded']] | Failed |
| positive zero | ['0.00', []] | ['0.00', ['Inexact', 'Rounded']] | Failed |
| integer quantum | ['1.2E+2', []] | ['1.2E+2', ['Inexact', 'Rounded']] | Failed |
| overflow exponent | ['10000000000', []] | ['NaN', ['InvalidOperation']] | Failed |
SHA-256 / a1cff283b0168ade27d68cce42ed8fdbf859a7270261eb39b17807769843668b
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 11 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
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.139976+00:00.
Case digest / 32abee37ce53e1a2b3623fee1d4942db2b82211c1a95c1cec6dd154e63d27154