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