20if (!function_exists(__NAMESPACE__ . 
'\\pow')) {
 
   21    function pow($complex, $power): Complex
 
   23        $complex = Complex::validateComplexArgument($complex);
 
   25        if (!is_numeric($power)) {
 
   26            throw new Exception(
'Power argument must be a real number');
 
   29        if ($complex->getImaginary() == 0.0 && $complex->getReal() >= 0.0) {
 
   30            return new Complex(\pow($complex->getReal(), $power));
 
   33        $rValue = \sqrt(($complex->getReal() * $complex->getReal()) + ($complex->getImaginary() * $complex->getImaginary()));
 
   34        $rPower = \pow($rValue, $power);
 
   35        $theta = $complex->argument() * $power;
 
   37            return new Complex(1);
 
   40        return new Complex($rPower * \cos($theta), $rPower * \sin($theta), $complex->getSuffix());
 
An exception for terminatinating execution or to throw for unit testing.