Maths.php 839 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @package JAMA
  4. *
  5. * Pythagorean Theorem:
  6. *
  7. * a = 3
  8. * b = 4
  9. * r = sqrt(square(a) + square(b))
  10. * r = 5
  11. *
  12. * r = sqrt(a^2 + b^2) without under/overflow.
  13. */
  14. function hypo($a, $b)
  15. {
  16. if (abs($a) > abs($b)) {
  17. $r = $b / $a;
  18. $r = abs($a) * sqrt(1 + $r * $r);
  19. } elseif ($b != 0) {
  20. $r = $a / $b;
  21. $r = abs($b) * sqrt(1 + $r * $r);
  22. } else {
  23. $r = 0.0;
  24. }
  25. return $r;
  26. } // function hypo()
  27. /**
  28. * Mike Bommarito's version.
  29. * Compute n-dimensional hyotheneuse.
  30. *
  31. function hypot() {
  32. $s = 0;
  33. foreach (func_get_args() as $d) {
  34. if (is_numeric($d)) {
  35. $s += pow($d, 2);
  36. } else {
  37. throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
  38. }
  39. }
  40. return sqrt($s);
  41. }
  42. */