diff --git a/lib/bn.js b/lib/bn.js index 0854c1c..bfd1916 100644 --- a/lib/bn.js +++ b/lib/bn.js @@ -2160,7 +2160,7 @@ // 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; diff --git a/test/arithmetic-test.js b/test/arithmetic-test.js index 67956ff..e2b657e 100644 --- a/test/arithmetic-test.js +++ b/test/arithmetic-test.js @@ -83,6 +83,11 @@ describe('BN.js/Arithmetic', function () { new BN(0).iaddn(0x4000000); }, /^Error: Assertion failed$/); }); + + it('should reset sign if value equal to value in instance', function () { + var a = new BN(-1); + assert.equal(a.addn(1).toString(), '0'); + }); }); describe('.sub()', function () {