23

Anyone have any suggestions on how to perform arithmetic on 64bit integers in Node.js? The node-int64 package doesn't seem to support that.

user1502301
  • 545
  • 1
  • 4
  • 15
  • 2
    I think you'll find this useful: http://stackoverflow.com/questions/9643626/javascript-cant-handle-64-bit-integers-can-it – Gabi Purcaru Jun 04 '14 at 12:46

2 Answers2

28

Javascript does not support 64 bit integers, because the native number type is a 64-bit double, giving only 53 bits of integer range.

You can create arrays of 32-bit numbers (i.e. Uint32Array) but if there were a 64-bit version of those there'd be no way to copy values from it into standalone variables.

There are some modules around to provide 64bit integer support:

Maybe your problem can be solved using one of those libraries.

Andy
  • 6,965
  • 4
  • 49
  • 60
Sarath
  • 8,762
  • 11
  • 46
  • 80
5

As of v10.4.0 NodeJS supports the BigInt type natively (see MDN BigInt docs). These support arithmetic operations too.

Alex Tullenhoff
  • 330
  • 4
  • 5