Commit | Line | Data |
---|---|---|
cd30a7d2 | 1 | .TH HYPOT 3M "7 August 1985" |
94305a63 | 2 | .UC 4 |
cd30a7d2 MAN |
3 | .ds up \fIulp\fR |
4 | .ds nn \fINaN\fR | |
f4bb663e | 5 | .SH NAME |
94305a63 | 6 | hypot, cabs \- Euclidean distance, complex absolute value |
f4bb663e KM |
7 | .SH SYNOPSIS |
8 | .nf | |
9 | .B #include <math.h> | |
10 | .PP | |
cd30a7d2 MAN |
11 | .B double hypot(x,y) |
12 | .B double x,y; | |
f4bb663e KM |
13 | .PP |
14 | .B double cabs(z) | |
cd30a7d2 | 15 | .B struct {double x,y;} z; |
f4bb663e KM |
16 | .fi |
17 | .SH DESCRIPTION | |
cd30a7d2 MAN |
18 | Hypot(x,y) and cabs(x,y) return sqrt(x\(**x+y\(**y) |
19 | computed in such a way that underflow will not happen, and overflow | |
20 | occurs only if the final result deserves it. | |
f4bb663e | 21 | .PP |
cd30a7d2 MAN |
22 | .if n \ |
23 | hypot(infinity,v) = hypot(v,infinity) = +infinity for all v, | |
24 | .if t \ | |
25 | hypot(\(if,v) = hypot(v,\(if) = +\(if for all v, | |
26 | including \*(nn. | |
f4bb663e | 27 | .SH SEE ALSO |
94305a63 | 28 | intro(3M), sqrt(3M) |
cd30a7d2 MAN |
29 | .SH ERROR (due to Roundoff, etc.) |
30 | Below 0.97 \*(ups. Consequently hypot(5.0,12.0)\0=\013.0 exactly; | |
31 | in general, hypot and cabs return an integer whenever an | |
32 | integer might be expected. | |
33 | .PP | |
34 | The same cannot be said for the shorter and faster version of hypot | |
35 | and cabs that is provided in the comments in cabs.c; its error can | |
36 | exceed 1.2 \*(ups. | |
37 | .SH NOTES | |
38 | As might be expected, hypot(v,\*(nn) and hypot(\*(nn,v) are \*(nn for all | |
39 | \fIfinite\fR v; with "reserved operand" in place of "\*(nn", the | |
40 | same is true on a VAX. But programmers on machines other than a VAX | |
41 | (it has no | |
42 | .if n \ | |
43 | infinity) | |
44 | .if t \ | |
45 | \(if) | |
46 | might be surprised at first to discover that | |
47 | .if n \ | |
48 | hypot(\(+-infinity,\*(nn) = +infinity. | |
49 | .if t \ | |
50 | hypot(\(+-\(if,\*(nn) = +\(if. | |
51 | This is intentional; it happens because | |
52 | .if n \ | |
53 | hypot(infinity,v) = +infinity | |
54 | .if t \ | |
55 | hypot(\(if,v) = +\(if | |
56 | for \fIall\fR v, finite or infinite. | |
57 | Hence | |
58 | .if n \ | |
59 | hypot(infinity,v) | |
60 | .if t \ | |
61 | hypot(\(if,v) | |
62 | is independent of v. | |
63 | Unlike the reserved operand on a VAX, the IEEE \*(nn is designed to | |
64 | disappear when it turns out to be irrelevant, as it does in | |
65 | .if n \ | |
66 | hypot(infinity,\*(nn). | |
67 | .if t \ | |
68 | hypot(\(if,\*(nn). | |
94305a63 MAN |
69 | .SH AUTHOR |
70 | W. Kahan |