date and time created 85/09/06 17:53:04 by zliu
[unix-history] / usr / src / lib / libm / common_source / hypot.3
CommitLineData
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 6hypot, 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
18Hypot(x,y) and cabs(x,y) return sqrt(x\(**x+y\(**y)
19computed in such a way that underflow will not happen, and overflow
20occurs only if the final result deserves it.
f4bb663e 21.PP
cd30a7d2
MAN
22.if n \
23hypot(infinity,v) = hypot(v,infinity) = +infinity for all v,
24.if t \
25hypot(\(if,v) = hypot(v,\(if) = +\(if for all v,
26including \*(nn.
f4bb663e 27.SH SEE ALSO
94305a63 28intro(3M), sqrt(3M)
cd30a7d2
MAN
29.SH ERROR (due to Roundoff, etc.)
30Below 0.97 \*(ups. Consequently hypot(5.0,12.0)\0=\013.0 exactly;
31in general, hypot and cabs return an integer whenever an
32integer might be expected.
33.PP
34The same cannot be said for the shorter and faster version of hypot
35and cabs that is provided in the comments in cabs.c; its error can
36exceed 1.2 \*(ups.
37.SH NOTES
38As 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
40same is true on a VAX. But programmers on machines other than a VAX
41(it has no
42.if n \
43infinity)
44.if t \
45\(if)
46might be surprised at first to discover that
47.if n \
48hypot(\(+-infinity,\*(nn) = +infinity.
49.if t \
50hypot(\(+-\(if,\*(nn) = +\(if.
51This is intentional; it happens because
52.if n \
53hypot(infinity,v) = +infinity
54.if t \
55hypot(\(if,v) = +\(if
56for \fIall\fR v, finite or infinite.
57Hence
58.if n \
59hypot(infinity,v)
60.if t \
61hypot(\(if,v)
62is independent of v.
63Unlike the reserved operand on a VAX, the IEEE \*(nn is designed to
64disappear when it turns out to be irrelevant, as it does in
65.if n \
66hypot(infinity,\*(nn).
67.if t \
68hypot(\(if,\*(nn).
94305a63
MAN
69.SH AUTHOR
70W. Kahan