ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
pow.php
Go to the documentation of this file.
1<?php
2
10namespace Complex;
11
20if (!function_exists(__NAMESPACE__ . '\\pow')) {
21 function pow($complex, $power): Complex
22 {
23 $complex = Complex::validateComplexArgument($complex);
24
25 if (!is_numeric($power)) {
26 throw new Exception('Power argument must be a real number');
27 }
28
29 if ($complex->getImaginary() == 0.0 && $complex->getReal() >= 0.0) {
30 return new Complex(\pow($complex->getReal(), $power));
31 }
32
33 $rValue = \sqrt(($complex->getReal() * $complex->getReal()) + ($complex->getImaginary() * $complex->getImaginary()));
34 $rPower = \pow($rValue, $power);
35 $theta = $complex->argument() * $power;
36 if ($theta == 0) {
37 return new Complex(1);
38 }
39
40 return new Complex($rPower * \cos($theta), $rPower * \sin($theta), $complex->getSuffix());
41 }
42}
An exception for terminatinating execution or to throw for unit testing.