FAILURE MAP
← Case archive

FA-16676 / Floating-point arithmetic / Open access

Stochastic rounding accepts an out-of-range remainder · case 01

Stochastic rounding accepts an out-of-range remainder.

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

ROOT CAUSE

Stochastic rounding accepts an out-of-range remainder. The faulty expression is if k<0 or rem<0 or rem>(1<<k) or draw<0 or draw>(1<<k): return "invalid".

THE FAILURE

Stochastic rounding accepts an out-of-range remainder. The faulty expression is if k<0 or rem<0 or rem>(1<<k) or draw<0 or draw>(1<<k): return "invalid".

Unsuccessful approach: The attempted local correction if k<0 or draw<0: return "invalid" still violates the explicit regression fixtures.

Case contract

Stipulated stochastic rounding of nonnegative significand with exact dyadic remainder rem/2**k. Draw is uniform integer in [0,2**k); increment magnitude iff draw<rem, then apply sign. Exact results never increment. Return rounded value and whether magnitude incremented.

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
N = 1
observations = []
def solve(q,rem,k,draw,sign):
    if k<0 or rem<0 or rem>(1<<k) or draw<0 or draw>(1<<k): return "invalid"
    if rem==0: return [sign*q,False]
    inc=draw<rem
    return [sign*(q+int(inc)),inc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('draw below', solve(N,3,3,2,1), [N+1,True])
check('draw equality', solve(N,3,3,3,1), [N,False])
check('draw above', solve(N,3,3,7,1), [N,False])
check('negative increment', solve(N,3,3,1,-1), [-N-1,True])
check('negative no increment', solve(N,3,3,5,-1), [-N,False])
check('exact', solve(N,0,3,0,1), [N,False])
check('invalid remainder', solve(N,8,3,0,1), "invalid")
check('invalid draw', solve(N,3,3,8,1), "invalid")
check('large resolution', solve(N,1,54,0,1), [N+1,True])
check('resolution boundary', solve(N,1,54,1,1), [N,False])
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
draw below[2, True][2, True]Passed
draw equality[1, False][1, False]Passed
draw above[1, False][1, False]Passed
negative increment[-2, True][-2, True]Passed
negative no increment[-1, False][-1, False]Passed
exact[1, False][1, False]Passed
invalid remainder[2, True]invalidFailed
invalid draw[1, False]invalidFailed
large resolution[2, True][2, True]Passed
resolution boundary[1, False][1, False]Passed

SHA-256 / 530828dcd61e90da4f240638498b7af86723524ff6d94eec676dd93214af5df4

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
N = 1
observations = []
def solve(q,rem,k,draw,sign):
    if k<0 or draw<0: return "invalid"
    if rem==0: return [sign*q,False]
    inc=draw<rem
    return [sign*(q+int(inc)),inc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('draw below', solve(N,3,3,2,1), [N+1,True])
check('draw equality', solve(N,3,3,3,1), [N,False])
check('draw above', solve(N,3,3,7,1), [N,False])
check('negative increment', solve(N,3,3,1,-1), [-N-1,True])
check('negative no increment', solve(N,3,3,5,-1), [-N,False])
check('exact', solve(N,0,3,0,1), [N,False])
check('invalid remainder', solve(N,8,3,0,1), "invalid")
check('invalid draw', solve(N,3,3,8,1), "invalid")
check('large resolution', solve(N,1,54,0,1), [N+1,True])
check('resolution boundary', solve(N,1,54,1,1), [N,False])
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
draw below[2, True][2, True]Passed
draw equality[1, False][1, False]Passed
draw above[1, False][1, False]Passed
negative increment[-2, True][-2, True]Passed
negative no increment[-1, False][-1, False]Passed
exact[1, False][1, False]Passed
invalid remainder[2, True]invalidFailed
invalid draw[1, False]invalidFailed
large resolution[2, True][2, True]Passed
resolution boundary[1, False][1, False]Passed

SHA-256 / cf0393a49a268d261752c25da9dbd375fcd36dcd64e94956dfe6fdb3348b4cf1

HELD IN THE MEMBER ARCHIVE

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

This mechanism has 10 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:38.704297+00:00.

Case digest / 5940562d5fec45e2bfc50046c459aa496fd48ceeac8d0ed01531fb516212407b