xref: /netbsd-src/lib/libm/man/hypot.3 (revision ce63d6c20fc4ec8ddc95c84bb229e3c4ecf82b69)
1.\" Copyright (c) 1985, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)hypot.3	6.7 (Berkeley) 5/6/91
33.\"
34.Dd May 6, 1991
35.Dt HYPOT 3
36.Os BSD 4
37.Sh NAME
38.Nm hypot ,
39.Nm cabs
40.Nd euclidean distance and complex absolute value functions
41.Sh SYNOPSIS
42.Fd #include <math.h>
43.Ft double
44.Fn hypot "double x" "double y"
45.Fd struct {double x, y;} z;
46.Ft double
47.Fn cabs z
48.Sh DESCRIPTION
49The
50.Fn hypot
51and
52.Fn cabs
53functions
54computes the
55sqrt(x*x+y*y)
56in such a way that underflow will not happen, and overflow
57occurs only if the final result deserves it.
58.Pp
59.Fn hypot "\*(If" "v"
60=
61.Fn hypot "v" "\*(If"
62= +\*(If for all
63.Ar v ,
64including \*(Na.
65.Sh ERROR (due to Roundoff, etc.)
66Below 0.97
67.Em ulps .
68Consequently
69.Fn hypot "5.0" "12.0"
70= 13.0
71exactly;
72in general, hypot and cabs return an integer whenever an
73integer might be expected.
74.Pp
75The same cannot be said for the shorter and faster version of hypot
76and cabs that is provided in the comments in cabs.c; its error can
77exceed 1.2
78.Em ulps .
79.Sh NOTES
80As might be expected,
81.Fn hypot "v" "\*(Na"
82and
83.Fn hypot "\*(Na" "v"
84are \*(Na for all
85.Em finite
86.Ar v ;
87with "reserved operand" in place of "\*(Na", the
88same is true on a
89.Tn VAX .
90But programmers on machines other than a
91.Tn VAX
92(if has no \*(If)
93might be surprised at first to discover that
94.Fn hypot "\(+-\*(If" "\*(Na"
95= +\*(If.
96This is intentional; it happens because
97.Fn hypot "\*(If" "v"
98= +\*(If
99for
100.Em all
101.Ar v ,
102finite or infinite.
103Hence
104.Fn hypot "\*(If" "v"
105is independent of
106.Ar v .
107Unlike the reserved operand fault on a
108.Tn VAX ,
109the
110.Tn IEEE
111\*(Na is designed to
112disappear when it turns out to be irrelevant, as it does in
113.Fn hypot "\*(If" "\*(Na" .
114.Sh SEE ALSO
115.Xr math 3 ,
116.Xr sqrt 3
117.Sh HISTORY
118Both a
119.Fn hypot
120function and a
121.Fn cabs
122function
123appeared in
124.At v7 .
125