acosh.php 920 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex acosh() 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 cosine of a complex number.
  12. *
  13. * @param Complex|mixed $complex Complex number or a numeric value.
  14. * @return Complex The inverse hyperbolic cosine of the complex argument.
  15. * @throws Exception If argument isn't a valid real or complex number.
  16. */
  17. function acosh($complex)
  18. {
  19. $complex = Complex::validateComplexArgument($complex);
  20. if ($complex->isReal() && ($complex->getReal() > 1)) {
  21. return new Complex(\acosh($complex->getReal()));
  22. }
  23. $acosh = acos($complex)
  24. ->reverse();
  25. if ($acosh->getReal() < 0.0) {
  26. $acosh = $acosh->invertReal();
  27. }
  28. return $acosh;
  29. }