xref: /freebsd/lib/msun/man/math.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
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.
12fbbd9655SWarner Losh.\" 3. 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.\"
28dfd6ede5SDimitry Andric.Dd December 7, 2017
292a6bf1faSDavid Schultz.Dt MATH 3
302a6bf1faSDavid Schultz.Os
312a6bf1faSDavid Schultz.Sh NAME
324e05ab77SRuslan Ermilov.Nm math
334e05ab77SRuslan Ermilov.Nd "floating-point mathematical library"
34dbc8f2b5SDavid Schultz.Sh LIBRARY
35dbc8f2b5SDavid Schultz.Lb libm
36dbc8f2b5SDavid Schultz.Sh SYNOPSIS
37dbc8f2b5SDavid Schultz.In math.h
382a6bf1faSDavid Schultz.Sh DESCRIPTION
39715a43edSDavid SchultzThe math library includes the following components:
40715a43edSDavid Schultz.Bl -column "<complex.h>" "polymorphic (type-generic) versions of functions" -compact -offset indent
41715a43edSDavid Schultz.In math.h Ta basic routines and real-valued functions
42715a43edSDavid Schultz.In complex.h Ta complex number support
43715a43edSDavid Schultz.In tgmath.h Ta polymorphic (type-generic) versions of functions
44715a43edSDavid Schultz.In fenv.h Ta routines to control rounding and exceptions
45715a43edSDavid Schultz.El
46715a43edSDavid SchultzThe rest of this manual page describes the functions provided by
47715a43edSDavid Schultz.In math.h .
48715a43edSDavid SchultzPlease consult
49715a43edSDavid Schultz.Xr complex 3 ,
50715a43edSDavid Schultz.Xr tgmath 3 ,
51715a43edSDavid Schultzand
52715a43edSDavid Schultz.Xr fenv 3
53715a43edSDavid Schultzfor information on the other components.
542a6bf1faSDavid Schultz.Sh "LIST OF FUNCTIONS"
552a6bf1faSDavid SchultzEach of the following
562a6bf1faSDavid Schultz.Vt double
572a6bf1faSDavid Schultzfunctions has a
582a6bf1faSDavid Schultz.Vt float
592a6bf1faSDavid Schultzcounterpart with an
602a6bf1faSDavid Schultz.Ql f
612a6bf1faSDavid Schultzappended to the name and a
624e05ab77SRuslan Ermilov.Vt "long double"
632a6bf1faSDavid Schultzcounterpart with an
642a6bf1faSDavid Schultz.Ql l
652a6bf1faSDavid Schultzappended.
662a6bf1faSDavid SchultzAs an example, the
672a6bf1faSDavid Schultz.Vt float
682a6bf1faSDavid Schultzand
694e05ab77SRuslan Ermilov.Vt "long double"
702a6bf1faSDavid Schultzcounterparts of
712a6bf1faSDavid Schultz.Ft double
722a6bf1faSDavid Schultz.Fn acos "double x"
732a6bf1faSDavid Schultzare
742a6bf1faSDavid Schultz.Ft float
752a6bf1faSDavid Schultz.Fn acosf "float x"
762a6bf1faSDavid Schultzand
774e05ab77SRuslan Ermilov.Ft "long double"
782a6bf1faSDavid Schultz.Fn acosl "long double x" ,
792a6bf1faSDavid Schultzrespectively.
803be0479bSDavid SchultzThe classification macros and silent order predicates are type generic and
813be0479bSDavid Schultzshould not be suffixed with
823be0479bSDavid Schultz.Ql f
833be0479bSDavid Schultzor
843be0479bSDavid Schultz.Ql l .
8552611c60SDavid Schultz.de Cl
8652611c60SDavid Schultz.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0"
8752611c60SDavid Schultz.Em "Name	Description"
8852611c60SDavid Schultz..
8952611c60SDavid Schultz.Ss Algebraic Functions
9052611c60SDavid Schultz.Cl
9152611c60SDavid Schultzcbrt	cube root
9252611c60SDavid Schultzfma	fused multiply-add
9352611c60SDavid Schultzhypot	Euclidean distance
9452611c60SDavid Schultzsqrt	square root
954e05ab77SRuslan Ermilov.El
963be0479bSDavid Schultz.Ss Classification Macros
9752611c60SDavid Schultz.Cl
9852611c60SDavid Schultzfpclassify	classify a floating-point value
9952611c60SDavid Schultzisfinite	determine whether a value is finite
10052611c60SDavid Schultzisinf	determine whether a value is infinite
10152611c60SDavid Schultzisnan	determine whether a value is \*(Na
10252611c60SDavid Schultzisnormal	determine whether a value is normalized
10352611c60SDavid Schultz.El
10452611c60SDavid Schultz.Ss Exponent Manipulation Functions
10552611c60SDavid Schultz.Cl
10652611c60SDavid Schultzfrexp	extract exponent and mantissa
10752611c60SDavid Schultzilogb	extract exponent
10852611c60SDavid Schultzldexp	multiply by power of 2
10932948b81SBruce Evanslogb	extract exponent
11052611c60SDavid Schultzscalbln	adjust exponent
11152611c60SDavid Schultzscalbn	adjust exponent
11252611c60SDavid Schultz.El
11352611c60SDavid Schultz.Ss Extremum- and Sign-Related Functions
11452611c60SDavid Schultz.Cl
11552611c60SDavid Schultzcopysign	copy sign bit
11652611c60SDavid Schultzfabs	absolute value
11752611c60SDavid Schultzfdim	positive difference
11852611c60SDavid Schultzfmax	maximum function
11952611c60SDavid Schultzfmin	minimum function
12052611c60SDavid Schultzsignbit	extract sign bit
12152611c60SDavid Schultz.El
1223be0479bSDavid Schultz.Ss Not a Number Functions
1233be0479bSDavid Schultz.Cl
1243be0479bSDavid Schultznan	generate a quiet \*(Na
1253be0479bSDavid Schultz.El
12652611c60SDavid Schultz.Ss Residue and Rounding Functions
12752611c60SDavid Schultz.Cl
12852611c60SDavid Schultzceil	integer no less than
12952611c60SDavid Schultzfloor	integer no greater than
13052611c60SDavid Schultzfmod	positive remainder
13152611c60SDavid Schultzllrint	round to integer in fixed-point format
13252611c60SDavid Schultzllround	round to nearest integer in fixed-point format
13352611c60SDavid Schultzlrint	round to integer in fixed-point format
13452611c60SDavid Schultzlround	round to nearest integer in fixed-point format
13552611c60SDavid Schultzmodf	extract integer and fractional parts
13652611c60SDavid Schultznearbyint	round to integer (silent)
13752611c60SDavid Schultznextafter	next representable value
13815a53f77SDavid Schultznexttoward	next representable value
13952611c60SDavid Schultzremainder	remainder
1403b9141eeSDavid Schultzremquo	remainder with partial quotient
14152611c60SDavid Schultzrint	round to integer
14252611c60SDavid Schultzround	round to nearest integer
14352611c60SDavid Schultztrunc	integer no greater in magnitude than
14452611c60SDavid Schultz.El
14552611c60SDavid Schultz.Pp
14652611c60SDavid SchultzThe
14752611c60SDavid Schultz.Fn ceil ,
14852611c60SDavid Schultz.Fn floor ,
14952611c60SDavid Schultz.Fn llround ,
15052611c60SDavid Schultz.Fn lround ,
15152611c60SDavid Schultz.Fn round ,
15252611c60SDavid Schultzand
15352611c60SDavid Schultz.Fn trunc
15452611c60SDavid Schultzfunctions round in predetermined directions, whereas
15552611c60SDavid Schultz.Fn llrint ,
15652611c60SDavid Schultz.Fn lrint ,
15752611c60SDavid Schultzand
15852611c60SDavid Schultz.Fn rint
15952611c60SDavid Schultzround according to the current (dynamic) rounding mode.
16052611c60SDavid SchultzFor more information on controlling the dynamic rounding mode, see
16152611c60SDavid Schultz.Xr fenv 3
16252611c60SDavid Schultzand
16352611c60SDavid Schultz.Xr fesetround 3 .
16452611c60SDavid Schultz.Ss Silent Order Predicates
16552611c60SDavid Schultz.Cl
16652611c60SDavid Schultzisgreater	greater than relation
16752611c60SDavid Schultzisgreaterequal	greater than or equal to relation
16852611c60SDavid Schultzisless	less than relation
16952611c60SDavid Schultzislessequal	less than or equal to relation
17052611c60SDavid Schultzislessgreater	less than or greater than relation
17152611c60SDavid Schultzisunordered	unordered relation
17252611c60SDavid Schultz.El
17352611c60SDavid Schultz.Ss Transcendental Functions
17452611c60SDavid Schultz.Cl
17552611c60SDavid Schultzacos	inverse cosine
17652611c60SDavid Schultzacosh	inverse hyperbolic cosine
17752611c60SDavid Schultzasin	inverse sine
17852611c60SDavid Schultzasinh	inverse hyperbolic sine
17952611c60SDavid Schultzatan	inverse tangent
18052611c60SDavid Schultzatanh	inverse hyperbolic tangent
18152611c60SDavid Schultzatan2	atan(y/x); complex argument
18252611c60SDavid Schultzcos	cosine
18352611c60SDavid Schultzcosh	hyperbolic cosine
18452611c60SDavid Schultzerf	error function
18552611c60SDavid Schultzerfc	complementary error function
18652611c60SDavid Schultzexp	exponential base e
18790232fdfSDavid Schultzexp2	exponential base 2
18852611c60SDavid Schultzexpm1	exp(x)\-1
18952611c60SDavid Schultzj0	Bessel function of the first kind of the order 0
19052611c60SDavid Schultzj1	Bessel function of the first kind of the order 1
19152611c60SDavid Schultzjn	Bessel function of the first kind of the order n
19252611c60SDavid Schultzlgamma	log gamma function
19352611c60SDavid Schultzlog	natural logarithm
19452611c60SDavid Schultzlog10	logarithm to base 10
19552611c60SDavid Schultzlog1p	log(1+x)
196177668d1SDavid Schultzlog2	base 2 logarithm
19752611c60SDavid Schultzpow	exponential x**y
19852611c60SDavid Schultzsin	trigonometric function
19952611c60SDavid Schultzsinh	hyperbolic function
20052611c60SDavid Schultztan	trigonometric function
20152611c60SDavid Schultztanh	hyperbolic function
20252611c60SDavid Schultztgamma	gamma function
20352611c60SDavid Schultzy0	Bessel function of the second kind of the order 0
20452611c60SDavid Schultzy1	Bessel function of the second kind of the order 1
20552611c60SDavid Schultzyn	Bessel function of the second kind of the order n
20652611c60SDavid Schultz.El
20752611c60SDavid Schultz.Pp
208177668d1SDavid SchultzThe routines
20963687c8bSDavid Schultzin this section might not produce a result that is correctly rounded,
21090232fdfSDavid Schultzso reproducible results cannot be guaranteed across platforms.
21190232fdfSDavid SchultzFor most of these functions, however, incorrect rounding occurs
21290232fdfSDavid Schultzrarely, and then only in very-close-to-halfway cases.
2132a6bf1faSDavid Schultz.Sh SEE ALSO
214715a43edSDavid Schultz.Xr complex 3 ,
2152a6bf1faSDavid Schultz.Xr fenv 3 ,
2163be0479bSDavid Schultz.Xr ieee 3 ,
217*5a38af1fSEdward Tomasz Napierala.Xr qmath 3 ,
2183be0479bSDavid Schultz.Xr tgmath 3
2192a6bf1faSDavid Schultz.Sh HISTORY
2202a6bf1faSDavid SchultzA math library with many of the present functions appeared in
2214e05ab77SRuslan Ermilov.At v7 .
2224e05ab77SRuslan ErmilovThe library was substantially rewritten for
2234e05ab77SRuslan Ermilov.Bx 4.3
2244e05ab77SRuslan Ermilovto provide
2252a6bf1faSDavid Schultzbetter accuracy and speed on machines supporting either VAX
2262a6bf1faSDavid Schultzor IEEE 754 floating-point.
2272a6bf1faSDavid SchultzMost of this library was replaced with FDLIBM, developed at Sun
2282a6bf1faSDavid SchultzMicrosystems, in
2292a6bf1faSDavid Schultz.Fx 1.1.5 .
23052611c60SDavid SchultzAdditional routines, including ones for
23152611c60SDavid Schultz.Vt float
23252611c60SDavid Schultzand
23352611c60SDavid Schultz.Vt long double
23452611c60SDavid Schultzvalues, were written for or imported into subsequent versions of FreeBSD.
23524a0682cSRuslan Ermilov.Sh BUGS
23690232fdfSDavid SchultzMany of the routines to compute transcendental functions produce
23790232fdfSDavid Schultzinaccurate results in other than the default rounding mode.
23890232fdfSDavid Schultz.Pp
239177668d1SDavid SchultzOn the i386 platform, trigonometric argument reduction is not
24063687c8bSDavid Schultzperformed accurately for huge arguments, resulting in
24163687c8bSDavid Schultzlarge errors
242177668d1SDavid Schultzfor such arguments to
24324a0682cSRuslan Ermilov.Fn cos ,
24424a0682cSRuslan Ermilov.Fn sin ,
24524a0682cSRuslan Ermilovand
24624a0682cSRuslan Ermilov.Fn tan .
247