FAILURE MAP
← Case archive

FA-17131 / Floating-point arithmetic / Open access

Engineering notation uses exponent residue as a zero-based digit count · case 01

Engineering notation uses exponent residue as a zero-based digit count.

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

ROOT CAUSE

Engineering notation uses exponent residue as a zero-based digit count. The faulty expression is leading=adjusted-scale.

VERIFIED REPAIR

Apply the contract at this fault site using leading=adjusted-scale+1.

Unsuccessful approach: The attempted local correction leading=1 still violates the explicit regression fixtures.

Case contract

Render a finite decimal text after half-even rounding to precision, in scientific or engineering notation. Preserve coefficient trailing zeros; engineering exponent is a multiple of three with one to three integer digits. Zero is canonical coefficient zero with original sign and exponent zero.

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 decimal
from decimal import Decimal, Context, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_DOWN

N = 1
observations = []
def solve(text,precision,engineering):
    ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN)
    value=ctx.create_decimal(text)
    sign,digits,exponent=value.as_tuple()
    prefix='-' if sign else ''
    if value.is_zero(): return prefix+'0e0'
    coefficient=''.join(str(d) for d in digits)
    adjusted=len(coefficient)+exponent-1
    scale=(adjusted//3)*3 if engineering else adjusted
    leading=adjusted-scale
    coefficient=coefficient.ljust(leading,'0')
    mantissa=coefficient[:leading]
    if len(coefficient)>leading: mantissa+='.'+coefficient[leading:]
    return prefix+mantissa+'e'+str(scale)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('scientific carry', solve("999.5",3,False), "1.00e3")
check('engineering carry', solve("999.5",3,True), "1.00e3")
check('two integer digits', solve("12345",3,True), "12.3e3")
check('three integer digits', solve("123456",3,True), "123e3")
check('negative exponent', solve("0.01234",3,True), "12.3e-3")
check('scientific small', solve("0.01234",3,False), "1.23e-2")
check('padding', solve(str(N)+"e2",3,True), str(N)+"00e0")
check('negative coefficient', solve("-12345",3,False), "-1.23e4")
check('negative zero', solve("-0.00",3,False), "-0e0")
check('positive zero', solve("0.00",3,True), "0e0")
check('retained zeros', solve("1.200",4,False), "1.200e0")
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
scientific carry.100e31.00e3Failed
engineering carry.100e31.00e3Failed
two integer digits1.23e312.3e3Failed
three integer digits12.3e3123e3Failed
negative exponent1.23e-312.3e-3Failed
scientific small.123e-21.23e-2Failed
padding10e0100e0Failed
negative coefficient-.123e4-1.23e4Failed
negative zero-0e0-0e0Passed
positive zero0e00e0Passed
retained zeros.1200e01.200e0Failed

SHA-256 / feaf4403bb2a421e233aeff321c6c17cb75882ac760d2c41f74f8fdefd398778

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import decimal
from decimal import Decimal, Context, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_DOWN

N = 1
observations = []
def solve(text,precision,engineering):
    ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN)
    value=ctx.create_decimal(text)
    sign,digits,exponent=value.as_tuple()
    prefix='-' if sign else ''
    if value.is_zero(): return prefix+'0e0'
    coefficient=''.join(str(d) for d in digits)
    adjusted=len(coefficient)+exponent-1
    scale=(adjusted//3)*3 if engineering else adjusted
    leading=1
    coefficient=coefficient.ljust(leading,'0')
    mantissa=coefficient[:leading]
    if len(coefficient)>leading: mantissa+='.'+coefficient[leading:]
    return prefix+mantissa+'e'+str(scale)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('scientific carry', solve("999.5",3,False), "1.00e3")
check('engineering carry', solve("999.5",3,True), "1.00e3")
check('two integer digits', solve("12345",3,True), "12.3e3")
check('three integer digits', solve("123456",3,True), "123e3")
check('negative exponent', solve("0.01234",3,True), "12.3e-3")
check('scientific small', solve("0.01234",3,False), "1.23e-2")
check('padding', solve(str(N)+"e2",3,True), str(N)+"00e0")
check('negative coefficient', solve("-12345",3,False), "-1.23e4")
check('negative zero', solve("-0.00",3,False), "-0e0")
check('positive zero', solve("0.00",3,True), "0e0")
check('retained zeros', solve("1.200",4,False), "1.200e0")
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
scientific carry1.00e31.00e3Passed
engineering carry1.00e31.00e3Passed
two integer digits1.23e312.3e3Failed
three integer digits1.23e3123e3Failed
negative exponent1.23e-312.3e-3Failed
scientific small1.23e-21.23e-2Passed
padding1e0100e0Failed
negative coefficient-1.23e4-1.23e4Passed
negative zero-0e0-0e0Passed
positive zero0e00e0Passed
retained zeros1.200e01.200e0Passed

SHA-256 / 8c7f2e45f5f8157e1d746c7c90b48de77260ebaa73afa43f49528fd0b43cabfd

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import decimal
from decimal import Decimal, Context, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_DOWN

N = 1
observations = []
def solve(text,precision,engineering):
    ctx=Context(prec=precision,rounding=ROUND_HALF_EVEN)
    value=ctx.create_decimal(text)
    sign,digits,exponent=value.as_tuple()
    prefix='-' if sign else ''
    if value.is_zero(): return prefix+'0e0'
    coefficient=''.join(str(d) for d in digits)
    adjusted=len(coefficient)+exponent-1
    scale=(adjusted//3)*3 if engineering else adjusted
    leading=adjusted-scale+1
    coefficient=coefficient.ljust(leading,'0')
    mantissa=coefficient[:leading]
    if len(coefficient)>leading: mantissa+='.'+coefficient[leading:]
    return prefix+mantissa+'e'+str(scale)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('scientific carry', solve("999.5",3,False), "1.00e3")
check('engineering carry', solve("999.5",3,True), "1.00e3")
check('two integer digits', solve("12345",3,True), "12.3e3")
check('three integer digits', solve("123456",3,True), "123e3")
check('negative exponent', solve("0.01234",3,True), "12.3e-3")
check('scientific small', solve("0.01234",3,False), "1.23e-2")
check('padding', solve(str(N)+"e2",3,True), str(N)+"00e0")
check('negative coefficient', solve("-12345",3,False), "-1.23e4")
check('negative zero', solve("-0.00",3,False), "-0e0")
check('positive zero', solve("0.00",3,True), "0e0")
check('retained zeros', solve("1.200",4,False), "1.200e0")
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
scientific carry1.00e31.00e3Passed
engineering carry1.00e31.00e3Passed
two integer digits12.3e312.3e3Passed
three integer digits123e3123e3Passed
negative exponent12.3e-312.3e-3Passed
scientific small1.23e-21.23e-2Passed
padding100e0100e0Passed
negative coefficient-1.23e4-1.23e4Passed
negative zero-0e0-0e0Passed
positive zero0e00e0Passed
retained zeros1.200e01.200e0Passed

SHA-256 / c421a992a6fd42590fcb32069f1fa06ed719cb80eba3fc3f3045dd9c8cb32870

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

Case digest / ebcb2eab158770be4b79e62c67b309da6f272fd90c0fd3f0c93c68e5cf306f5c