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

BigInt support?

Open bpierre opened this issue 7 years ago • 6 comments

I was wondering if there was any plan to support BigInt when available in the environment?

https://developers.google.com/web/updates/2018/05/bigint

Edit (08-2023): I made this library which I now use for dapps: https://github.com/bpierre/dnum

bpierre avatar Oct 05 '18 16:10 bpierre

Really important!

douglasb99 avatar Dec 27 '19 10:12 douglasb99

What you like to see as BigInt support? Accept BigInt in constructor/methods?

fanatid avatar Dec 27 '19 15:12 fanatid

Basically that or something similar. BigInt is becoming popular. A library I am writing I would like to support it for public methods as a dataype. Internally we use your library and it would be nice if it was super easy to convert between the two so supporting it in the constructor would be useful, or some static method to construct a BN from a BigInt would be great. To BigInt methods would also be very useful.

douglasb99 avatar Dec 27 '19 20:12 douglasb99

What about duplicate the library API with BigInt, there is no need to have all the code for operations if you can use native JS operators like add can be just +. It would be awesome to import this thinner library if BigInt have native support.

jcubic avatar Apr 18 '20 07:04 jcubic

@jcubic I reimplemented all the methods using BigInt keeping the same API https://github.com/alexandrius/bn.js-bigint

Major benefits are creating instances and stringifying them, other than that I wouldn't suggest migrating. Here's the benchmark results: https://github.com/alexandrius/bn.js-bigint/blob/master/bench.txt

alexandrius avatar Aug 10 '23 14:08 alexandrius