Skip to content

Commit

Permalink
bn: fix iaddn sign issue. see indutny/bn.js#216.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Mar 28, 2019
1 parent 8b42737 commit 600eaa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/js/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class BN {

// Possible sign change.
if (this.negative !== 0) {
if (this.length === 1 && (this.words[0] | 0) < num) {
if (this.length === 1 && (this.words[0] | 0) <= num) {
this.words[0] = num - (this.words[0] | 0);
this.negative = 0;
return this;
Expand Down
5 changes: 5 additions & 0 deletions test/bn-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ describe('BN.js', function() {
new BN(0).iaddn(0x4000000);
});
});

it('should reset sign if value equal to value in instance', function () {
const a = new BN(-1);
assert.equal(a.addn(1).toString(), '0');
});
});

describe('.sub()', () => {
Expand Down

0 comments on commit 600eaa9

Please sign in to comment.