Differences Between: [Versions 310 and 311] [Versions 39 and 311]
1 <?php 2 3 /** 4 * 5 * Function code for the complex multiplication operation 6 * 7 * @copyright Copyright (c) 2013-2018 Mark Baker (https://github.com/MarkBaker/PHPComplex) 8 * @license https://opensource.org/licenses/MIT MIT 9 */ 10 namespace Complex; 11 12 /** 13 * Multiplies two or more complex numbers 14 * 15 * @param array of string|integer|float|Complex $complexValues The numbers to multiply 16 * @return Complex 17 */ 18 function multiply(...$complexValues): Complex 19 { 20 if (count($complexValues) < 2) { 21 throw new \Exception('This function requires at least 2 arguments'); 22 } 23 24 $base = array_shift($complexValues); 25 $result = clone Complex::validateComplexArgument($base); 26 27 foreach ($complexValues as $complex) { 28 $complex = Complex::validateComplexArgument($complex); 29 30 if ($result->isComplex() && $complex->isComplex() && 31 $result->getSuffix() !== $complex->getSuffix()) { 32 throw new Exception('Suffix Mismatch'); 33 } 34 35 $real = ($result->getReal() * $complex->getReal()) - 36 ($result->getImaginary() * $complex->getImaginary()); 37 $imaginary = ($result->getReal() * $complex->getImaginary()) + 38 ($result->getImaginary() * $complex->getReal()); 39 40 $result = new Complex( 41 $real, 42 $imaginary, 43 ($imaginary == 0.0) ? null : max($result->getSuffix(), $complex->getSuffix()) 44 ); 45 } 46 47 return $result; 48 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body