JavaScript Tutorial JavaScript Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

JavaScript - Math.imul() Method



The JavaScript Math.imul() method returns the result of the C-like 32-bit multiplication of the two parameters.

Syntax

Math.imul(x, y);

Parameters

x Specify the first number.
y Specify the second number.

Return Value

Returns the result of the C-like 32-bit multiplication of the given arguments.

Example:

The example below shows the usage of Math.imul() method.

var txt;

txt = "Math.imul(10, 5) = " + Math.imul(10, 5) + "<br>";
txt = txt + "Math.imul(-4, 8) = " + Math.imul(-4, 8) + "<br>";
txt = txt + "Math.imul(-7, -4) = " + Math.imul(-7, -4) + "<br>";
txt = txt + "Math.imul(0xffffffff, 3) = " + Math.imul(0xffffffff, 3) + "<br>";
txt = txt + "Math.imul(0xfffffffe, 3) = " + Math.imul(0xfffffffe, 3) + "<br>";

The output (value of txt) after running above script will be:

Math.imul(10, 5) = 50
Math.imul(-4, 8) = -32
Math.imul(-7, -4) = 28
Math.imul(0xffffffff, 3) = -3
Math.imul(0xfffffffe, 3) = -6

❮ JavaScript - Math Object

5