FAILURE MAP
← Case archive

FA-17086 / Floating-point arithmetic / Open access

Closeness silently takes absolute values of negative tolerances · case 01

Closeness silently takes absolute values of negative tolerances.

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

ROOT CAUSE

Closeness silently takes absolute values of negative tolerances. The faulty expression is rel_tol=abs(rel_tol); abs_tol=abs(abs_tol).

VERIFIED REPAIR

Apply the contract at this fault site using if rel_tol<0 or abs_tol<0: return 'invalid'.

Unsuccessful approach: The attempted local correction if rel_tol<0 and abs_tol<0: return 'invalid' 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):
    rel_tol=abs(rel_tol); abs_tol=abs(abs_tol)
    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 relativeTrueinvalidFailed
bad absoluteTrueinvalidFailed

SHA-256 / 778b0f14a4be8b36b14c127aba8a7082efc27ea3ba38a528ecc385e8d68eb429

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 and 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 relativeTrueinvalidFailed
bad absoluteTrueinvalidFailed

SHA-256 / df1d10bef082ecf0a3d5ad8202571af948f28d16c1f3c304eedb942e5dcf0c52

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

Case digest / 3e62bcf0b379ac471f8264151ed01449924a2cf2aa28ee4eb084a78b376819c3