+ 1

How to use 64-bit Integer in Javascript to avoid the overflow?

How to use 64-bit Integer in Javascript to avoid the overflow?

31st Jan 2021, 5:51 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
3 odpowiedzi
+ 4
XXX js has types, even if js variables are not typed ^^ anyway, js has no 'long' type... only float numbers (and internally 32 bits signed integer) wich impose integer upper limit at 2^53. however, modern js have BigInt object, wich could handle arbitrarily large integers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt ... or you could use TypedArray wich provide 64 bits models (float, int, uint) since your browser do support BigInt: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
31st Jan 2021, 7:46 PM
visph
visph - avatar
+ 2
visph yeah I meant to say that you can't 'specify' types for variables in JavaScript. And thanks for the additional info though. I didn't know JavaScript has BigInt too. I'll delete my answer because it's wrong👍
31st Jan 2021, 7:59 PM
XXX
XXX - avatar
0
Use "long" datatype for it
31st Jan 2021, 6:02 PM
Atul [Inactive]