Repository navigation
fix(base): classify F32.hypot overflow at the rounding boundary - #2202
Draft
sebastian-griego wants to merge 1 commit into
Draft
sebastian-griego wants to merge 1 commit into
sebastian-griego wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
F32.hypotcan return infinity for a result that rounds to the largest finite F32. It can also return the largest finite F32 for a result that rounds to infinity. Both occur on9c586f09in the default CLI, native C, Bun, and Node. This follows #1515.2.22e38, 2.578916e387f8000007f7fffff3.4028235e38, 1.0e357f7fffff7f800000Draft because of a performance regression. The numerical checks pass. A focused loop of ordinary calls is 2.71 times slower on Node. The measurements below make that cost explicit for review.
The scaled squares lose information near the overflow boundary. For inputs whose maximum magnitude reaches 2^127, the fix checks the original significands with existing 48-bit
Natoperations. The exact check selects infinity or a finite result from the scaled formula.For the relevant finite inputs, write
hi = A*2^104andlo = B*2^(104-d). The overflow midpoint is(2^24 - 1/2)*2^104. SetD = (2^24-A)*(2^24+A) - 2^24andP = 4^d. Overflow occurs whenfloor((B^2 + floor(3P/4))/P) > D. This also handles an exact midpoint. Ford >= 12, overflow is impossible, and clamping d to 12 gives the same decision. All integer intermediates fit below 2^48.The regressions cover both reported cases, signs, argument order, an exact midpoint and its adjacent inputs, large exponent gaps, zero, infinity, and NaN. The GPU test adds parallel checks at the boundary.
Validation
WONTFIX.txt.Performance on Apple M5 Max, macOS 26.6.2, Apple clang 21, Bun 1.3.14, and Node 24.15.0. These are median process times from nine alternating pairs after one warmup.
The ordinary loop uses runtime-generated coordinates and returns the same checksum. On Node, the new cold branch prevents loop peeling in this benchmark. The generated loop then boxes its accumulator and seed on each iteration. With loop peeling disabled for diagnosis, both versions take about 374–380 ms. Several helper arrangements retained this cost. The existing runtime benchmarks contain no
F32.hypotcalls.The full cluster suite and CUDA were not run.