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