Skip to content

Commit 6d72f52

Browse files
committed
Properly implement unsigned conversion
1 parent f764f90 commit 6d72f52

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ function createNumberConversion(bitLength, typeOpts) {
6161

6262
if (!typeOpts.unsigned && x >= moduloBound) {
6363
return x - moduloVal;
64+
} else if (typeOpts.unsigned) {
65+
if (x < 0) {
66+
x += moduloVal;
67+
} else if (x === -0) { // don't return negative zero
68+
return 0;
69+
}
6470
}
6571

6672
return x;

0 commit comments

Comments
 (0)