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

Support BigInt

Open betamos opened this issue 6 years ago • 2 comments

The builtin BigInt type is supported in many browsers and in NodeJS (such as the fs.stat API).

Current behavior is particularly spurious and can cause bugs: Long.fromValue(55n) results in 0

Please consider adding support for BigInt or if you'd rather accept contributions I'd be happy to take a look.

betamos avatar Oct 27 '19 23:10 betamos

I maybe think it should rather be suggested that BigInt is used instead of long?

jimmywarting avatar Jun 21 '22 22:06 jimmywarting

In longfn I implemented BigInt for the from/toBytes methods:

toBigInt(fromBytesLE(bytes,...))

But independently of that, I think it is a good idea to have a int64 implementation handy when needing to be computationally compatible to other implementations. With BigInt buffer overflows don't exist...

martinheidegger avatar Jun 22 '22 12:06 martinheidegger