bn.js icon indicating copy to clipboard operation
bn.js copied to clipboard

Wrong `cmpn` result

Open devDesu opened this issue 3 years ago • 1 comments

Version: 5.2.0 Node version: v17.5.0

let x = new BN(9000000000);
assert.equal(x.gten(100000000000), false); // error!

I've checked cmpn function and it seems that it's the source of the problem because x.cmpn(100000000000) returns 1 which means that A (9000000000) > B (100000000000)

This works fine

let x = new BN(9000000000);
assert.equal(x.gte(new BN(100000000000)), false); // ok

devDesu avatar May 03 '22 10:05 devDesu

Thanks. Probably we need to move this assertion before if. https://github.com/indutny/bn.js/blob/db57519421f0c47c9f68c05fa6fc12273dcca2c2/lib/bn.js#L2854

Currently, I'd recommend using BigInt instead of bn.js.

fanatid avatar May 03 '22 11:05 fanatid