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