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 degrades 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:
- Example 1: When two positive numbers are passed as parameters.
<scripttype="text/javascript">document.write(Math.imul(3, 4));</script>chevron_rightfilter_noneOutput:
12
- Example 2: 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
- Example 3: When two negative numbers are passed as parameters.
<scripttype="text/javascript">document.write(Math.imul(-3, -4));</script>chevron_rightfilter_noneOutput:
12
- Example 4: When one of the parameter passed is a zero.
<scripttype="text/javascript">document.write(Math.imul(0, 4));</script>chevron_rightfilter_noneOutput:
0
Supported Browsers: The browsers supported by JavaScript Math.imul( ) function are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- JavaScript | Function binding
- JavaScript | Function Parameters
- JavaScript | toExponential() Function
- JavaScript | Math.pow( ) Function
- JavaScript | Function Definitions
- How to override a JavaScript function ?
- JavaScript | String() Function
- JavaScript | Function Apply
- JavaScript | Array.of() function
- JavaScript | Array every() function
- JavaScript | Symbol.for() function
- JavaScript | Math.E() function
- Javascript | Number() Function
- JavaScript | toPrecision( ) 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.



