1 .\" Copyright (c) 1985 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 .\" from: @(#)math.3 6.10 (Berkeley) 5/6/91
33 .\" $FreeBSD: src/lib/msun/man/math.3,v 1.27 2005/11/17 13:00:00 ru Exp $
34 .\"
35 .Dd November 6, 2005
36 .Dt MATH 3
37 .Os
38 .if n \{\
39 .char \[sr] "sqrt
40 .\}
41 .Sh NAME
42 .Nm math
43 .Nd "floating-point mathematical library"
44 .Sh LIBRARY
45 .Lb libm
46 .Sh SYNOPSIS
47 .In math.h
48 .Sh DESCRIPTION
49 These functions constitute the C math library.
50 .Sh "LIST OF FUNCTIONS"
51 Each of the following
52 .Vt double
53 functions has a
54 .Vt float
55 counterpart with an
56 .Ql f
57 appended to the name and a
58 .Vt "long double"
59 counterpart with an
60 .Ql l
61 appended.
62 As an example, the
63 .Vt float
64 and
65 .Vt "long double"
66 counterparts of
67 .Ft double
68 .Fn acos "double x"
69 are
70 .Ft float
71 .Fn acosf "float x"
72 and
73 .Ft "long double"
74 .Fn acosl "long double x" ,
75 respectively.
76 .de Cl
77 .Bl -column "isgreaterequal" "bessel function of the second kind of the order 0"
78 .Em "Name Description"
79 ..
80 .Ss Algebraic Functions
81 .Cl
82 cbrt cube root
83 fma fused multiply-add
84 hypot Euclidean distance
85 sqrt square root
86 .El
87 .Ss Classification Functions
88 .Cl
89 fpclassify classify a floating-point value
90 isfinite determine whether a value is finite
91 isinf determine whether a value is infinite
92 isnan determine whether a value is \*(Na
93 isnormal determine whether a value is normalized
94 .El
95 .Ss Exponent Manipulation Functions
96 .Cl
97 frexp extract exponent and mantissa
98 ilogb extract exponent
99 ldexp multiply by power of 2
100 logb extract exponent
101 scalbln adjust exponent
102 scalbn adjust exponent
103 .El
104 .Ss Extremum- and Sign-Related Functions
105 .Cl
106 copysign copy sign bit
107 fabs absolute value
108 fdim positive difference
109 fmax maximum function
110 fmin minimum function
111 signbit extract sign bit
112 .El
113 .\" .Ss Not a Number
114 .\" .Cl
115 .\" nan return quiet \*(Na) 0
116 .\" .El
117 .Ss Residue and Rounding Functions
118 .Cl
119 ceil integer no less than
120 floor integer no greater than
121 fmod positive remainder
122 llrint round to integer in fixed-point format
123 llround round to nearest integer in fixed-point format
124 lrint round to integer in fixed-point format
125 lround round to nearest integer in fixed-point format
126 modf extract integer and fractional parts
127 nearbyint round to integer (silent)
128 nextafter next representable value
129 nexttoward next representable value
130 remainder remainder
131 remquo remainder with partial quotient
132 rint round to integer
133 round round to nearest integer
134 trunc integer no greater in magnitude than
135 .El
136 .Pp
137 The
138 .Fn ceil ,
139 .Fn floor ,
140 .Fn llround ,
141 .Fn lround ,
142 .Fn round ,
143 and
144 .Fn trunc
145 functions round in predetermined directions, whereas
146 .Fn llrint ,
147 .Fn lrint ,
148 and
149 .Fn rint
150 round according to the current (dynamic) rounding mode.
151 For more information on controlling the dynamic rounding mode, see
152 .Xr fenv 3
153 and
154 .Xr fesetround 3 .
155 .Ss Silent Order Predicates
156 .Cl
157 isgreater greater than relation
158 isgreaterequal greater than or equal to relation
159 isless less than relation
160 islessequal less than or equal to relation
161 islessgreater less than or greater than relation
162 isunordered unordered relation
163 .El
164 .Ss Transcendental Functions
165 .Cl
166 acos inverse cosine
167 acosh inverse hyperbolic cosine
168 asin inverse sine
169 asinh inverse hyperbolic sine
170 atan inverse tangent
171 atanh inverse hyperbolic tangent
172 atan2 atan(y/x); complex argument
173 cos cosine
174 cosh hyperbolic cosine
175 erf error function
176 erfc complementary error function
177 exp exponential base e
178 exp2 exponential base 2
179 expm1 exp(x)\-1
180 j0 Bessel function of the first kind of the order 0
181 j1 Bessel function of the first kind of the order 1
182 jn Bessel function of the first kind of the order n
183 lgamma log gamma function
184 log natural logarithm
185 log10 logarithm to base 10
186 log1p log(1+x)
187 .\" log2 base 2 logarithm
188 pow exponential x**y
189 sin trigonometric function
190 sinh hyperbolic function
191 tan trigonometric function
192 tanh hyperbolic function
193 tgamma gamma function
194 y0 Bessel function of the second kind of the order 0
195 y1 Bessel function of the second kind of the order 1
196 yn Bessel function of the second kind of the order n
197 .El
198 .Pp
199 Unlike the algebraic functions listed earlier, the routines
200 in this section may not produce a result that is correctly rounded,
201 so reproducible results cannot be guaranteed across platforms.
202 For most of these functions, however, incorrect rounding occurs
203 rarely, and then only in very-close-to-halfway cases.
204 .Sh SEE ALSO
205 .Xr fenv 3 ,
206 .Xr ieee 3
207 .Sh HISTORY
208 A math library with many of the present functions appeared in
209 .At v7 .
210 The library was substantially rewritten for
211 .Bx 4.3
212 to provide
213 better accuracy and speed on machines supporting either VAX
214 or IEEE 754 floating-point.
215 Most of this library was replaced with FDLIBM, developed at Sun
216 Microsystems, in
217 .Fx 1.1.5 .
218 Additional routines, including ones for
219 .Vt float
220 and
221 .Vt long double
222 values, were written for or imported into subsequent versions of FreeBSD.
223 .Sh BUGS
224 The
225 .Fn log2
226 and
227 .Fn nan
228 functions are missing, and many functions are not available in their
229 .Vt "long double"
230 variants.
231 .Pp
232 Many of the routines to compute transcendental functions produce
233 inaccurate results in other than the default rounding mode.
234 .Pp
235 On some architectures, trigonometric argument reduction is not
236 performed accurately, resulting in errors greater than 1
237 .Em ulp
238 for large arguments to
239 .Fn cos ,
240 .Fn sin ,
241 and
242 .Fn tan .