source: sourcecode/application/libraries/PHPExcel/Shared/JAMA/utils/Maths.php @ 1

Last change on this file since 1 was 1, checked in by dungnv, 11 years ago
File size: 711 bytes
Line 
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 */
14function 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
28/**
29 *      Mike Bommarito's version.
30 *      Compute n-dimensional hyotheneuse.
31 *
32function hypot() {
33        $s = 0;
34        foreach (func_get_args() as $d) {
35                if (is_numeric($d)) {
36                        $s += pow($d, 2);
37                } else {
38                        throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException));
39                }
40        }
41        return sqrt($s);
42}
43*/
Note: See TracBrowser for help on using the repository browser.