FAILURE MAP
← Case archive

FA-16786 / Floating-point arithmetic / Open access

Cosine-pi fails to take magnitude after signed reduction · case 01

Cosine-pi fails to take magnitude after signed reduction.

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

ROOT CAUSE

Cosine-pi fails to take magnitude after signed reduction. The faulty expression is r=math.remainder(x,2.0).

VERIFIED REPAIR

Apply the contract at this fault site using r=abs(math.remainder(x,2.0)).

Unsuccessful approach: The attempted local correction r=x%2.0 still violates the explicit regression fixtures.

Case contract

Evaluate cos(pi*x) for finite x after modulo-two reduction. Half integers return positive zero; integers are exact; near half integers use a sine of the distance to the half integer. 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,2.0)
        if r==0: return '1'
        if r==1: return '-1'
        if r==0.5: return '0'
        if r<0.5:
            result=math.sin(math.pi*(0.5-r))
        else:
            result=-math.sin(math.pi*(r-0.5))
        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('even integer', solve(2.0*N), "1")
check('odd integer', solve(2.0*N+1), "-1")
check('negative integer', solve(-2.0*N-1), "-1")
check('half integer', solve(2.0*N+0.5), "0")
check('quarter', solve(0.25), render(math.sqrt(0.5)))
check('three quarters', solve(0.75), render(-math.sqrt(0.5)))
check('near half below', solve(0.5-N*2.0**-50), render(math.sin(math.pi*N*2.0**-50)))
check('near half above', solve(0.5+N*2.0**-50), render(-math.sin(math.pi*N*2.0**-50)))
check('negative half', solve(-0.5), "0")
check('negative quarter', solve(-0.25), render(math.sqrt(0.5)))
check('large integer', solve(2.0**52+2*N), "1")
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
even integer11Passed
odd integer-1-1Passed
negative integer-1-1Passed
half integer00Passed
quarter0.707106781190.70710678119Passed
three quarters-0.70710678119-0.70710678119Passed
near half below2.7902947984e-152.7902947984e-15Passed
near half above-2.7902947984e-15-2.7902947984e-15Passed
negative half1.2246467991e-160Failed
negative quarter0.707106781190.70710678119Passed
large integer11Passed

SHA-256 / 20e7fc70acfd97f25d24b45ee901e72ccd013f7ab98ff3d97ffe5967e91da109

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=x%2.0
        if r==0: return '1'
        if r==1: return '-1'
        if r==0.5: return '0'
        if r<0.5:
            result=math.sin(math.pi*(0.5-r))
        else:
            result=-math.sin(math.pi*(r-0.5))
        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('even integer', solve(2.0*N), "1")
check('odd integer', solve(2.0*N+1), "-1")
check('negative integer', solve(-2.0*N-1), "-1")
check('half integer', solve(2.0*N+0.5), "0")
check('quarter', solve(0.25), render(math.sqrt(0.5)))
check('three quarters', solve(0.75), render(-math.sqrt(0.5)))
check('near half below', solve(0.5-N*2.0**-50), render(math.sin(math.pi*N*2.0**-50)))
check('near half above', solve(0.5+N*2.0**-50), render(-math.sin(math.pi*N*2.0**-50)))
check('negative half', solve(-0.5), "0")
check('negative quarter', solve(-0.25), render(math.sqrt(0.5)))
check('large integer', solve(2.0**52+2*N), "1")
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
even integer11Passed
odd integer-1-1Passed
negative integer-1-1Passed
half integer00Passed
quarter0.707106781190.70710678119Passed
three quarters-0.70710678119-0.70710678119Passed
near half below2.7902947984e-152.7902947984e-15Passed
near half above-2.7902947984e-15-2.7902947984e-15Passed
negative half-1.2246467991e-160Failed
negative quarter0.707106781190.70710678119Passed
large integer11Passed

SHA-256 / d9b00dcd255ffed99fdcd990cf86d274a3b05958dce59a20e94c486c9962f8e0

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=abs(math.remainder(x,2.0))
        if r==0: return '1'
        if r==1: return '-1'
        if r==0.5: return '0'
        if r<0.5:
            result=math.sin(math.pi*(0.5-r))
        else:
            result=-math.sin(math.pi*(r-0.5))
        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('even integer', solve(2.0*N), "1")
check('odd integer', solve(2.0*N+1), "-1")
check('negative integer', solve(-2.0*N-1), "-1")
check('half integer', solve(2.0*N+0.5), "0")
check('quarter', solve(0.25), render(math.sqrt(0.5)))
check('three quarters', solve(0.75), render(-math.sqrt(0.5)))
check('near half below', solve(0.5-N*2.0**-50), render(math.sin(math.pi*N*2.0**-50)))
check('near half above', solve(0.5+N*2.0**-50), render(-math.sin(math.pi*N*2.0**-50)))
check('negative half', solve(-0.5), "0")
check('negative quarter', solve(-0.25), render(math.sqrt(0.5)))
check('large integer', solve(2.0**52+2*N), "1")
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
even integer11Passed
odd integer-1-1Passed
negative integer-1-1Passed
half integer00Passed
quarter0.707106781190.70710678119Passed
three quarters-0.70710678119-0.70710678119Passed
near half below2.7902947984e-152.7902947984e-15Passed
near half above-2.7902947984e-15-2.7902947984e-15Passed
negative half00Passed
negative quarter0.707106781190.70710678119Passed
large integer11Passed

SHA-256 / 41416c11b6aa6861cfaa3b93f83ae6b9d6dd75bceb32e3074e0a4dba029dbad1

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

Case digest / 87d9a99a2adabe3adb831f86571f29c587dc5a8325ef76f8164a65a31fe9f6ad