lib: fix evenRound sign for fractional values in (-1, 1)#62837
Open
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
Open
lib: fix evenRound sign for fractional values in (-1, 1)#62837deepview-autofix wants to merge 1 commit intonodejs:mainfrom
evenRound sign for fractional values in (-1, 1)#62837deepview-autofix wants to merge 1 commit intonodejs:mainfrom
Conversation
`evenRound` derived the rounding direction from `MathSign(i)` where `i = integerPart(x)`. For any `x` whose truncated integer part is zero (e.g. `0.7`, `-0.7`), `sign` was `0`, so the non-halfway branch returned `i + sign === 0` instead of rounding away from zero. This produced incorrect `[Clamp]` WebIDL integer conversions for fractional inputs in `(-1, 0) ∪ (0, 1)` that are not exactly `±0.5`, observable e.g. via `new Blob([Uint8Array.of(1,2,3)]).slice(-0.9999999)` returning the whole blob instead of a 1-byte slice. Use `MathSign(x)` so the rounding direction follows the sign of the original value. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com> Co-Authored-By: Nikita Skovoroda <chalkerx@gmail.com> Signed-off-by: Nikita Skovoroda <chalkerx@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62837 +/- ##
=======================================
Coverage 89.62% 89.62%
=======================================
Files 706 706
Lines 219136 219136
Branches 41987 41981 -6
=======================================
+ Hits 196404 196410 +6
- Misses 14611 14614 +3
+ Partials 8121 8112 -9
🚀 New features to boost your workflow:
|
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.


evenRoundderived the rounding direction fromMathSign(i)wherei = integerPart(x). For anyxwhose truncated integer part is zero (e.g.0.7,-0.7),signwas0, so the non-halfway branch returnedi + sign === 0instead of rounding away from zero.This produced incorrect
[Clamp]WebIDL integer conversions for fractional inputs in(-1, 0) ∪ (0, 1)that are not exactly±0.5Observable e.g. via
new Blob([Uint8Array.of(1,2,3)]).slice(-0.9999999)returning the whole blob instead of a 1-byte slice.Use
MathSign(x)so the rounding direction follows the sign of the original value.