rho.php 947 B

12345678910111213141516171819202122232425262728293031
  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. if (!function_exists(__NAMESPACE__ . '\\rho')) {
  19. function rho($complex): float
  20. {
  21. $complex = Complex::validateComplexArgument($complex);
  22. return \sqrt(
  23. ($complex->getReal() * $complex->getReal()) +
  24. ($complex->getImaginary() * $complex->getImaginary())
  25. );
  26. }
  27. }