ln.php 963 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex ln() 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 natural logarithm of a complex number.
  12. *
  13. * @param Complex|mixed $complex Complex number or a numeric value.
  14. * @return Complex The natural logarithm of the complex argument.
  15. * @throws Exception If argument isn't a valid real or complex number.
  16. * @throws \InvalidArgumentException If the real and the imaginary parts are both zero
  17. */
  18. function ln($complex)
  19. {
  20. $complex = Complex::validateComplexArgument($complex);
  21. if (($complex->getReal() == 0.0) && ($complex->getImaginary() == 0.0)) {
  22. throw new \InvalidArgumentException();
  23. }
  24. return new Complex(
  25. \log(rho($complex)),
  26. theta($complex),
  27. $complex->getSuffix()
  28. );
  29. }