negative.php 781 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. *
  4. * Function code for the complex negative() 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 negative of a complex number.
  12. *
  13. * @param Complex|mixed $complex Complex number or a numeric value.
  14. * @return float The negative value of the complex argument.
  15. * @throws Exception If argument isn't a valid real or complex number.
  16. *
  17. * @see rho
  18. *
  19. */
  20. function negative($complex)
  21. {
  22. $complex = Complex::validateComplexArgument($complex);
  23. return new Complex(
  24. -1 * $complex->getReal(),
  25. -1 * $complex->getImaginary(),
  26. $complex->getSuffix()
  27. );
  28. }