FA-17251 / Floating-point arithmetic / Open access
Reciprocal flushes subnormal results · case 01
Reciprocal flushes subnormal results.
ROOT CAUSE
Reciprocal flushes subnormal results. The faulty expression is return render(math.copysign(0.0 if result<2.0**-1022 else result,x)).
VERIFIED REPAIR
Apply the contract at this fault site using return render(math.copysign(result,x)).
Unsuccessful approach: The attempted local correction return render(math.copysign(max(result,2.0**-1022),x)) still violates the explicit regression fixtures.
Case contract
Compute the reciprocal of finite binary64 x using exponent decomposition. Signed zeros return signed infinity; overflow returns signed infinity and representable subnormal reciprocals are retained. Finite results are rendered to eleven significant decimal digits; modeled domain violations and arithmetic errors are explicit strings.
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 struct
def render(x):
if math.isnan(x): return 'nan'
if math.isinf(x): return '-infinity' if x<0 else '+infinity'
return format(x,'.11g')
N = 1
observations = []
def solve(x):
try:
if x==0: return '-infinity' if math.copysign(1.0,x)<0 else '+infinity'
m,e=math.frexp(abs(x))
fraction=1/m
try:
result=math.ldexp(fraction,-e)
except OverflowError:
return '-infinity' if x<0 else '+infinity'
return render(math.copysign(0.0 if result<2.0**-1022 else result,x))
except (ValueError, OverflowError, ZeroDivisionError, TypeError):
return "arithmetic-error"
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('positive ordinary', solve(float(N)), render(1/N))
check('negative ordinary', solve(-float(N)), render(-1/N))
check('huge', solve(1e308), render(1e-308))
check('negative huge', solve(-1e308), render(-1e-308))
check('tiny overflow', solve(math.ldexp(1.0,-1074)), "+infinity")
check('negative tiny', solve(-math.ldexp(1.0,-1074)), "-infinity")
check('positive zero', solve(0.0), "+infinity")
check('negative zero', solve(-0.0), "-infinity")
check('fraction', solve(0.125), "8")
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 |
|---|---|---|---|
| positive ordinary | 1 | 1 | Passed |
| negative ordinary | -1 | -1 | Passed |
| huge | 0 | 1e-308 | Failed |
| negative huge | -0 | -1e-308 | Failed |
| tiny overflow | +infinity | +infinity | Passed |
| negative tiny | -infinity | -infinity | Passed |
| positive zero | +infinity | +infinity | Passed |
| negative zero | -infinity | -infinity | Passed |
| fraction | 8 | 8 | Passed |
SHA-256 / d7135728815a6137737750e6c933a82cff5cdc166ffc5cd57a2f436eec401f3d
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
if math.isnan(x): return 'nan'
if math.isinf(x): return '-infinity' if x<0 else '+infinity'
return format(x,'.11g')
N = 1
observations = []
def solve(x):
try:
if x==0: return '-infinity' if math.copysign(1.0,x)<0 else '+infinity'
m,e=math.frexp(abs(x))
fraction=1/m
try:
result=math.ldexp(fraction,-e)
except OverflowError:
return '-infinity' if x<0 else '+infinity'
return render(math.copysign(max(result,2.0**-1022),x))
except (ValueError, OverflowError, ZeroDivisionError, TypeError):
return "arithmetic-error"
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('positive ordinary', solve(float(N)), render(1/N))
check('negative ordinary', solve(-float(N)), render(-1/N))
check('huge', solve(1e308), render(1e-308))
check('negative huge', solve(-1e308), render(-1e-308))
check('tiny overflow', solve(math.ldexp(1.0,-1074)), "+infinity")
check('negative tiny', solve(-math.ldexp(1.0,-1074)), "-infinity")
check('positive zero', solve(0.0), "+infinity")
check('negative zero', solve(-0.0), "-infinity")
check('fraction', solve(0.125), "8")
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 |
|---|---|---|---|
| positive ordinary | 1 | 1 | Passed |
| negative ordinary | -1 | -1 | Passed |
| huge | 2.2250738585e-308 | 1e-308 | Failed |
| negative huge | -2.2250738585e-308 | -1e-308 | Failed |
| tiny overflow | +infinity | +infinity | Passed |
| negative tiny | -infinity | -infinity | Passed |
| positive zero | +infinity | +infinity | Passed |
| negative zero | -infinity | -infinity | Passed |
| fraction | 8 | 8 | Passed |
SHA-256 / bf2471824739251dfeda9b4cc839cb1d5031f9da2bf1526af4a6977b4e52e128
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
if math.isnan(x): return 'nan'
if math.isinf(x): return '-infinity' if x<0 else '+infinity'
return format(x,'.11g')
N = 1
observations = []
def solve(x):
try:
if x==0: return '-infinity' if math.copysign(1.0,x)<0 else '+infinity'
m,e=math.frexp(abs(x))
fraction=1/m
try:
result=math.ldexp(fraction,-e)
except OverflowError:
return '-infinity' if x<0 else '+infinity'
return render(math.copysign(result,x))
except (ValueError, OverflowError, ZeroDivisionError, TypeError):
return "arithmetic-error"
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('positive ordinary', solve(float(N)), render(1/N))
check('negative ordinary', solve(-float(N)), render(-1/N))
check('huge', solve(1e308), render(1e-308))
check('negative huge', solve(-1e308), render(-1e-308))
check('tiny overflow', solve(math.ldexp(1.0,-1074)), "+infinity")
check('negative tiny', solve(-math.ldexp(1.0,-1074)), "-infinity")
check('positive zero', solve(0.0), "+infinity")
check('negative zero', solve(-0.0), "-infinity")
check('fraction', solve(0.125), "8")
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 |
|---|---|---|---|
| positive ordinary | 1 | 1 | Passed |
| negative ordinary | -1 | -1 | Passed |
| huge | 1e-308 | 1e-308 | Passed |
| negative huge | -1e-308 | -1e-308 | Passed |
| tiny overflow | +infinity | +infinity | Passed |
| negative tiny | -infinity | -infinity | Passed |
| positive zero | +infinity | +infinity | Passed |
| negative zero | -infinity | -infinity | Passed |
| fraction | 8 | 8 | Passed |
SHA-256 / 82643796da93f08648e3a833d9bd6056f8ef38de0bbe127c8c746d13d50f4515
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:44.411198+00:00.
Case digest / 03e3b22593856eb4090b74a3ff8951226c06ff7af93a2e52bf708f184b64670e