Search code examples
javascript32-bit

Javascript - How to squared a number?


Using the javascript function

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

When given the number 4294967296 the function returns 18446744073709552000 is returned

Everyone knows the real answer is 18446744073709551616 :-)

I guess this is to to with rounding on my 32-bit machine. However, would this script give the right answer on a 64 bit machine? Has anyone tried this?


Solution

  • ChrisV- see this post. Also it easier for people to evaluate your question by typing the following JavaScript directly into the browser URL textbox:

    javascript:4294967296*4294967296