atan.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex atan() function
  5. *
  6. * @copyright Copyright (c) 2013-2018 Mark Baker (https://github.com/MarkBaker/PHPComplex)
  7. * @license https://opensource.org/licenses/MIT MIT
  8. */
  9. namespace Complex;
  10. //include_once 'Math/Complex.php';
  11. //include_once 'Math/ComplexOp.php';
  12. /**
  13. * Returns the inverse tangent of a complex number.
  14. *
  15. * @param Complex|mixed $complex Complex number or a numeric value.
  16. * @return Complex The inverse tangent of the complex argument.
  17. * @throws Exception If argument isn't a valid real or complex number.
  18. * @throws \InvalidArgumentException If function would result in a division by zero
  19. */
  20. function atan($complex)
  21. {
  22. $complex = Complex::validateComplexArgument($complex);
  23. if ($complex->isReal()) {
  24. return new Complex(\atan($complex->getReal()));
  25. }
  26. $t1Value = new Complex(-1 * $complex->getImaginary(), $complex->getReal());
  27. $uValue = new Complex(1, 0);
  28. $d1Value = clone $uValue;
  29. $d1Value = subtract($d1Value, $t1Value);
  30. $d2Value = add($t1Value, $uValue);
  31. $uResult = $d1Value->divideBy($d2Value);
  32. $uResult = ln($uResult);
  33. return new Complex(
  34. (($uResult->getImaginary() == M_PI) ? -M_PI : $uResult->getImaginary()) * -0.5,
  35. $uResult->getReal() * 0.5,
  36. $complex->getSuffix()
  37. );
  38. }