a8d205c0bcf3bdf7d0fe56f3a648c50ec6ec452a.svn-base 711 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. if (abs($a) > abs($b)) {
  16. $r = $b / $a;
  17. $r = abs($a) * sqrt(1 + $r * $r);
  18. } elseif ($b != 0) {
  19. $r = $a / $b;
  20. $r = abs($b) * sqrt(1 + $r * $r);
  21. } else {
  22. $r = 0.0;
  23. }
  24. return $r;
  25. } // function hypo()
  26. /**
  27. * Mike Bommarito's version.
  28. * Compute n-dimensional hyotheneuse.
  29. *
  30. function hypot() {
  31. $s = 0;
  32. foreach (func_get_args() as $d) {
  33. if (is_numeric($d)) {
  34. $s += pow($d, 2);
  35. } else {
  36. throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException));
  37. }
  38. }
  39. return sqrt($s);
  40. }
  41. */