Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Math.imul() Function

Improve Article
Save Article
Like Article
  • Last Updated : 30 Dec, 2022
Improve Article
Save Article
Like Article

The Javascript 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 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() function is used with normal floating-point variables allowed in JavaScript.

Syntax:

Math.imul(Value1, Value2);

Parameters: This function accepts two parameters 

  • Value1, 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.

Below programs illustrate the Math.imul() function in JavaScript:

Example 1: When two positive numbers are passed as parameters. 

Javascript




<script type="text/javascript">
    console.log(Math.imul(3, 4));
</script>


Output:

12

Example 2: When both the numbers(of opposite sign) are passed as parameters. 

Javascript




<script type="text/javascript">
    console.log(Math.imul(0xfffffffe, 4));
</script>


Output:

-8

Example 3: When two negative numbers are passed as parameters. 

Javascript




<script type="text/javascript">
    console.log(Math.imul(-3, -4));
</script>


Output:

12

Example 4: When one of the parameters passed is a zero. 

Javascript




<script type="text/javascript">
    console.log(Math.imul(0, 4));
</script>


Output:

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!