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.\" 283a8617a8SJordan K. Hubbard.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91 297f3dea24SPeter Wemm.\" $FreeBSD$ 303a8617a8SJordan K. Hubbard.\" 31dfd6ede5SDimitry Andric.Dd December 7, 2017 322a6bf1faSDavid Schultz.Dt MATH 3 332a6bf1faSDavid Schultz.Os 342a6bf1faSDavid Schultz.Sh NAME 354e05ab77SRuslan Ermilov.Nm math 364e05ab77SRuslan Ermilov.Nd "floating-point mathematical library" 37dbc8f2b5SDavid Schultz.Sh LIBRARY 38dbc8f2b5SDavid Schultz.Lb libm 39dbc8f2b5SDavid Schultz.Sh SYNOPSIS 40dbc8f2b5SDavid Schultz.In math.h 412a6bf1faSDavid Schultz.Sh DESCRIPTION 42715a43edSDavid SchultzThe math library includes the following components: 43715a43edSDavid Schultz.Bl -column "<complex.h>" "polymorphic (type-generic) versions of functions" -compact -offset indent 44715a43edSDavid Schultz.In math.h Ta basic routines and real-valued functions 45715a43edSDavid Schultz.In complex.h Ta complex number support 46715a43edSDavid Schultz.In tgmath.h Ta polymorphic (type-generic) versions of functions 47715a43edSDavid Schultz.In fenv.h Ta routines to control rounding and exceptions 48715a43edSDavid Schultz.El 49715a43edSDavid SchultzThe rest of this manual page describes the functions provided by 50715a43edSDavid Schultz.In math.h . 51715a43edSDavid SchultzPlease consult 52715a43edSDavid Schultz.Xr complex 3 , 53715a43edSDavid Schultz.Xr tgmath 3 , 54715a43edSDavid Schultzand 55715a43edSDavid Schultz.Xr fenv 3 56715a43edSDavid Schultzfor information on the other components. 572a6bf1faSDavid Schultz.Sh "LIST OF FUNCTIONS" 582a6bf1faSDavid SchultzEach of the following 592a6bf1faSDavid Schultz.Vt double 602a6bf1faSDavid Schultzfunctions has a 612a6bf1faSDavid Schultz.Vt float 622a6bf1faSDavid Schultzcounterpart with an 632a6bf1faSDavid Schultz.Ql f 642a6bf1faSDavid Schultzappended to the name and a 654e05ab77SRuslan Ermilov.Vt "long double" 662a6bf1faSDavid Schultzcounterpart with an 672a6bf1faSDavid Schultz.Ql l 682a6bf1faSDavid Schultzappended. 692a6bf1faSDavid SchultzAs an example, the 702a6bf1faSDavid Schultz.Vt float 712a6bf1faSDavid Schultzand 724e05ab77SRuslan Ermilov.Vt "long double" 732a6bf1faSDavid Schultzcounterparts of 742a6bf1faSDavid Schultz.Ft double 752a6bf1faSDavid Schultz.Fn acos "double x" 762a6bf1faSDavid Schultzare 772a6bf1faSDavid Schultz.Ft float 782a6bf1faSDavid Schultz.Fn acosf "float x" 792a6bf1faSDavid Schultzand 804e05ab77SRuslan Ermilov.Ft "long double" 812a6bf1faSDavid Schultz.Fn acosl "long double x" , 822a6bf1faSDavid Schultzrespectively. 833be0479bSDavid SchultzThe classification macros and silent order predicates are type generic and 843be0479bSDavid Schultzshould not be suffixed with 853be0479bSDavid Schultz.Ql f 863be0479bSDavid Schultzor 873be0479bSDavid Schultz.Ql l . 8852611c60SDavid Schultz.de Cl 8952611c60SDavid Schultz.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" 9052611c60SDavid Schultz.Em "Name Description" 9152611c60SDavid Schultz.. 9252611c60SDavid Schultz.Ss Algebraic Functions 9352611c60SDavid Schultz.Cl 9452611c60SDavid Schultzcbrt cube root 9552611c60SDavid Schultzfma fused multiply-add 9652611c60SDavid Schultzhypot Euclidean distance 9752611c60SDavid Schultzsqrt square root 984e05ab77SRuslan Ermilov.El 993be0479bSDavid Schultz.Ss Classification Macros 10052611c60SDavid Schultz.Cl 10152611c60SDavid Schultzfpclassify classify a floating-point value 10252611c60SDavid Schultzisfinite determine whether a value is finite 10352611c60SDavid Schultzisinf determine whether a value is infinite 10452611c60SDavid Schultzisnan determine whether a value is \*(Na 10552611c60SDavid Schultzisnormal determine whether a value is normalized 10652611c60SDavid Schultz.El 10752611c60SDavid Schultz.Ss Exponent Manipulation Functions 10852611c60SDavid Schultz.Cl 10952611c60SDavid Schultzfrexp extract exponent and mantissa 11052611c60SDavid Schultzilogb extract exponent 11152611c60SDavid Schultzldexp multiply by power of 2 11232948b81SBruce Evanslogb extract exponent 11352611c60SDavid Schultzscalbln adjust exponent 11452611c60SDavid Schultzscalbn adjust exponent 11552611c60SDavid Schultz.El 11652611c60SDavid Schultz.Ss Extremum- and Sign-Related Functions 11752611c60SDavid Schultz.Cl 11852611c60SDavid Schultzcopysign copy sign bit 11952611c60SDavid Schultzfabs absolute value 12052611c60SDavid Schultzfdim positive difference 12152611c60SDavid Schultzfmax maximum function 12252611c60SDavid Schultzfmin minimum function 12352611c60SDavid Schultzsignbit extract sign bit 12452611c60SDavid Schultz.El 1253be0479bSDavid Schultz.Ss Not a Number Functions 1263be0479bSDavid Schultz.Cl 1273be0479bSDavid Schultznan generate a quiet \*(Na 1283be0479bSDavid Schultz.El 12952611c60SDavid Schultz.Ss Residue and Rounding Functions 13052611c60SDavid Schultz.Cl 13152611c60SDavid Schultzceil integer no less than 13252611c60SDavid Schultzfloor integer no greater than 13352611c60SDavid Schultzfmod positive remainder 13452611c60SDavid Schultzllrint round to integer in fixed-point format 13552611c60SDavid Schultzllround round to nearest integer in fixed-point format 13652611c60SDavid Schultzlrint round to integer in fixed-point format 13752611c60SDavid Schultzlround round to nearest integer in fixed-point format 13852611c60SDavid Schultzmodf extract integer and fractional parts 13952611c60SDavid Schultznearbyint round to integer (silent) 14052611c60SDavid Schultznextafter next representable value 14115a53f77SDavid Schultznexttoward next representable value 14252611c60SDavid Schultzremainder remainder 1433b9141eeSDavid Schultzremquo remainder with partial quotient 14452611c60SDavid Schultzrint round to integer 14552611c60SDavid Schultzround round to nearest integer 14652611c60SDavid Schultztrunc integer no greater in magnitude than 14752611c60SDavid Schultz.El 14852611c60SDavid Schultz.Pp 14952611c60SDavid SchultzThe 15052611c60SDavid Schultz.Fn ceil , 15152611c60SDavid Schultz.Fn floor , 15252611c60SDavid Schultz.Fn llround , 15352611c60SDavid Schultz.Fn lround , 15452611c60SDavid Schultz.Fn round , 15552611c60SDavid Schultzand 15652611c60SDavid Schultz.Fn trunc 15752611c60SDavid Schultzfunctions round in predetermined directions, whereas 15852611c60SDavid Schultz.Fn llrint , 15952611c60SDavid Schultz.Fn lrint , 16052611c60SDavid Schultzand 16152611c60SDavid Schultz.Fn rint 16252611c60SDavid Schultzround according to the current (dynamic) rounding mode. 16352611c60SDavid SchultzFor more information on controlling the dynamic rounding mode, see 16452611c60SDavid Schultz.Xr fenv 3 16552611c60SDavid Schultzand 16652611c60SDavid Schultz.Xr fesetround 3 . 16752611c60SDavid Schultz.Ss Silent Order Predicates 16852611c60SDavid Schultz.Cl 16952611c60SDavid Schultzisgreater greater than relation 17052611c60SDavid Schultzisgreaterequal greater than or equal to relation 17152611c60SDavid Schultzisless less than relation 17252611c60SDavid Schultzislessequal less than or equal to relation 17352611c60SDavid Schultzislessgreater less than or greater than relation 17452611c60SDavid Schultzisunordered unordered relation 17552611c60SDavid Schultz.El 17652611c60SDavid Schultz.Ss Transcendental Functions 17752611c60SDavid Schultz.Cl 17852611c60SDavid Schultzacos inverse cosine 17952611c60SDavid Schultzacosh inverse hyperbolic cosine 18052611c60SDavid Schultzasin inverse sine 18152611c60SDavid Schultzasinh inverse hyperbolic sine 18252611c60SDavid Schultzatan inverse tangent 18352611c60SDavid Schultzatanh inverse hyperbolic tangent 18452611c60SDavid Schultzatan2 atan(y/x); complex argument 18552611c60SDavid Schultzcos cosine 18652611c60SDavid Schultzcosh hyperbolic cosine 18752611c60SDavid Schultzerf error function 18852611c60SDavid Schultzerfc complementary error function 18952611c60SDavid Schultzexp exponential base e 19090232fdfSDavid Schultzexp2 exponential base 2 19152611c60SDavid Schultzexpm1 exp(x)\-1 19252611c60SDavid Schultzj0 Bessel function of the first kind of the order 0 19352611c60SDavid Schultzj1 Bessel function of the first kind of the order 1 19452611c60SDavid Schultzjn Bessel function of the first kind of the order n 19552611c60SDavid Schultzlgamma log gamma function 19652611c60SDavid Schultzlog natural logarithm 19752611c60SDavid Schultzlog10 logarithm to base 10 19852611c60SDavid Schultzlog1p log(1+x) 199177668d1SDavid Schultzlog2 base 2 logarithm 20052611c60SDavid Schultzpow exponential x**y 20152611c60SDavid Schultzsin trigonometric function 20252611c60SDavid Schultzsinh hyperbolic function 20352611c60SDavid Schultztan trigonometric function 20452611c60SDavid Schultztanh hyperbolic function 20552611c60SDavid Schultztgamma gamma function 20652611c60SDavid Schultzy0 Bessel function of the second kind of the order 0 20752611c60SDavid Schultzy1 Bessel function of the second kind of the order 1 20852611c60SDavid Schultzyn Bessel function of the second kind of the order n 20952611c60SDavid Schultz.El 21052611c60SDavid Schultz.Pp 211177668d1SDavid SchultzThe routines 21263687c8bSDavid Schultzin this section might not produce a result that is correctly rounded, 21390232fdfSDavid Schultzso reproducible results cannot be guaranteed across platforms. 21490232fdfSDavid SchultzFor most of these functions, however, incorrect rounding occurs 21590232fdfSDavid Schultzrarely, and then only in very-close-to-halfway cases. 2162a6bf1faSDavid Schultz.Sh SEE ALSO 217715a43edSDavid Schultz.Xr complex 3 , 2182a6bf1faSDavid Schultz.Xr fenv 3 , 2193be0479bSDavid Schultz.Xr ieee 3 , 220*5a38af1fSEdward Tomasz Napierala.Xr qmath 3 , 2213be0479bSDavid Schultz.Xr tgmath 3 2222a6bf1faSDavid Schultz.Sh HISTORY 2232a6bf1faSDavid SchultzA math library with many of the present functions appeared in 2244e05ab77SRuslan Ermilov.At v7 . 2254e05ab77SRuslan ErmilovThe library was substantially rewritten for 2264e05ab77SRuslan Ermilov.Bx 4.3 2274e05ab77SRuslan Ermilovto provide 2282a6bf1faSDavid Schultzbetter accuracy and speed on machines supporting either VAX 2292a6bf1faSDavid Schultzor IEEE 754 floating-point. 2302a6bf1faSDavid SchultzMost of this library was replaced with FDLIBM, developed at Sun 2312a6bf1faSDavid SchultzMicrosystems, in 2322a6bf1faSDavid Schultz.Fx 1.1.5 . 23352611c60SDavid SchultzAdditional routines, including ones for 23452611c60SDavid Schultz.Vt float 23552611c60SDavid Schultzand 23652611c60SDavid Schultz.Vt long double 23752611c60SDavid Schultzvalues, were written for or imported into subsequent versions of FreeBSD. 23824a0682cSRuslan Ermilov.Sh BUGS 23990232fdfSDavid SchultzMany of the routines to compute transcendental functions produce 24090232fdfSDavid Schultzinaccurate results in other than the default rounding mode. 24190232fdfSDavid Schultz.Pp 242177668d1SDavid SchultzOn the i386 platform, trigonometric argument reduction is not 24363687c8bSDavid Schultzperformed accurately for huge arguments, resulting in 24463687c8bSDavid Schultzlarge errors 245177668d1SDavid Schultzfor such arguments to 24624a0682cSRuslan Ermilov.Fn cos , 24724a0682cSRuslan Ermilov.Fn sin , 24824a0682cSRuslan Ermilovand 24924a0682cSRuslan Ermilov.Fn tan . 250