18 if (!function_exists(__NAMESPACE__ .
'\\divideby')) {
19 function divideby(...$complexValues):
Complex 21 if (count($complexValues) < 2) {
22 throw new \Exception(
'This function requires at least 2 arguments');
25 $base = array_shift($complexValues);
28 foreach ($complexValues as $complex) {
29 $complex = Complex::validateComplexArgument($complex);
31 if (
$result->isComplex() && $complex->isComplex() &&
32 $result->getSuffix() !== $complex->getSuffix()) {
35 if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
36 throw new \InvalidArgumentException(
'Division by zero');
39 $delta1 = (
$result->getReal() * $complex->getReal()) +
40 (
$result->getImaginary() * $complex->getImaginary());
41 $delta2 = (
$result->getImaginary() * $complex->getReal()) -
42 (
$result->getReal() * $complex->getImaginary());
43 $delta3 = ($complex->getReal() * $complex->getReal()) +
44 ($complex->getImaginary() * $complex->getImaginary());
46 $real = $delta1 / $delta3;
47 $imaginary = $delta2 / $delta3;
52 ($imaginary == 0.0) ? null : max(
$result->getSuffix(), $complex->getSuffix())