Guido van Rossum | 57b1822 | 1996-08-29 18:10:41 +0000 | [diff] [blame] | 1 | /* hypot() replacement */ |
2 | |||||
Martin v. Löwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 3 | #include "pyconfig.h" |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 4 | #include "pyport.h" |
Guido van Rossum | 57b1822 | 1996-08-29 18:10:41 +0000 | [diff] [blame] | 5 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 6 | double hypot(double x, double y) |
Guido van Rossum | 57b1822 | 1996-08-29 18:10:41 +0000 | [diff] [blame] | 7 | { |
8 | double yx; | ||||
9 | |||||
10 | x = fabs(x); | ||||
11 | y = fabs(y); | ||||
12 | if (x < y) { | ||||
13 | double temp = x; | ||||
14 | x = y; | ||||
15 | y = temp; | ||||
16 | } | ||||
17 | if (x == 0.) | ||||
18 | return 0.; | ||||
19 | else { | ||||
20 | yx = y/x; | ||||
21 | return x*sqrt(1.+yx*yx); | ||||
22 | } | ||||
23 | } |