JavaScript | 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 degrade if the Math.imul() function is used with normal floating point variables allowed in JavaScript.
Syntax:
Math.imul(Value1, Value2);
Parameters: This function accepts two parameters Value1 and Value2 which represents two numbers to be multiplied.
Return Value: The Math.imul() function returns the result of the C-like 32-bit multiplication of the given arguments.
Examples:
Input : Math.imul(3, 4)
Output : 12
Input : Math.imul(-3, -4)
Output : 12
Input : Math.imul(0, 4)
Output : 0
Below programs illustrate the Math.imul() function in JavaScript:
- When two positive numbers are passed as parameters:
<scripttype="text/javascript">document.write(Math.imul(3, 4));</script>chevron_rightfilter_noneOutput:
12
- When both the numbers(of opposite sign) are passed as parameters:
<scripttype="text/javascript">document.write(Math.imul(0xfffffffe, 4));</script>chevron_rightfilter_noneOutput:
-8
- When two negative numbers are passed as parameters:
<scripttype="text/javascript">document.write(Math.imul(-3, -4));</script>chevron_rightfilter_noneOutput:
12
- When one of the parameter passed is a zero:
<scripttype="text/javascript">document.write(Math.imul(0, 4));</script>chevron_rightfilter_noneOutput:
0
Recommended Posts:
- JavaScript | Function Parameters
- JavaScript | Array.of() function
- JavaScript | Math.pow( ) Function
- JavaScript | Function Definitions
- JavaScript | Function Call
- JavaScript | Function Apply
- JavaScript | Math.E() function
- Javascript | Number() Function
- JavaScript | String() Function
- JavaScript | Array every() function
- JavaScript | Function Invocation
- JavaScript | toFixed( ) Function
- JavaScript | toPrecision( ) Function
- JavaScript | Array some() function
- JavaScript | Math.abs( ) function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



