Line | |
---|
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".
|
---|
4 | *
|
---|
5 | * Author: Ceriel J.H. Jacobs
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <math.h>
|
---|
9 |
|
---|
10 | struct complex {
|
---|
11 | double r,i;
|
---|
12 | };
|
---|
13 |
|
---|
14 | _PROTOTYPE(double hypot, (double x, double y ));
|
---|
15 | _PROTOTYPE(double cabs, (struct complex p_compl ));
|
---|
16 |
|
---|
17 | /* $Header: /cvsup/minix/src/lib/other/hypot.c,v 1.1.1.1 2005/04/21 14:56:27 beng Exp $ */
|
---|
18 |
|
---|
19 | double
|
---|
20 | hypot(x, y)
|
---|
21 | double x, y;
|
---|
22 | {
|
---|
23 | /* Computes sqrt(x*x+y*y), avoiding overflow */
|
---|
24 |
|
---|
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;
|
---|
31 | }
|
---|
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);
|
---|
36 | }
|
---|
37 |
|
---|
38 | double
|
---|
39 | cabs(p_compl)
|
---|
40 | struct complex p_compl;
|
---|
41 | {
|
---|
42 | return hypot(p_compl.r, p_compl.i);
|
---|
43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.