UNPKG

@rayyamhk/complex

Version:

A lightweight and easy-to-use library for you to manipulate complex numbers

23 lines (20 loc) 591 B
"use strict"; /** * Calculates the product of two Complex Number. * @memberof Complex * @static * @param {Complex} num1 - The Complex Number on the left of '*' operator. * @param {Complex} num2 - The Complex Number on the right of '*' operator. * @returns {Complex} The product of two Complex Numbers */ function multiply(num1, num2) { if (!(num1 instanceof this) || !(num2 instanceof this)) { return this.NaN; } var a = num1.re; var b = num1.im; var c = num2.re; var d = num2.im; return new this(a * c - b * d, a * d + b * c); } module.exports = multiply;