xref: /freebsd/lib/msun/man/hypot.3 (revision 608da65de9552d5678c1000776ed69da04a45983)
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. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     from: @(#)hypot.3	6.7 (Berkeley) 5/6/91
29.\"
30.Dd March 30, 2008
31.Dt HYPOT 3
32.Os
33.Sh NAME
34.Nm hypot ,
35.Nm hypotf ,
36.Nm hypotl ,
37.Nm cabs ,
38.Nm cabsf ,
39.Nm cabsl
40.Nd Euclidean distance and complex absolute value functions
41.Sh LIBRARY
42.Lb libm
43.Sh SYNOPSIS
44.In math.h
45.Ft double
46.Fn hypot "double x" "double y"
47.Ft float
48.Fn hypotf "float x" "float y"
49.Ft "long double"
50.Fn hypotl "long double x" "long double y"
51.In complex.h
52.Ft double
53.Fn cabs "double complex z"
54.Ft float
55.Fn cabsf "float complex z"
56.Ft "long double"
57.Fn cabsl "long double complex z"
58.Sh DESCRIPTION
59The
60.Fn hypot ,
61.Fn hypotf
62and
63.Fn hypotl
64functions
65compute the
66sqrt(x*x+y*y)
67in such a way that underflow will not happen, and overflow
68occurs only if the final result deserves it.
69The
70.Fn cabs ,
71.Fn cabsf
72and
73.Fn cabsl
74functions compute the complex absolute value of
75.Fa z .
76.Pp
77.Fn hypot "\*(If" "v"
78=
79.Fn hypot "v" "\*(If"
80= +\*(If for all
81.Fa v ,
82including \*(Na.
83.Sh ERROR (due to Roundoff, etc.)
84Below 0.97
85.Em ulps .
86Consequently
87.Fn hypot "5.0" "12.0"
88= 13.0
89exactly;
90in general, hypot and cabs return an integer whenever an
91integer might be expected.
92.Sh NOTES
93As might be expected,
94.Fn hypot "v" "\*(Na"
95and
96.Fn hypot "\*(Na" "v"
97are \*(Na for all
98.Em finite
99.Fa v .
100But programmers
101might be surprised at first to discover that
102.Fn hypot "\(+-\*(If" "\*(Na"
103= +\*(If.
104This is intentional; it happens because
105.Fn hypot "\*(If" "v"
106= +\*(If
107for
108.Em all
109.Fa v ,
110finite or infinite.
111Hence
112.Fn hypot "\*(If" "v"
113is independent of
114.Fa v .
115Unlike the reserved operand fault on a
116.Tn VAX ,
117the
118.Tn IEEE
119\*(Na is designed to
120disappear when it turns out to be irrelevant, as it does in
121.Fn hypot "\*(If" "\*(Na" .
122.Sh SEE ALSO
123.Xr carg 3 ,
124.Xr math 3 ,
125.Xr sqrt 3
126.Sh STANDARDS
127The
128.Fn hypot ,
129.Fn hypotf ,
130.Fn hypotl ,
131.Fn cabs ,
132.Fn cabsf ,
133and
134.Fn cabsl
135functions conform to
136.St -isoC-99 .
137.Sh HISTORY
138Both a
139.Fn hypot
140function and a
141.Fn cabs
142function
143appeared in
144.At v7 .
145