1HYPOT(3M) HYPOT(3M)
2
3
4
6 hypot, cabs - Euclidean distance, complex absolute value
7
9 #include <math.h>
10
11 double hypot(x,y)
12 double x,y;
13
14 double cabs(z)
15 struct {double x,y;} z;
16
18 Hypot(x,y) and cabs(x,y) return sqrt(x∗x+y∗y) computed in such a way
19 that underflow will not happen, and overflow occurs only if the final
20 result deserves it.
21
22 hypot(infinity,v) = hypot(v,infinity) = +infinity for all v, including
23 NaN.
24
26 Below 0.97 ulps. Consequently hypot(5.0,12.0) = 13.0 exactly; in gen‐
27 eral, hypot and cabs return an integer whenever an integer might be
28 expected.
29
30 The same cannot be said for the shorter and faster version of hypot and
31 cabs that is provided in the comments in cabs.c; its error can exceed
32 1.2 ulps.
33
35 As might be expected, hypot(v,NaN) and hypot(NaN,v) are NaN for all
36 finite v; with "reserved operand" in place of "NaN", the same is true
37 on a VAX. But programmers on machines other than a VAX (it has no
38 infinity) might be surprised at first to discover that hypot(±infin‐
39 ity,NaN) = +infinity. This is intentional; it happens because
40 hypot(infinity,v) = +infinity for all v, finite or infinite. Hence
41 hypot(infinity,v) is independent of v. Unlike the reserved operand on
42 a VAX, the IEEE NaN is designed to disappear when it turns out to be
43 irrelevant, as it does in hypot(infinity,NaN).
44
46 math(3M), sqrt(3M)
47
49 W. Kahan
50
51
52
534th Berkeley Distribution May 12, 1986 HYPOT(3M)