酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acos.php 1.0 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex acos() 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 cosine of a complex number.
  12. *
  13. * @param Complex|mixed $complex Complex number or a numeric value.
  14. * @return Complex The inverse cosine of the complex argument.
  15. * @throws Exception If argument isn't a valid real or complex number.
  16. */
  17. function acos($complex)
  18. {
  19. $complex = Complex::validateComplexArgument($complex);
  20. $square = clone $complex;
  21. $square = multiply($square, $complex);
  22. $invsqrt = new Complex(1.0);
  23. $invsqrt = subtract($invsqrt, $square);
  24. $invsqrt = sqrt($invsqrt);
  25. $adjust = new Complex(
  26. $complex->getReal() - $invsqrt->getImaginary(),
  27. $complex->getImaginary() + $invsqrt->getReal()
  28. );
  29. $log = ln($adjust);
  30. return new Complex(
  31. $log->getImaginary(),
  32. -1 * $log->getReal()
  33. );
  34. }