blob: 755d0c31c8ef93fb4932d153b838bea5b7d63a3d [file] [log] [blame]
Guido van Rossum57b18221996-08-29 18:10:41 +00001/* hypot() replacement */
2
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +00003#include "pyconfig.h"
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +00004#include "pyport.h"
Guido van Rossum57b18221996-08-29 18:10:41 +00005
Thomas Woutersf70ef4f2000-07-22 18:47:25 +00006double hypot(double x, double y)
Guido van Rossum57b18221996-08-29 18:10:41 +00007{
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}