atanh.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex atanh() 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. /**
  11. * Returns the inverse hyperbolic tangent of a complex number.
  12. *
  13. * @param Complex|mixed $complex Complex number or a numeric value.
  14. * @return Complex The inverse hyperbolic tangent of the complex argument.
  15. * @throws Exception If argument isn't a valid real or complex number.
  16. */
  17. if (!function_exists(__NAMESPACE__ . '\\atanh')) {
  18. function atanh($complex): Complex
  19. {
  20. $complex = Complex::validateComplexArgument($complex);
  21. if ($complex->isReal()) {
  22. $real = $complex->getReal();
  23. if ($real >= -1.0 && $real <= 1.0) {
  24. return new Complex(\atanh($real));
  25. } else {
  26. return new Complex(\atanh(1 / $real), (($real < 0.0) ? M_PI_2 : -1 * M_PI_2));
  27. }
  28. }
  29. $iComplex = clone $complex;
  30. $iComplex = $iComplex->invertImaginary()
  31. ->reverse();
  32. return atan($iComplex)
  33. ->invertReal()
  34. ->reverse();
  35. }
  36. }