1 #include <math.h> 2 /* 3 * sqrt(a^2 + b^2) 4 * (but carefully) 5 */ 6 7 double hypot(double a,double b)8hypot(double a, double b) 9 { 10 double t; 11 12 if(a < 0) 13 a = -a; 14 if(b < 0) 15 b = -b; 16 if(a > b) { 17 t = a; 18 a = b; 19 b = t; 20 } 21 if(b == 0) 22 return 0; 23 a /= b; 24 /* 25 * pathological overflow possible 26 * in the next line. 27 */ 28 return b * sqrt(1 + a*a); 29 } 30