The Javascript Math.imul() method 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() method is used with normal floating type variables in JavaScript then there will be a degradation 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() method is used with normal floating-point variables allowed in JavaScript.
Syntax:
Math.imul(Value1, Value2);
Parameters: This method accepts two parameters
- Value1, Value2: Which represents two numbers to be multiplied.
Return Value: The Math.imul() method returns the result of the C-like 32-bit multiplication of the given arguments.
Below programs illustrate the Math.imul() method in JavaScript:
Example 1: When two positive numbers are passed as parameters.
Javascript
console.log(Math.imul(3, 4)); |
12
Example 2: When both the numbers(of opposite sign) are passed as parameters.
Javascript
console.log(Math.imul(0xfffffffe, 4)); |
-8
Example 3: When two negative numbers are passed as parameters.
Javascript
console.log(Math.imul(-3, -4)); |
12
Example 4: When one of the parameters passed is a zero.
Javascript
console.log(Math.imul(0, 4)); |
0
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Supported Browsers:
- Google Chrome 1 and above
- Internet Explorer 3 and above
- Firefox 1 and above
- Opera 3 and above
- Safari 1 and above