Repository navigation
fix: correctly round subnormals in number/float16/base/to-word - #16511
Open
harsh-thakkar7 wants to merge 1 commit into
Open
harsh-thakkar7 wants to merge 1 commit into
harsh-thakkar7 wants to merge 1 commit into
Conversation
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
harsh-thakkar7
force-pushed
the
fix/16510-float16-subnormal
branch
from
November 5, 2026 19:22
f7f5974 to
3d3c4a8
Compare
This branch has not been deployed
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.
Resolves #16510
Description
Fixes subnormal rounding in
@stdlib/number/float16/base/to-wordat the 11-bit shift boundary. Whenshift === 11, the code previously took the wrong rounding branch and returned zero for values that should round to the smallest subnormal:toWord( 2.98038125038147e-8 )returned0x0000; now returns0x0001.toWord( -2.98038125038147e-8 )returned0x8000; now returns0x8001.The fix changes the branch condition from
shift < 11toshift <= 11, so the round bit is taken from the correct bit of the 11-bit mantissa. Values requiringshift > 11already return zero earlier via thef16Exponent < -10check.Regression tests cover the positive and negative rounding cases, the exact
2^-25tie, and values just below2^-24.Related Issues
number/float16/base/to-wordmis-rounds subnormals at the 11-bit shift boundary #16510Questions
No.
Other
The C/native path is unaffected: it returns the bits of an already encoded
stdlib_float16_t. The JS test suite passes (5,013 tests), and the result was cross-checked against nativeFloat16Array: 0 mismatches over a 50,000-value sweep around2^-25(previously ~25,007 mismatches).Checklist
@stdlib-js/reviewers