February 2018
Intermediate to advanced
298 pages
8h 22m
English
The Math.imul() function takes two numbers as 32-bit integers and multiplies them. It returns the lower 32 bits of the result. This is the only native way to do 32-bit integer multiplication in JavaScript. Here is an example to demonstrate this:
console.log(Math.imul(590, 5000000)); //32-bit integer multiplicationconsole.log(590 * 5000000); //64-bit floating-point multiplication
The output is as follows:
-13449672962950000000
Here, when multiplication was done, it produced a number so large it couldn't be stored in 32 bits; therefore, the lower bits were lost.
Read now
Unlock full access