Math.imul( ) Function

The Math.imul() function in JavaScript is used to calculate the result of the 32-bit multiplication of the two integers passed as parameters to it. Math.imul() allows for 32-bit integer multiplication with C-like semantics. If the Math.imul() function is used with normal floating type variables in JavaScript then there will be a degrade in performance because of the conversion of floats to ints before multiplication. The overhead of conversion results in a performance degrades if the Math.imul() function is used with normal floating-point variables allowed in JavaScript.

Input  : Math.imul(3, 4)
Output : 12
     
Input  : Math.imul(-3, -4)
Output : 12

Input  : Math.imul(0, 4)
Output : 0

Warning:

The following line does shows the right results, it is not 100% sure that result is the expected:

console.log(Math.imul(-5, 2.5432));
// Output -10
// It should be -12.716

Last updated