You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
floor_int built its staircase via piecewise_linear, which sums slope-change
ReLUs Σ ±s·ReLU(x−b_i) in one linear projection. For a tall staircase at large
x this is catastrophic: each term is ~s·x and the fp32 partial sums overflow
2^24 (16.7M) so the +/- terms cancel into garbage. floor_int(40000.4, [0,65535],
s=1000) returned 0.0 (true 40000); even [0,255] staircases lost ~1-2 units near
the top of the range, unstable to 1-ULP input changes.
Rebuild as a sum of bounded saturating steps:
floor(x) = min + Σ_k step_k, step_k = clamp(s·(x−k)+1, 0, W) = relu(t)−relu(t−W)
floor = min + n − Σ_k relu(1 − step_k).
Each step_k is a 2-term per-output difference (not a sum over all breakpoints),
so the final Σ accumulates only bounded [0,1] terms — partial sums never exceed
n. The step is clamped to [0, W] (not left unbounded), keeping the stage-1
intermediate small so it does not amplify upstream compiled noise (an unbounded
relu(t) intermediate broke the linear_bin_index compile-fidelity probe). W is
sized max(2, 8·ulp(s·n)) — 2 for the common small-range case, larger only as s·n
approaches 2^24, where relu(t)−relu(t−W) would otherwise collapse to 0. Exact at
any magnitude/sharpness AND compiled-precise. Cost: one extra MLP sublayer (two
chained ReLUs). ceil_int = −floor_int(−x) inherits the fix.
thermometer_floor_div shares the slope-change-sum structure but is correct for
its documented integer-inputs-only contract (verified exact on large integers) —
not reworked.
Tests: test_floor_int_wide_range_large_magnitude (s=10/1000 over [0,65535]),
test_floor_int_byte_range_exact_high_sharpness, test_ceil_int_wide_range; full
arithmetic_ops + resampling (compiled probe) + value_type suites green. Noise
re-measured (the [-5,10] distributions never probed the bug — see
numerical_noise_findings.md).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments