FA-17231 / Floating-point arithmetic / Open access
Scaled square root rounds the exponent quotient upward · case 01
Scaled square root rounds the exponent quotient upward.
ROOT CAUSE
Scaled square root rounds the exponent quotient upward. The faulty expression is q,r=(e+1)//2,e%2.
VERIFIED REPAIR
Apply the contract at this fault site using q,r=divmod(e,2).
Unsuccessful approach: The attempted local correction q,r=abs(e)//2,e%2 still violates the explicit regression fixtures.
Case contract
Nonnegative square root of finite binary64 x via exponent normalization. Negative input returns domain; negative zero is preserved. 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:
if x<0: return 'domain'
if x==0: return render(x)
m,e=math.frexp(x)
q,r=(e+1)//2,e%2
root=math.sqrt(math.ldexp(m,r))
return render(math.ldexp(root,q))
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('square', solve(float(N*N)), render(float(N)))
check('normal', solve(float(N)), render(math.sqrt(N)))
check('huge', solve(1e300), "1e+150")
check('tiny', solve(1e-300), "1e-150")
check('odd exponent', solve(2.0), render(math.sqrt(2)))
check('positive root zero', solve(0.0), "0")
check('negative domain', solve(-float(N)), "domain")
check('negative zero', solve(-0.0), "-0")
check('subnormal', solve(math.ldexp(1.0,-1074)), render(math.ldexp(1.0,-537)))
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 |
|---|---|---|---|
| square | 2 | 1 | Failed |
| normal | 2 | 1 | Failed |
| huge | 2e+150 | 1e+150 | Failed |
| tiny | 1e-150 | 1e-150 | Passed |
| odd exponent | 1.4142135624 | 1.4142135624 | Passed |
| positive root zero | 0 | 0 | Passed |
| negative domain | domain | domain | Passed |
| negative zero | -0 | -0 | Passed |
| subnormal | 4.445517499e-162 | 2.2227587495e-162 | Failed |
SHA-256 / f4f16258cd54f05dc6ca40c5fb625bcef67af19a573c192531cc5dff53b88423
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:
if x<0: return 'domain'
if x==0: return render(x)
m,e=math.frexp(x)
q,r=abs(e)//2,e%2
root=math.sqrt(math.ldexp(m,r))
return render(math.ldexp(root,q))
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('square', solve(float(N*N)), render(float(N)))
check('normal', solve(float(N)), render(math.sqrt(N)))
check('huge', solve(1e300), "1e+150")
check('tiny', solve(1e-300), "1e-150")
check('odd exponent', solve(2.0), render(math.sqrt(2)))
check('positive root zero', solve(0.0), "0")
check('negative domain', solve(-float(N)), "domain")
check('negative zero', solve(-0.0), "-0")
check('subnormal', solve(math.ldexp(1.0,-1074)), render(math.ldexp(1.0,-537)))
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 |
|---|---|---|---|
| square | 1 | 1 | Passed |
| normal | 1 | 1 | Passed |
| huge | 1e+150 | 1e+150 | Passed |
| tiny | 6.6969287949e+149 | 1e-150 | Failed |
| odd exponent | 1.4142135624 | 1.4142135624 | Passed |
| positive root zero | 0 | 0 | Passed |
| negative domain | domain | domain | Passed |
| negative zero | -0 | -0 | Passed |
| subnormal | 2.2494568973e+161 | 2.2227587495e-162 | Failed |
SHA-256 / 597c822b568b0678cc44d4f74875b003ed9ff63b7fe5c72bfbe16595ce428709
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:
if x<0: return 'domain'
if x==0: return render(x)
m,e=math.frexp(x)
q,r=divmod(e,2)
root=math.sqrt(math.ldexp(m,r))
return render(math.ldexp(root,q))
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('square', solve(float(N*N)), render(float(N)))
check('normal', solve(float(N)), render(math.sqrt(N)))
check('huge', solve(1e300), "1e+150")
check('tiny', solve(1e-300), "1e-150")
check('odd exponent', solve(2.0), render(math.sqrt(2)))
check('positive root zero', solve(0.0), "0")
check('negative domain', solve(-float(N)), "domain")
check('negative zero', solve(-0.0), "-0")
check('subnormal', solve(math.ldexp(1.0,-1074)), render(math.ldexp(1.0,-537)))
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 |
|---|---|---|---|
| square | 1 | 1 | Passed |
| normal | 1 | 1 | Passed |
| huge | 1e+150 | 1e+150 | Passed |
| tiny | 1e-150 | 1e-150 | Passed |
| odd exponent | 1.4142135624 | 1.4142135624 | Passed |
| positive root zero | 0 | 0 | Passed |
| negative domain | domain | domain | Passed |
| negative zero | -0 | -0 | Passed |
| subnormal | 2.2227587495e-162 | 2.2227587495e-162 | Passed |
SHA-256 / a2be440e40877a8ca6d5cbe5e4d7abbf5c9581a86035cddc86c6c1bf1b225c3e
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:44.363901+00:00.
Case digest / 27ef4f5d153795dad7ca59db00780ee1f4388869d9f1ee34d4d965ceb8142b07