FA-17336 / Floating-point arithmetic / Open access
Nearest floating remainder keeps the sign of the divisor · case 01
Nearest floating remainder keeps the sign of the divisor.
ROOT CAUSE
Nearest floating remainder keeps the sign of the divisor. The faulty expression is ay=y.
VERIFIED REPAIR
Apply the contract at this fault site using ay=abs(y).
Unsuccessful approach: The attempted local correction ay=-abs(y) 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=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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| even tie | 2 | 2 | Passed |
| odd tie | -2 | -2 | Passed |
| negative even tie | -2 | -2 | Passed |
| negative odd tie | 2 | 2 | Passed |
| above half | -1 | -1 | Passed |
| below half | 1 | 1 | Passed |
| negative divisor below half | -3 | 1 | Failed |
| negative divisor | -1 | -1 | Passed |
| negative exact | -0 | -0 | Passed |
| positive exact | 0 | 0 | Passed |
| zero divisor | domain | domain | Passed |
| huge finite | -5e+307 | -5e+307 | Passed |
SHA-256 / 8b8c15d97698895b0be3a516d1888b5c148eaaed651c8e15751ac35449cf2fad
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| even tie | -2 | 2 | Failed |
| odd tie | -2 | -2 | Passed |
| negative even tie | 2 | -2 | Failed |
| negative odd tie | 2 | 2 | Passed |
| above half | -1 | -1 | Passed |
| below half | -3 | 1 | Failed |
| negative divisor below half | -3 | 1 | Failed |
| negative divisor | -1 | -1 | Passed |
| negative exact | 4 | -0 | Failed |
| positive exact | -4 | 0 | Failed |
| zero divisor | domain | domain | Passed |
| huge finite | -5e+307 | -5e+307 | Passed |
SHA-256 / a70cccbe6c30282d75cc18e1928d4166159bfde302962b028579177191aabd32
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| even tie | 2 | 2 | Passed |
| odd tie | -2 | -2 | Passed |
| negative even tie | -2 | -2 | Passed |
| negative odd tie | 2 | 2 | Passed |
| above half | -1 | -1 | Passed |
| below half | 1 | 1 | Passed |
| negative divisor below half | 1 | 1 | Passed |
| negative divisor | -1 | -1 | Passed |
| negative exact | -0 | -0 | Passed |
| positive exact | 0 | 0 | Passed |
| zero divisor | domain | domain | Passed |
| huge finite | -5e+307 | -5e+307 | Passed |
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.192120+00:00.
Case digest / 3e8c11bc9dfae2a384867567b05828e056eaf951b27a117520841b35a8f2aee5