FAILURE MAP
← Case archive

FA-5366 / Integer arithmetic / Open access

Minimum signed twos complement width · case 01

Negative powers of two are allocated an unnecessary sign bit.

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

ROOT CAUSE

Negative powers of two are allocated an unnecessary sign bit.

VERIFIED REPAIR

Apply the specified mathematical contract directly, preserving all terms and boundary cases: return max(1, (n if n >= 0 else ~n).bit_length()+1)

Unsuccessful approach: Dropping the sign bit underallocates positive values.

Case contract

Integer arguments; denominators, steps, moduli, and bit widths are positive. Unsigned word inputs fit the specified width except where masking is explicitly the operation. Sequence sizes are nonnegative. Return the smallest positive width whose signed two-complement range contains n. Exact operational definition: max(1, (n if n >= 0 else ~n).bit_length()+1)

Why this case matters

Small exact fixtures expose this error without platform timing, external services, or probabilistic observations. Integer mathematics results depend on the stated convention.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR

N = 1
observations = []
def solve(n):
    return abs(n).bit_length()+1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (-8,)', solve(*(-8,)), 4)
check('fixture 2: (7,)', solve(*(7,)), 4)
check('fixture 3: (0,)', solve(*(0,)), 1)
check('fixture 4: (-1,)', solve(*(-1,)), 1)
check('fixture 5: (8,)', solve(*(8,)), 5)
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
fixture 1: (-8,)54Failed
fixture 2: (7,)44Passed
fixture 3: (0,)11Passed
fixture 4: (-1,)21Failed
fixture 5: (8,)55Passed

SHA-256 / fbb83a716ac3ab60101c707cea810404b4ee88c72bc194abfa54e06a35d1b516

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR

N = 1
observations = []
def solve(n):
    return max(1, abs(n).bit_length())
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (-8,)', solve(*(-8,)), 4)
check('fixture 2: (7,)', solve(*(7,)), 4)
check('fixture 3: (0,)', solve(*(0,)), 1)
check('fixture 4: (-1,)', solve(*(-1,)), 1)
check('fixture 5: (8,)', solve(*(8,)), 5)
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
fixture 1: (-8,)44Passed
fixture 2: (7,)34Failed
fixture 3: (0,)11Passed
fixture 4: (-1,)11Passed
fixture 5: (8,)45Failed

SHA-256 / 0a64dea924f9222a5077230a5a904e85476567c555f5a8eb5799994ec5620703

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR

N = 1
observations = []
def solve(n):
    return max(1, (n if n >= 0 else ~n).bit_length()+1)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (-8,)', solve(*(-8,)), 4)
check('fixture 2: (7,)', solve(*(7,)), 4)
check('fixture 3: (0,)', solve(*(0,)), 1)
check('fixture 4: (-1,)', solve(*(-1,)), 1)
check('fixture 5: (8,)', solve(*(8,)), 5)
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
fixture 1: (-8,)44Passed
fixture 2: (7,)44Passed
fixture 3: (0,)11Passed
fixture 4: (-1,)11Passed
fixture 5: (8,)55Passed

SHA-256 / 00dd1d8fad02f1196b7044080dcf3feefea8e90d37dd7d4b40a6658a877fb897

Verification & scope

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

Case digest / 741a57c58979172ecd5cf3d28c08c510075af88036d0916982e455ac98ed7c8a