FAILURE MAP
← Case archive

FA-17071 / Floating-point arithmetic / Open access

Relative closeness uses signed magnitudes · case 01

Relative closeness uses signed magnitudes.

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

ROOT CAUSE

Relative closeness uses signed magnitudes. The faulty expression is relative=rel_tol*max(a,b).

VERIFIED REPAIR

Apply the contract at this fault site using relative=rel_tol*max(abs(a),abs(b)).

Unsuccessful approach: The attempted local correction relative=rel_tol*min(abs(a),abs(b)) still violates the explicit regression fixtures.

Case contract

Symmetric binary64 closeness: equal values including like-signed infinities are close; remaining nonfinite pairs are not. For finite a,b require abs(a-b)<=max(abs_tol,rel_tol*max(abs(a),abs(b))). Negative tolerances return invalid.

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,rel_tol,abs_tol):
    if rel_tol<0 or abs_tol<0: return 'invalid'
    if a==b: return True
    if not math.isfinite(a) or not math.isfinite(b): return False
    difference=abs(a-b)
    relative=rel_tol*max(a,b)
    return difference<=max(abs_tol,relative)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('equal infinity', solve(math.inf,math.inf,1e-9,0.0), True)
check('opposite infinity', solve(math.inf,-math.inf,1e-9,0.0), False)
check('nan', solve(math.nan,math.nan,1.0,1.0), False)
check('absolute zero', solve(0.0,N*1e-9,0.0,N*1e-9), True)
check('relative boundary', solve(float(N),float(N*2),0.5,0.0), True)
check('reverse relative', solve(float(N*2),float(N),0.5,0.0), True)
check('negative values', solve(-float(N),-float(N*2),0.5,0.0), True)
check('disjoint tolerances', solve(0.0,1.5,0.5,1.0), False)
check('ordinary apart', solve(float(N),float(N+1),1e-6,0.0), False)
check('bad relative', solve(1.0,1.0,-1.0,0.0), "invalid")
check('bad absolute', solve(1.0,1.0,0.0,-1.0), "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
equal infinityTrueTruePassed
opposite infinityFalseFalsePassed
nanFalseFalsePassed
absolute zeroTrueTruePassed
relative boundaryTrueTruePassed
reverse relativeTrueTruePassed
negative valuesFalseTrueFailed
disjoint tolerancesFalseFalsePassed
ordinary apartFalseFalsePassed
bad relativeinvalidinvalidPassed
bad absoluteinvalidinvalidPassed

SHA-256 / 6fbcced2dfca76f50b2cc755fc5d6285b3ffa2b2106d1354100c51857b2fe455

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,rel_tol,abs_tol):
    if rel_tol<0 or abs_tol<0: return 'invalid'
    if a==b: return True
    if not math.isfinite(a) or not math.isfinite(b): return False
    difference=abs(a-b)
    relative=rel_tol*min(abs(a),abs(b))
    return difference<=max(abs_tol,relative)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('equal infinity', solve(math.inf,math.inf,1e-9,0.0), True)
check('opposite infinity', solve(math.inf,-math.inf,1e-9,0.0), False)
check('nan', solve(math.nan,math.nan,1.0,1.0), False)
check('absolute zero', solve(0.0,N*1e-9,0.0,N*1e-9), True)
check('relative boundary', solve(float(N),float(N*2),0.5,0.0), True)
check('reverse relative', solve(float(N*2),float(N),0.5,0.0), True)
check('negative values', solve(-float(N),-float(N*2),0.5,0.0), True)
check('disjoint tolerances', solve(0.0,1.5,0.5,1.0), False)
check('ordinary apart', solve(float(N),float(N+1),1e-6,0.0), False)
check('bad relative', solve(1.0,1.0,-1.0,0.0), "invalid")
check('bad absolute', solve(1.0,1.0,0.0,-1.0), "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
equal infinityTrueTruePassed
opposite infinityFalseFalsePassed
nanFalseFalsePassed
absolute zeroTrueTruePassed
relative boundaryFalseTrueFailed
reverse relativeFalseTrueFailed
negative valuesFalseTrueFailed
disjoint tolerancesFalseFalsePassed
ordinary apartFalseFalsePassed
bad relativeinvalidinvalidPassed
bad absoluteinvalidinvalidPassed

SHA-256 / 9a2446c091a05fb719e764e0c19c50cb4ae36e22df611a19b7d5cc2ad93c443e

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,rel_tol,abs_tol):
    if rel_tol<0 or abs_tol<0: return 'invalid'
    if a==b: return True
    if not math.isfinite(a) or not math.isfinite(b): return False
    difference=abs(a-b)
    relative=rel_tol*max(abs(a),abs(b))
    return difference<=max(abs_tol,relative)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('equal infinity', solve(math.inf,math.inf,1e-9,0.0), True)
check('opposite infinity', solve(math.inf,-math.inf,1e-9,0.0), False)
check('nan', solve(math.nan,math.nan,1.0,1.0), False)
check('absolute zero', solve(0.0,N*1e-9,0.0,N*1e-9), True)
check('relative boundary', solve(float(N),float(N*2),0.5,0.0), True)
check('reverse relative', solve(float(N*2),float(N),0.5,0.0), True)
check('negative values', solve(-float(N),-float(N*2),0.5,0.0), True)
check('disjoint tolerances', solve(0.0,1.5,0.5,1.0), False)
check('ordinary apart', solve(float(N),float(N+1),1e-6,0.0), False)
check('bad relative', solve(1.0,1.0,-1.0,0.0), "invalid")
check('bad absolute', solve(1.0,1.0,0.0,-1.0), "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
equal infinityTrueTruePassed
opposite infinityFalseFalsePassed
nanFalseFalsePassed
absolute zeroTrueTruePassed
relative boundaryTrueTruePassed
reverse relativeTrueTruePassed
negative valuesTrueTruePassed
disjoint tolerancesFalseFalsePassed
ordinary apartFalseFalsePassed
bad relativeinvalidinvalidPassed
bad absoluteinvalidinvalidPassed

SHA-256 / d99becf37aff8567b546848e57dd7b96eb8a46f9a6359a7133a912bf628d5c9f

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

Case digest / b923e3a687d177f51b80c6ec435aaeb673b0ba3cc54f5c1ba9cebff1b7f731cc