FAILURE MAP
← Case archive

FA-16091 / Floating-point arithmetic / Open access

ULP distance leaves the first negative encoding unsigned · case 01

ULP distance leaves the first negative encoding unsigned.

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

ROOT CAUSE

ULP distance leaves the first negative encoding unsigned. The faulty expression is a_index=ab.

VERIFIED REPAIR

Apply the contract at this fault site using a_index=-(ab&((1<<63)-1)) if ab>>63 else ab.

Unsuccessful approach: The attempted local correction a_index=~ab if ab>>63 else ab 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
    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 fixtureActualExpectedOutcome
same00Passed
zero signs92233720368547758080Failed
negative adjacent184377368744548106251Failed
positive adjacent11Passed
cross zero92233720368547758082Failed
reverse cross22Passed
nan leftNoneNonePassed
nan rightNoneNonePassed
infinityNoneNonePassed

SHA-256 / da781445cc325f5cadfd5449062ae17898807930bc2a9415eabb060e76ea1cc3

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 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 fixtureActualExpectedOutcome
same00Passed
zero signs92233720368547758090Failed
negative adjacent92233720368547758081Failed
positive adjacent11Passed
cross zero92233720368547758112Failed
reverse cross22Passed
nan leftNoneNonePassed
nan rightNoneNonePassed
infinityNoneNonePassed

SHA-256 / 181ec215dae198f111437e685433ee1e080194cdf0909470b3f8fd02001ecfa3

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 fixtureActualExpectedOutcome
same00Passed
zero signs00Passed
negative adjacent11Passed
positive adjacent11Passed
cross zero22Passed
reverse cross22Passed
nan leftNoneNonePassed
nan rightNoneNonePassed
infinityNoneNonePassed

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

Case digest / 9c6c751df3e0f6a40652a3e3602861d7ad21e396cb560a4e1d0fbdf89a9a8217