xref: /freebsd/lib/msun/man/math.3 (revision 3be0479b4cdb1a893b3b08a99c3af2f1d684790c)
13a8617a8SJordan K. Hubbard.\" Copyright (c) 1985 Regents of the University of California.
23a8617a8SJordan K. Hubbard.\" All rights reserved.
33a8617a8SJordan K. Hubbard.\"
43a8617a8SJordan K. Hubbard.\" Redistribution and use in source and binary forms, with or without
53a8617a8SJordan K. Hubbard.\" modification, are permitted provided that the following conditions
63a8617a8SJordan K. Hubbard.\" are met:
73a8617a8SJordan K. Hubbard.\" 1. Redistributions of source code must retain the above copyright
83a8617a8SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer.
93a8617a8SJordan K. Hubbard.\" 2. Redistributions in binary form must reproduce the above copyright
103a8617a8SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer in the
113a8617a8SJordan K. Hubbard.\"    documentation and/or other materials provided with the distribution.
123a8617a8SJordan K. Hubbard.\" 4. Neither the name of the University nor the names of its contributors
133a8617a8SJordan K. Hubbard.\"    may be used to endorse or promote products derived from this software
143a8617a8SJordan K. Hubbard.\"    without specific prior written permission.
153a8617a8SJordan K. Hubbard.\"
163a8617a8SJordan K. Hubbard.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
173a8617a8SJordan K. Hubbard.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183a8617a8SJordan K. Hubbard.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
193a8617a8SJordan K. Hubbard.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
203a8617a8SJordan K. Hubbard.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
213a8617a8SJordan K. Hubbard.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223a8617a8SJordan K. Hubbard.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233a8617a8SJordan K. Hubbard.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
243a8617a8SJordan K. Hubbard.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
253a8617a8SJordan K. Hubbard.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
263a8617a8SJordan K. Hubbard.\" SUCH DAMAGE.
273a8617a8SJordan K. Hubbard.\"
283a8617a8SJordan K. Hubbard.\"	from: @(#)math.3	6.10 (Berkeley) 5/6/91
297f3dea24SPeter Wemm.\" $FreeBSD$
303a8617a8SJordan K. Hubbard.\"
313be0479bSDavid Schultz.Dd December 16, 2007
322a6bf1faSDavid Schultz.Dt MATH 3
332a6bf1faSDavid Schultz.Os
344e05ab77SRuslan Ermilov.if n \{\
354e05ab77SRuslan Ermilov.char \[sr] "sqrt
364e05ab77SRuslan Ermilov.\}
372a6bf1faSDavid Schultz.Sh NAME
384e05ab77SRuslan Ermilov.Nm math
394e05ab77SRuslan Ermilov.Nd "floating-point mathematical library"
40dbc8f2b5SDavid Schultz.Sh LIBRARY
41dbc8f2b5SDavid Schultz.Lb libm
42dbc8f2b5SDavid Schultz.Sh SYNOPSIS
43dbc8f2b5SDavid Schultz.In math.h
442a6bf1faSDavid Schultz.Sh DESCRIPTION
45dbc8f2b5SDavid SchultzThese functions constitute the C math library.
462a6bf1faSDavid Schultz.Sh "LIST OF FUNCTIONS"
472a6bf1faSDavid SchultzEach of the following
482a6bf1faSDavid Schultz.Vt double
492a6bf1faSDavid Schultzfunctions has a
502a6bf1faSDavid Schultz.Vt float
512a6bf1faSDavid Schultzcounterpart with an
522a6bf1faSDavid Schultz.Ql f
532a6bf1faSDavid Schultzappended to the name and a
544e05ab77SRuslan Ermilov.Vt "long double"
552a6bf1faSDavid Schultzcounterpart with an
562a6bf1faSDavid Schultz.Ql l
572a6bf1faSDavid Schultzappended.
582a6bf1faSDavid SchultzAs an example, the
592a6bf1faSDavid Schultz.Vt float
602a6bf1faSDavid Schultzand
614e05ab77SRuslan Ermilov.Vt "long double"
622a6bf1faSDavid Schultzcounterparts of
632a6bf1faSDavid Schultz.Ft double
642a6bf1faSDavid Schultz.Fn acos "double x"
652a6bf1faSDavid Schultzare
662a6bf1faSDavid Schultz.Ft float
672a6bf1faSDavid Schultz.Fn acosf "float x"
682a6bf1faSDavid Schultzand
694e05ab77SRuslan Ermilov.Ft "long double"
702a6bf1faSDavid Schultz.Fn acosl "long double x" ,
712a6bf1faSDavid Schultzrespectively.
723be0479bSDavid SchultzThe classification macros and silent order predicates are type generic and
733be0479bSDavid Schultzshould not be suffixed with
743be0479bSDavid Schultz.Ql f
753be0479bSDavid Schultzor
763be0479bSDavid Schultz.Ql l .
7752611c60SDavid Schultz.de Cl
7852611c60SDavid Schultz.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0"
7952611c60SDavid Schultz.Em "Name	Description"
8052611c60SDavid Schultz..
8152611c60SDavid Schultz.Ss Algebraic Functions
8252611c60SDavid Schultz.Cl
8352611c60SDavid Schultzcbrt	cube root
8452611c60SDavid Schultzfma	fused multiply-add
8552611c60SDavid Schultzhypot	Euclidean distance
8652611c60SDavid Schultzsqrt	square root
874e05ab77SRuslan Ermilov.El
883be0479bSDavid Schultz.Ss Classification Macros
8952611c60SDavid Schultz.Cl
9052611c60SDavid Schultzfpclassify	classify a floating-point value
9152611c60SDavid Schultzisfinite	determine whether a value is finite
9252611c60SDavid Schultzisinf	determine whether a value is infinite
9352611c60SDavid Schultzisnan	determine whether a value is \*(Na
9452611c60SDavid Schultzisnormal	determine whether a value is normalized
9552611c60SDavid Schultz.El
9652611c60SDavid Schultz.Ss Exponent Manipulation Functions
9752611c60SDavid Schultz.Cl
9852611c60SDavid Schultzfrexp	extract exponent and mantissa
9952611c60SDavid Schultzilogb	extract exponent
10052611c60SDavid Schultzldexp	multiply by power of 2
10132948b81SBruce Evanslogb	extract exponent
10252611c60SDavid Schultzscalbln	adjust exponent
10352611c60SDavid Schultzscalbn	adjust exponent
10452611c60SDavid Schultz.El
10552611c60SDavid Schultz.Ss Extremum- and Sign-Related Functions
10652611c60SDavid Schultz.Cl
10752611c60SDavid Schultzcopysign	copy sign bit
10852611c60SDavid Schultzfabs	absolute value
10952611c60SDavid Schultzfdim	positive difference
11052611c60SDavid Schultzfmax	maximum function
11152611c60SDavid Schultzfmin	minimum function
11252611c60SDavid Schultzsignbit	extract sign bit
11352611c60SDavid Schultz.El
1143be0479bSDavid Schultz.Ss Not a Number Functions
1153be0479bSDavid Schultz.Cl
1163be0479bSDavid Schultznan	generate a quiet \*(Na
1173be0479bSDavid Schultz.El
11852611c60SDavid Schultz.Ss Residue and Rounding Functions
11952611c60SDavid Schultz.Cl
12052611c60SDavid Schultzceil	integer no less than
12152611c60SDavid Schultzfloor	integer no greater than
12252611c60SDavid Schultzfmod	positive remainder
12352611c60SDavid Schultzllrint	round to integer in fixed-point format
12452611c60SDavid Schultzllround	round to nearest integer in fixed-point format
12552611c60SDavid Schultzlrint	round to integer in fixed-point format
12652611c60SDavid Schultzlround	round to nearest integer in fixed-point format
12752611c60SDavid Schultzmodf	extract integer and fractional parts
12852611c60SDavid Schultznearbyint	round to integer (silent)
12952611c60SDavid Schultznextafter	next representable value
13015a53f77SDavid Schultznexttoward	next representable value
13152611c60SDavid Schultzremainder	remainder
1323b9141eeSDavid Schultzremquo	remainder with partial quotient
13352611c60SDavid Schultzrint	round to integer
13452611c60SDavid Schultzround	round to nearest integer
13552611c60SDavid Schultztrunc	integer no greater in magnitude than
13652611c60SDavid Schultz.El
13752611c60SDavid Schultz.Pp
13852611c60SDavid SchultzThe
13952611c60SDavid Schultz.Fn ceil ,
14052611c60SDavid Schultz.Fn floor ,
14152611c60SDavid Schultz.Fn llround ,
14252611c60SDavid Schultz.Fn lround ,
14352611c60SDavid Schultz.Fn round ,
14452611c60SDavid Schultzand
14552611c60SDavid Schultz.Fn trunc
14652611c60SDavid Schultzfunctions round in predetermined directions, whereas
14752611c60SDavid Schultz.Fn llrint ,
14852611c60SDavid Schultz.Fn lrint ,
14952611c60SDavid Schultzand
15052611c60SDavid Schultz.Fn rint
15152611c60SDavid Schultzround according to the current (dynamic) rounding mode.
15252611c60SDavid SchultzFor more information on controlling the dynamic rounding mode, see
15352611c60SDavid Schultz.Xr fenv 3
15452611c60SDavid Schultzand
15552611c60SDavid Schultz.Xr fesetround 3 .
15652611c60SDavid Schultz.Ss Silent Order Predicates
15752611c60SDavid Schultz.Cl
15852611c60SDavid Schultzisgreater	greater than relation
15952611c60SDavid Schultzisgreaterequal	greater than or equal to relation
16052611c60SDavid Schultzisless	less than relation
16152611c60SDavid Schultzislessequal	less than or equal to relation
16252611c60SDavid Schultzislessgreater	less than or greater than relation
16352611c60SDavid Schultzisunordered	unordered relation
16452611c60SDavid Schultz.El
16552611c60SDavid Schultz.Ss Transcendental Functions
16652611c60SDavid Schultz.Cl
16752611c60SDavid Schultzacos	inverse cosine
16852611c60SDavid Schultzacosh	inverse hyperbolic cosine
16952611c60SDavid Schultzasin	inverse sine
17052611c60SDavid Schultzasinh	inverse hyperbolic sine
17152611c60SDavid Schultzatan	inverse tangent
17252611c60SDavid Schultzatanh	inverse hyperbolic tangent
17352611c60SDavid Schultzatan2	atan(y/x); complex argument
17452611c60SDavid Schultzcos	cosine
17552611c60SDavid Schultzcosh	hyperbolic cosine
17652611c60SDavid Schultzerf	error function
17752611c60SDavid Schultzerfc	complementary error function
17852611c60SDavid Schultzexp	exponential base e
17990232fdfSDavid Schultzexp2	exponential base 2
18052611c60SDavid Schultzexpm1	exp(x)\-1
18152611c60SDavid Schultzj0	Bessel function of the first kind of the order 0
18252611c60SDavid Schultzj1	Bessel function of the first kind of the order 1
18352611c60SDavid Schultzjn	Bessel function of the first kind of the order n
18452611c60SDavid Schultzlgamma	log gamma function
18552611c60SDavid Schultzlog	natural logarithm
18652611c60SDavid Schultzlog10	logarithm to base 10
18752611c60SDavid Schultzlog1p	log(1+x)
18852611c60SDavid Schultz.\" log2	base 2 logarithm
18952611c60SDavid Schultzpow	exponential x**y
19052611c60SDavid Schultzsin	trigonometric function
19152611c60SDavid Schultzsinh	hyperbolic function
19252611c60SDavid Schultztan	trigonometric function
19352611c60SDavid Schultztanh	hyperbolic function
19452611c60SDavid Schultztgamma	gamma function
19552611c60SDavid Schultzy0	Bessel function of the second kind of the order 0
19652611c60SDavid Schultzy1	Bessel function of the second kind of the order 1
19752611c60SDavid Schultzyn	Bessel function of the second kind of the order n
19852611c60SDavid Schultz.El
19952611c60SDavid Schultz.Pp
20052611c60SDavid SchultzUnlike the algebraic functions listed earlier, the routines
20190232fdfSDavid Schultzin this section may not produce a result that is correctly rounded,
20290232fdfSDavid Schultzso reproducible results cannot be guaranteed across platforms.
20390232fdfSDavid SchultzFor most of these functions, however, incorrect rounding occurs
20490232fdfSDavid Schultzrarely, and then only in very-close-to-halfway cases.
2052a6bf1faSDavid Schultz.Sh SEE ALSO
2062a6bf1faSDavid Schultz.Xr fenv 3 ,
2073be0479bSDavid Schultz.Xr ieee 3 ,
2083be0479bSDavid Schultz.Xr tgmath 3
2092a6bf1faSDavid Schultz.Sh HISTORY
2102a6bf1faSDavid SchultzA math library with many of the present functions appeared in
2114e05ab77SRuslan Ermilov.At v7 .
2124e05ab77SRuslan ErmilovThe library was substantially rewritten for
2134e05ab77SRuslan Ermilov.Bx 4.3
2144e05ab77SRuslan Ermilovto provide
2152a6bf1faSDavid Schultzbetter accuracy and speed on machines supporting either VAX
2162a6bf1faSDavid Schultzor IEEE 754 floating-point.
2172a6bf1faSDavid SchultzMost of this library was replaced with FDLIBM, developed at Sun
2182a6bf1faSDavid SchultzMicrosystems, in
2192a6bf1faSDavid Schultz.Fx 1.1.5 .
22052611c60SDavid SchultzAdditional routines, including ones for
22152611c60SDavid Schultz.Vt float
22252611c60SDavid Schultzand
22352611c60SDavid Schultz.Vt long double
22452611c60SDavid Schultzvalues, were written for or imported into subsequent versions of FreeBSD.
22524a0682cSRuslan Ermilov.Sh BUGS
22615a53f77SDavid SchultzThe
22790232fdfSDavid Schultz.Fn log2
2283be0479bSDavid Schultzfunction is missing, and many functions are not available in their
22924a0682cSRuslan Ermilov.Vt "long double"
23024a0682cSRuslan Ermilovvariants.
23124a0682cSRuslan Ermilov.Pp
23290232fdfSDavid SchultzMany of the routines to compute transcendental functions produce
23390232fdfSDavid Schultzinaccurate results in other than the default rounding mode.
23490232fdfSDavid Schultz.Pp
23524a0682cSRuslan ErmilovOn some architectures, trigonometric argument reduction is not
23624a0682cSRuslan Ermilovperformed accurately, resulting in errors greater than 1
23724a0682cSRuslan Ermilov.Em ulp
23824a0682cSRuslan Ermilovfor large arguments to
23924a0682cSRuslan Ermilov.Fn cos ,
24024a0682cSRuslan Ermilov.Fn sin ,
24124a0682cSRuslan Ermilovand
24224a0682cSRuslan Ermilov.Fn tan .
243