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