FAILURE MAP
← Case archive

FA-17316 / Floating-point arithmetic / Open access

Nearest floating remainder uses residual parity instead of quotient parity · case 01

Nearest floating remainder uses residual parity instead of quotient parity.

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

ROOT CAUSE

Nearest floating remainder uses residual parity instead of quotient parity. The faulty expression is odd=bool(int(abs(r))%2).

VERIFIED REPAIR

Apply the contract at this fault site using odd=math.fmod(abs(x),2*ay)>=ay.

Unsuccessful approach: The attempted local correction odd=math.fmod(abs(x),2*ay)<ay still violates the explicit regression fixtures.

Case contract

For finite x and finite nonzero y, return the remainder x-n*y with n the nearest integer quotient, ties to even. The output has magnitude at most abs(y)/2; exact zero has the sign of x. 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,y):
    try:
        if y==0: return 'domain'
        ay=abs(y)
        r=math.fmod(x,ay)
        a=abs(r)
        other=ay-a
        odd=bool(int(abs(r))%2)
        if a>other or (a==other and odd):
            r-=math.copysign(ay,x)
        if r==0: r=math.copysign(0.0,x)
        return render(r)
    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 tie', solve(2.0*N*4+2,4.0), "2")
check('odd tie', solve((2.0*N+1)*4+2,4.0), "-2")
check('negative even tie', solve(-2.0*N*4-2,4.0), "-2")
check('negative odd tie', solve(-(2.0*N+1)*4-2,4.0), "2")
check('above half', solve(4.0*N+3,4.0), "-1")
check('below half', solve(4.0*N+1,4.0), "1")
check('negative divisor below half', solve(4.0*N+1,-4.0), "1")
check('negative divisor', solve(4.0*N+3,-4.0), "-1")
check('negative exact', solve(-4.0*N,4.0), "-0")
check('positive exact', solve(4.0*N,4.0), "0")
check('zero divisor', solve(float(N),0.0), "domain")
check('huge finite', solve(1.5e308,1e308), render(math.remainder(1.5e308,1e308)))
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 tie22Passed
odd tie2-2Failed
negative even tie-2-2Passed
negative odd tie-22Failed
above half-1-1Passed
below half11Passed
negative divisor below half11Passed
negative divisor-1-1Passed
negative exact-0-0Passed
positive exact00Passed
zero divisordomaindomainPassed
huge finite5e+307-5e+307Failed

SHA-256 / b022139718f510e93e590f79adb009c55262c100534b7379bb4316222c5906bc

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,y):
    try:
        if y==0: return 'domain'
        ay=abs(y)
        r=math.fmod(x,ay)
        a=abs(r)
        other=ay-a
        odd=math.fmod(abs(x),2*ay)<ay
        if a>other or (a==other and odd):
            r-=math.copysign(ay,x)
        if r==0: r=math.copysign(0.0,x)
        return render(r)
    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 tie', solve(2.0*N*4+2,4.0), "2")
check('odd tie', solve((2.0*N+1)*4+2,4.0), "-2")
check('negative even tie', solve(-2.0*N*4-2,4.0), "-2")
check('negative odd tie', solve(-(2.0*N+1)*4-2,4.0), "2")
check('above half', solve(4.0*N+3,4.0), "-1")
check('below half', solve(4.0*N+1,4.0), "1")
check('negative divisor below half', solve(4.0*N+1,-4.0), "1")
check('negative divisor', solve(4.0*N+3,-4.0), "-1")
check('negative exact', solve(-4.0*N,4.0), "-0")
check('positive exact', solve(4.0*N,4.0), "0")
check('zero divisor', solve(float(N),0.0), "domain")
check('huge finite', solve(1.5e308,1e308), render(math.remainder(1.5e308,1e308)))
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 tie-22Failed
odd tie2-2Failed
negative even tie2-2Failed
negative odd tie-22Failed
above half-1-1Passed
below half11Passed
negative divisor below half11Passed
negative divisor-1-1Passed
negative exact-0-0Passed
positive exact00Passed
zero divisordomaindomainPassed
huge finite5e+307-5e+307Failed

SHA-256 / 4e841c523aaf12f217c64148bc30f084fdf75d0c2ea6321215566b1ffa0414f0

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,y):
    try:
        if y==0: return 'domain'
        ay=abs(y)
        r=math.fmod(x,ay)
        a=abs(r)
        other=ay-a
        odd=math.fmod(abs(x),2*ay)>=ay
        if a>other or (a==other and odd):
            r-=math.copysign(ay,x)
        if r==0: r=math.copysign(0.0,x)
        return render(r)
    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 tie', solve(2.0*N*4+2,4.0), "2")
check('odd tie', solve((2.0*N+1)*4+2,4.0), "-2")
check('negative even tie', solve(-2.0*N*4-2,4.0), "-2")
check('negative odd tie', solve(-(2.0*N+1)*4-2,4.0), "2")
check('above half', solve(4.0*N+3,4.0), "-1")
check('below half', solve(4.0*N+1,4.0), "1")
check('negative divisor below half', solve(4.0*N+1,-4.0), "1")
check('negative divisor', solve(4.0*N+3,-4.0), "-1")
check('negative exact', solve(-4.0*N,4.0), "-0")
check('positive exact', solve(4.0*N,4.0), "0")
check('zero divisor', solve(float(N),0.0), "domain")
check('huge finite', solve(1.5e308,1e308), render(math.remainder(1.5e308,1e308)))
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 tie22Passed
odd tie-2-2Passed
negative even tie-2-2Passed
negative odd tie22Passed
above half-1-1Passed
below half11Passed
negative divisor below half11Passed
negative divisor-1-1Passed
negative exact-0-0Passed
positive exact00Passed
zero divisordomaindomainPassed
huge finite-5e+307-5e+307Passed

SHA-256 / 219b3658834515af71ddcc114790af2e7ee62879adddbee7d0d062833b3403a6

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

Case digest / 298c2af5e1f026f8bdd22ea938f5c9fd005c9bea3a0c6a7dcc5f432d8c167bc7