FA-16101 / Floating-point arithmetic / Open access
ULP distance returns signed separation · case 01
ULP distance returns signed separation.
ROOT CAUSE
ULP distance returns signed separation. The faulty expression is return a_index-b_index.
VERIFIED REPAIR
Apply the contract at this fault site using return abs(a_index-b_index).
Unsuccessful approach: The attempted local correction return b_index-a_index still violates the explicit regression fixtures.
Case contract
Distance between finite binary64 values in representable steps, treating the two zeros as a single position; NaN or infinity yields null. Negative and positive subnormals are adjacent through zero.
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
N = 1
observations = []
def solve(a,b):
if not math.isfinite(a) or not math.isfinite(b): return None
ab=int.from_bytes(struct.pack('>d',a),'big')
bb=int.from_bytes(struct.pack('>d',b),'big')
a_index=-(ab&((1<<63)-1)) if ab>>63 else ab
b_index=-(bb&((1<<63)-1)) if bb>>63 else bb
return a_index-b_index
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('same', solve(float(N),float(N)), 0)
check('zero signs', solve(-0.0,0.0), 0)
check('negative adjacent', solve(-float(N),math.nextafter(-float(N),-math.inf)), 1)
check('positive adjacent', solve(float(N),math.nextafter(float(N),math.inf)), 1)
check('cross zero', solve(-math.ldexp(float(N),-1074),math.ldexp(float(N),-1074)), 2*N)
check('reverse cross', solve(math.ldexp(float(N),-1074),-math.ldexp(float(N),-1074)), 2*N)
check('nan left', solve(float("nan"),1.0), None)
check('nan right', solve(1.0,float("nan")), None)
check('infinity', solve(math.inf,math.inf), None)
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 |
|---|---|---|---|
| same | 0 | 0 | Passed |
| zero signs | 0 | 0 | Passed |
| negative adjacent | 1 | 1 | Passed |
| positive adjacent | -1 | 1 | Failed |
| cross zero | -2 | 2 | Failed |
| reverse cross | 2 | 2 | Passed |
| nan left | None | None | Passed |
| nan right | None | None | Passed |
| infinity | None | None | Passed |
SHA-256 / 299bc14863554e22136767f2c98d4daeca783a91b2959b0d38a6055d37117bc3
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
N = 1
observations = []
def solve(a,b):
if not math.isfinite(a) or not math.isfinite(b): return None
ab=int.from_bytes(struct.pack('>d',a),'big')
bb=int.from_bytes(struct.pack('>d',b),'big')
a_index=-(ab&((1<<63)-1)) if ab>>63 else ab
b_index=-(bb&((1<<63)-1)) if bb>>63 else bb
return b_index-a_index
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('same', solve(float(N),float(N)), 0)
check('zero signs', solve(-0.0,0.0), 0)
check('negative adjacent', solve(-float(N),math.nextafter(-float(N),-math.inf)), 1)
check('positive adjacent', solve(float(N),math.nextafter(float(N),math.inf)), 1)
check('cross zero', solve(-math.ldexp(float(N),-1074),math.ldexp(float(N),-1074)), 2*N)
check('reverse cross', solve(math.ldexp(float(N),-1074),-math.ldexp(float(N),-1074)), 2*N)
check('nan left', solve(float("nan"),1.0), None)
check('nan right', solve(1.0,float("nan")), None)
check('infinity', solve(math.inf,math.inf), None)
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 |
|---|---|---|---|
| same | 0 | 0 | Passed |
| zero signs | 0 | 0 | Passed |
| negative adjacent | -1 | 1 | Failed |
| positive adjacent | 1 | 1 | Passed |
| cross zero | 2 | 2 | Passed |
| reverse cross | -2 | 2 | Failed |
| nan left | None | None | Passed |
| nan right | None | None | Passed |
| infinity | None | None | Passed |
SHA-256 / 8e82646b9c02c4ca45c5ad6ade7f2b2f43d0b098ed42ed2eda7260425956bbef
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
N = 1
observations = []
def solve(a,b):
if not math.isfinite(a) or not math.isfinite(b): return None
ab=int.from_bytes(struct.pack('>d',a),'big')
bb=int.from_bytes(struct.pack('>d',b),'big')
a_index=-(ab&((1<<63)-1)) if ab>>63 else ab
b_index=-(bb&((1<<63)-1)) if bb>>63 else bb
return abs(a_index-b_index)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('same', solve(float(N),float(N)), 0)
check('zero signs', solve(-0.0,0.0), 0)
check('negative adjacent', solve(-float(N),math.nextafter(-float(N),-math.inf)), 1)
check('positive adjacent', solve(float(N),math.nextafter(float(N),math.inf)), 1)
check('cross zero', solve(-math.ldexp(float(N),-1074),math.ldexp(float(N),-1074)), 2*N)
check('reverse cross', solve(math.ldexp(float(N),-1074),-math.ldexp(float(N),-1074)), 2*N)
check('nan left', solve(float("nan"),1.0), None)
check('nan right', solve(1.0,float("nan")), None)
check('infinity', solve(math.inf,math.inf), None)
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 |
|---|---|---|---|
| same | 0 | 0 | Passed |
| zero signs | 0 | 0 | Passed |
| negative adjacent | 1 | 1 | Passed |
| positive adjacent | 1 | 1 | Passed |
| cross zero | 2 | 2 | Passed |
| reverse cross | 2 | 2 | Passed |
| nan left | None | None | Passed |
| nan right | None | None | Passed |
| infinity | None | None | Passed |
SHA-256 / b4444a40538d6b1c2937a3fd331d44cb409920423aaa46f429612d1c2911aa1c
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:33.258410+00:00.
Case digest / bd81ae198cf4c09e7ba6f3218d503022742d3a24ad8283c4324cdd740f230438