Differences Between: [Versions 310 and 311] [Versions 39 and 311]
1 <?php 2 3 /** 4 * 5 * Function code for the complex division 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 * Divides two or more complex numbers 14 * 15 * @param array of string|integer|float|Complex $complexValues The numbers to divide 16 * @return Complex 17 */ 18 function divideinto(...$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 if ($result->getReal() == 0.0 && $result->getImaginary() == 0.0) { 35 throw new \InvalidArgumentException('Division by zero'); 36 } 37 38 $delta1 = ($complex->getReal() * $result->getReal()) + 39 ($complex->getImaginary() * $result->getImaginary()); 40 $delta2 = ($complex->getImaginary() * $result->getReal()) - 41 ($complex->getReal() * $result->getImaginary()); 42 $delta3 = ($result->getReal() * $result->getReal()) + 43 ($result->getImaginary() * $result->getImaginary()); 44 45 $real = $delta1 / $delta3; 46 $imaginary = $delta2 / $delta3; 47 48 $result = new Complex( 49 $real, 50 $imaginary, 51 ($imaginary == 0.0) ? null : max($result->getSuffix(), $complex->getSuffix()) 52 ); 53 } 54 55 return $result; 56 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body