rho.php 857 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex rho() 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 rho of a complex number.
  12. * This is the distance/radius from the centrepoint to the representation of the number in polar coordinates.
  13. *
  14. * @param Complex|mixed $complex Complex number or a numeric value.
  15. * @return float The rho value of the complex argument.
  16. * @throws Exception If argument isn't a valid real or complex number.
  17. */
  18. function rho($complex)
  19. {
  20. $complex = Complex::validateComplexArgument($complex);
  21. return \sqrt(
  22. ($complex->getReal() * $complex->getReal()) +
  23. ($complex->getImaginary() * $complex->getImaginary())
  24. );
  25. }