JavaScript: Math imul() function
This JavaScript tutorial explains how to use the math function called imul() with syntax and examples.
Description
In JavaScript, imul() is a function ("integer multiplication") that is used to perform 32-bit integer multiplication of two values and return the result. Because the imul() function is a static function of the Math object, it must be invoked through the placeholder object called Math.
Syntax
In JavaScript, the syntax for the imul() function is:
Math.imul(number1, number2);
Parameters or Arguments
- number1
- The first number to multiply.
- number2
- The second number to multiply.
Returns
The imul() function returns the result of two values that are multiplied together using 32-bit multiplication.
Note
- Math is a placeholder object that contains mathematical functions and constants of which imul() is one of these functions.
Example
Let's take a look at an example of how to use the imul() function in JavaScript.
For example:
console.log(Math.imul(2, 5));
console.log(Math.imul(-18, 6));
In this example, we have invoked the imul() function using the Math class.
We have written the output of the imul() function to the web browser console log, for demonstration purposes, to show what the imul() function returns.
The following will be output to the web browser console log:
10 -108
In this example, the first output to the console log returned 10 which is the result of 2 multiplied by 5 using 32-bit multiplication.
The second output to the console log returned -108 which is the result of -18 multiplied by 6 using 32-bit multiplication.
Advertisements