asin.php 1.0 KB

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