Javascript - How to build a number?

Using javascript function

function squareIt(number) { return number * number; } 

When specifying number 4294967296, the return function 18446744073709552000 is returned

Everyone knows that the real answer is: 18446744073709551616 :-)

I assume this is due to rounding on my 32 bit machine. However, this script will give the correct answer on a 64-bit machine? Has anyone tried this?

+4
source share
4 answers

ChrisV- see this post . It’s also easier for people to rate your question by entering the following JavaScript directly into the browser URL text box:

 javascript:4294967296*4294967296 
+3
source

Javascript uses 64-bit floating-point arithmetic inside for numerical calculations - the results you see are a reflection of this and will occur regardless of the underlying architecture.

+1
source

how about this

 function squareIt(number){ return Math.pow(number,2) } 
+1
source

Here is another example based on BigInteger.js .

 alert(bigInt(4294967296).square()); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/big-integer/1.6.40/BigInteger.min.js"></script> 
0
source

All Articles