bn.js
bn.js copied to clipboard
Wrong `cmpn` result
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
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.