FAILURE MAP
← Case archive

FA-17111 / Floating-point arithmetic / Open access

Midpoint silently sorts reversed endpoints · case 01

Midpoint silently sorts reversed endpoints.

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

ROOT CAUSE

Midpoint silently sorts reversed endpoints. The faulty expression is if a>b: a,b=b,a.

VERIFIED REPAIR

Apply the contract at this fault site using if a>b: return 'invalid'.

Unsuccessful approach: The attempted local correction if a>b: return b.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: a,b=b,a
    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
reverse0x1.8000000000000p+0invalidFailed

SHA-256 / 2da63a05ca7f32f507c31d8dc0986e9f026a36420c6879501daf224c771cbb04

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 b.hex()
    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
reverse0x1.0000000000000p+0invalidFailed

SHA-256 / 785f336a58f4208ae11b69446d2b8a8adb0a47e11388dab452de2c33d03f4f6f

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

Case digest / e7aaf0a51cac25b207e1600d82215ed73241cb00363f36185cb2cd7b8436cfad