FAILURE MAP
← Case archive

FA-17106 / Floating-point arithmetic / Open access

Midpoint computes an exact negative-zero endpoint through addition · case 01

Midpoint computes an exact negative-zero endpoint through addition.

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

ROOT CAUSE

Midpoint computes an exact negative-zero endpoint through addition. The faulty expression is if a==b: return (a+0.0).hex().

VERIFIED REPAIR

Apply the contract at this fault site using if a==b: return a.hex().

Unsuccessful approach: The attempted local correction if a==b: return abs(a).hex() still violates the explicit regression fixtures.

Case contract

Finite ordered binary64 midpoint rendered as hex. Opposite-sign endpoints use half-sums to avoid difference overflow; same-sign endpoints use a difference to preserve subnormal increments. Exact equal endpoints preserve their bits.

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 a>b: return 'invalid'
    if a==b: return (a+0.0).hex()
    if a<0<b:
        midpoint=a/2+b/2
    else:
        midpoint=a+(b-a)/2
    return midpoint.hex()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('opposite huge', solve(-1e308,1e308), 0.0.hex())
check('positive huge', solve(1e308,1.5e308), (1.25e308).hex())
check('negative huge', solve(-1.5e308,-1e308), (-1.25e308).hex())
check('subnormal midpoint', solve(math.ldexp(1.0,-1074),math.ldexp(5.0,-1074)), math.ldexp(3.0,-1074).hex())
check('subnormal same', solve(math.ldexp(1.0,-1074),math.ldexp(3.0,-1074)), math.ldexp(2.0,-1074).hex())
check('negative subnormal', solve(-math.ldexp(3.0,-1074),-math.ldexp(1.0,-1074)), (-math.ldexp(2.0,-1074)).hex())
check('negative zero equal', solve(-0.0,-0.0), (-0.0).hex())
check('ordinary', solve(float(N),float(N+8)), float(N+4).hex())
check('reverse', solve(float(N+1),float(N)), "invalid")
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
opposite huge0x0.0p+00x0.0p+0Passed
positive huge0x1.640306766bac8p+10230x1.640306766bac8p+1023Passed
negative huge-0x1.640306766bac8p+1023-0x1.640306766bac8p+1023Passed
subnormal midpoint0x0.0000000000003p-10220x0.0000000000003p-1022Passed
subnormal same0x0.0000000000002p-10220x0.0000000000002p-1022Passed
negative subnormal-0x0.0000000000002p-1022-0x0.0000000000002p-1022Passed
negative zero equal0x0.0p+0-0x0.0p+0Failed
ordinary0x1.4000000000000p+20x1.4000000000000p+2Passed
reverseinvalidinvalidPassed

SHA-256 / 829dd5dcf347adf4168632cf0d0cab2729ecce05d9689bdeb137c62b3ea3fed8

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 a>b: return 'invalid'
    if a==b: return abs(a).hex()
    if a<0<b:
        midpoint=a/2+b/2
    else:
        midpoint=a+(b-a)/2
    return midpoint.hex()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('opposite huge', solve(-1e308,1e308), 0.0.hex())
check('positive huge', solve(1e308,1.5e308), (1.25e308).hex())
check('negative huge', solve(-1.5e308,-1e308), (-1.25e308).hex())
check('subnormal midpoint', solve(math.ldexp(1.0,-1074),math.ldexp(5.0,-1074)), math.ldexp(3.0,-1074).hex())
check('subnormal same', solve(math.ldexp(1.0,-1074),math.ldexp(3.0,-1074)), math.ldexp(2.0,-1074).hex())
check('negative subnormal', solve(-math.ldexp(3.0,-1074),-math.ldexp(1.0,-1074)), (-math.ldexp(2.0,-1074)).hex())
check('negative zero equal', solve(-0.0,-0.0), (-0.0).hex())
check('ordinary', solve(float(N),float(N+8)), float(N+4).hex())
check('reverse', solve(float(N+1),float(N)), "invalid")
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
opposite huge0x0.0p+00x0.0p+0Passed
positive huge0x1.640306766bac8p+10230x1.640306766bac8p+1023Passed
negative huge-0x1.640306766bac8p+1023-0x1.640306766bac8p+1023Passed
subnormal midpoint0x0.0000000000003p-10220x0.0000000000003p-1022Passed
subnormal same0x0.0000000000002p-10220x0.0000000000002p-1022Passed
negative subnormal-0x0.0000000000002p-1022-0x0.0000000000002p-1022Passed
negative zero equal0x0.0p+0-0x0.0p+0Failed
ordinary0x1.4000000000000p+20x1.4000000000000p+2Passed
reverseinvalidinvalidPassed

SHA-256 / f0f9d1a88500177220af6e9177a4f4543f4adc42b37d8c2c900d9c8af99c1c52

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 a>b: return 'invalid'
    if a==b: return a.hex()
    if a<0<b:
        midpoint=a/2+b/2
    else:
        midpoint=a+(b-a)/2
    return midpoint.hex()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('opposite huge', solve(-1e308,1e308), 0.0.hex())
check('positive huge', solve(1e308,1.5e308), (1.25e308).hex())
check('negative huge', solve(-1.5e308,-1e308), (-1.25e308).hex())
check('subnormal midpoint', solve(math.ldexp(1.0,-1074),math.ldexp(5.0,-1074)), math.ldexp(3.0,-1074).hex())
check('subnormal same', solve(math.ldexp(1.0,-1074),math.ldexp(3.0,-1074)), math.ldexp(2.0,-1074).hex())
check('negative subnormal', solve(-math.ldexp(3.0,-1074),-math.ldexp(1.0,-1074)), (-math.ldexp(2.0,-1074)).hex())
check('negative zero equal', solve(-0.0,-0.0), (-0.0).hex())
check('ordinary', solve(float(N),float(N+8)), float(N+4).hex())
check('reverse', solve(float(N+1),float(N)), "invalid")
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
opposite huge0x0.0p+00x0.0p+0Passed
positive huge0x1.640306766bac8p+10230x1.640306766bac8p+1023Passed
negative huge-0x1.640306766bac8p+1023-0x1.640306766bac8p+1023Passed
subnormal midpoint0x0.0000000000003p-10220x0.0000000000003p-1022Passed
subnormal same0x0.0000000000002p-10220x0.0000000000002p-1022Passed
negative subnormal-0x0.0000000000002p-1022-0x0.0000000000002p-1022Passed
negative zero equal-0x0.0p+0-0x0.0p+0Passed
ordinary0x1.4000000000000p+20x1.4000000000000p+2Passed
reverseinvalidinvalidPassed

SHA-256 / 0012a90273b46b3f5e0d0c84c54b3347f32324dff9ac8f78b39bd3527c153291

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

Case digest / 9ea3fd4f2bf7c7c1e812896cd4303d205f8cadc493f627c08d4bd9eacb55b756