Uninitialized vector entry?
[minix3.git] / lib / other / hypot.c
blob8fa1a6cb7ab76058418291e49906139413fdbc8f
1 /*
2 * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
6 */
8 #include <math.h>
10 struct complex {
11 double r,i;
14 _PROTOTYPE(double hypot, (double x, double y ));
15 _PROTOTYPE(double cabs, (struct complex p_compl ));
17 /* $Header$ */
19 double
20 hypot(x, y)
21 double x, y;
23 /* Computes sqrt(x*x+y*y), avoiding overflow */
25 if (x < 0) x = -x;
26 if (y < 0) y = -y;
27 if (x > y) {
28 double t = y;
29 y = x;
30 x = t;
32 /* sqrt(x*x+y*y) = sqrt(y*y*(x*x/(y*y)+1.0)) = y*sqrt(x*x/(y*y)+1.0) */
33 if (y == 0.0) return 0.0;
34 x /= y;
35 return y*sqrt(x*x+1.0);
38 double
39 cabs(p_compl)
40 struct complex p_compl;
42 return hypot(p_compl.r, p_compl.i);