Skip to content

Commit 600eaa9

Browse files
committed
bn: fix iaddn sign issue. see indutny/bn.js#216.
1 parent 8b42737 commit 600eaa9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/js/bn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class BN {
186186

187187
// Possible sign change.
188188
if (this.negative !== 0) {
189-
if (this.length === 1 && (this.words[0] | 0) < num) {
189+
if (this.length === 1 && (this.words[0] | 0) <= num) {
190190
this.words[0] = num - (this.words[0] | 0);
191191
this.negative = 0;
192192
return this;

test/bn-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ describe('BN.js', function() {
411411
new BN(0).iaddn(0x4000000);
412412
});
413413
});
414+
415+
it('should reset sign if value equal to value in instance', function () {
416+
const a = new BN(-1);
417+
assert.equal(a.addn(1).toString(), '0');
418+
});
414419
});
415420

416421
describe('.sub()', () => {

0 commit comments

Comments
 (0)