FAILURE MAP
← Case archive

FA-16826 / Floating-point arithmetic / Open access

Tangent-pi loses the sign of its near-pole branch · case 01

Tangent-pi loses the sign of its near-pole branch.

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

ROOT CAUSE

Tangent-pi loses the sign of its near-pole branch. The faulty expression is result=1/math.tan(math.pi*d).

VERIFIED REPAIR

Apply the contract at this fault site using result=math.copysign(1/math.tan(math.pi*d),r).

Unsuccessful approach: The attempted local correction result=-1/math.tan(math.pi*d) still violates the explicit regression fixtures.

Case contract

Evaluate tan(pi*x) after modulo-one reduction. Exact half integers are poles; integer zeros carry the sign of x. Near poles use a reciprocal tangent of distance to the pole. Finite results are rendered to eleven significant decimal digits; modeled domain violations and arithmetic errors are explicit strings.

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
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x):
    try:
        r=math.remainder(x,1.0)
        if r==0: return render(math.copysign(0.0,x))
        if abs(r)==0.5: return 'pole'
        if abs(r)>0.25:
            d=0.5-abs(r)
            result=1/math.tan(math.pi*d)
        else:
            result=math.tan(math.pi*r)
        return render(result)
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('integer', solve(float(N)), "0")
check('negative integer', solve(-float(N)), "-0")
check('positive quarter', solve(2.0*N+0.25), "1")
check('negative quarter', solve(-2.0*N-0.25), "-1")
check('pole', solve(N+0.5), "pole")
check('negative pole', solve(-N-0.5), "pole")
check('near positive pole', solve(0.5-N*2.0**-50), render(1/math.tan(math.pi*N*2.0**-50)))
check('near negative pole', solve(-0.5+N*2.0**-50), render(-1/math.tan(math.pi*N*2.0**-50)))
check('beyond pole', solve(0.75), "-1")
check('huge integer', solve(2.0**52+N), "0")
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
integer00Passed
negative integer-0-0Passed
positive quarter11Passed
negative quarter-1-1Passed
polepolepolePassed
negative polepolepolePassed
near positive pole3.583850712e+143.583850712e+14Passed
near negative pole3.583850712e+14-3.583850712e+14Failed
beyond pole-1-1Passed
huge integer00Passed

SHA-256 / 1eb761d4a71c649210ce6d14920c7fc6e23f3f969541f4a480031be4078b5e8c

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x):
    try:
        r=math.remainder(x,1.0)
        if r==0: return render(math.copysign(0.0,x))
        if abs(r)==0.5: return 'pole'
        if abs(r)>0.25:
            d=0.5-abs(r)
            result=-1/math.tan(math.pi*d)
        else:
            result=math.tan(math.pi*r)
        return render(result)
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('integer', solve(float(N)), "0")
check('negative integer', solve(-float(N)), "-0")
check('positive quarter', solve(2.0*N+0.25), "1")
check('negative quarter', solve(-2.0*N-0.25), "-1")
check('pole', solve(N+0.5), "pole")
check('negative pole', solve(-N-0.5), "pole")
check('near positive pole', solve(0.5-N*2.0**-50), render(1/math.tan(math.pi*N*2.0**-50)))
check('near negative pole', solve(-0.5+N*2.0**-50), render(-1/math.tan(math.pi*N*2.0**-50)))
check('beyond pole', solve(0.75), "-1")
check('huge integer', solve(2.0**52+N), "0")
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
integer00Passed
negative integer-0-0Passed
positive quarter11Passed
negative quarter-1-1Passed
polepolepolePassed
negative polepolepolePassed
near positive pole-3.583850712e+143.583850712e+14Failed
near negative pole-3.583850712e+14-3.583850712e+14Passed
beyond pole-1-1Passed
huge integer00Passed

SHA-256 / 389e69e33d5efc8189d159f28e90460eb8b76c19639cf2ab559f8ec9acc38292

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x):
    try:
        r=math.remainder(x,1.0)
        if r==0: return render(math.copysign(0.0,x))
        if abs(r)==0.5: return 'pole'
        if abs(r)>0.25:
            d=0.5-abs(r)
            result=math.copysign(1/math.tan(math.pi*d),r)
        else:
            result=math.tan(math.pi*r)
        return render(result)
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('integer', solve(float(N)), "0")
check('negative integer', solve(-float(N)), "-0")
check('positive quarter', solve(2.0*N+0.25), "1")
check('negative quarter', solve(-2.0*N-0.25), "-1")
check('pole', solve(N+0.5), "pole")
check('negative pole', solve(-N-0.5), "pole")
check('near positive pole', solve(0.5-N*2.0**-50), render(1/math.tan(math.pi*N*2.0**-50)))
check('near negative pole', solve(-0.5+N*2.0**-50), render(-1/math.tan(math.pi*N*2.0**-50)))
check('beyond pole', solve(0.75), "-1")
check('huge integer', solve(2.0**52+N), "0")
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
integer00Passed
negative integer-0-0Passed
positive quarter11Passed
negative quarter-1-1Passed
polepolepolePassed
negative polepolepolePassed
near positive pole3.583850712e+143.583850712e+14Passed
near negative pole-3.583850712e+14-3.583850712e+14Passed
beyond pole-1-1Passed
huge integer00Passed

SHA-256 / 7bb38e60b67d2bd67d075181f824cc22d182debd28495d76f9e37878be73bfdd

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

Case digest / bc760c832c3abb61f5c12c8d5f0e6d8eacccc43d44f73f3486e937e96b93e967