isComplex() && $complex->isComplex() && $result->getSuffix() !== $complex->getSuffix()) { throw new Exception('Suffix Mismatch'); } if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) { throw new \InvalidArgumentException('Division by zero'); } $delta1 = ($result->getReal() * $complex->getReal()) + ($result->getImaginary() * $complex->getImaginary()); $delta2 = ($result->getImaginary() * $complex->getReal()) - ($result->getReal() * $complex->getImaginary()); $delta3 = ($complex->getReal() * $complex->getReal()) + ($complex->getImaginary() * $complex->getImaginary()); $real = $delta1 / $delta3; $imaginary = $delta2 / $delta3; $result = new Complex( $real, $imaginary, ($imaginary == 0.0) ? null : max($result->getSuffix(), $complex->getSuffix()) ); } return $result; }