FAILURE MAP
← Case archive

FA-17311 / Floating-point arithmetic / Open access

Nearest floating remainder rounds every quotient tie away from zero · case 01

Nearest floating remainder rounds every quotient tie away from zero.

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

ROOT CAUSE

Nearest floating remainder rounds every quotient tie away from zero. The faulty expression is if a>=other:.

THE FAILURE

Nearest floating remainder rounds every quotient tie away from zero. The faulty expression is if a>=other:.

Unsuccessful approach: The attempted local correction if a>other: 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=math.fmod(abs(x),2*ay)>=ay
        if a>=other:
            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 tie-2-2Passed
negative even tie2-2Failed
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 / 3ccde7ad5c725477df3e4588086c3595f82cd13d30ed27c63ddc59a0d14b68c1

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:
            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 / fd9eff663d3da6671673bb4ca1d1f050f93737d79ee07e6f8279465a86dd37e0

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 12 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / 7884aa6c01e160debca5029c0d2f69e6371ddf9c6059993951cc928939b0d9a3