1 /* @(#)hypot.c 4.1 12/25/82 */ 2 3 /* 4 * sqrt(a^2 + b^2) 5 * (but carefully) 6 */ 7 8 double sqrt(); 9 double 10 hypot(a,b) 11 double a,b; 12 { 13 double t; 14 if(a<0) a = -a; 15 if(b<0) b = -b; 16 if(a > b) { 17 t = a; 18 a = b; 19 b = t; 20 } 21 if(b==0) return(0.); 22 a /= b; 23 /* 24 * pathological overflow possible 25 * in the next line. 26 */ 27 return(b*sqrt(1. + a*a)); 28 } 29 30 struct complex 31 { 32 double r; 33 double i; 34 }; 35 36 double 37 cabs(arg) 38 struct complex arg; 39 { 40 double hypot(); 41 42 return(hypot(arg.r, arg.i)); 43 } 44