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.\" 31177668d1SDavid Schultz.Dd December 5, 2010 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 42dbc8f2b5SDavid SchultzThese functions constitute the C math library. 432a6bf1faSDavid Schultz.Sh "LIST OF FUNCTIONS" 442a6bf1faSDavid SchultzEach of the following 452a6bf1faSDavid Schultz.Vt double 462a6bf1faSDavid Schultzfunctions has a 472a6bf1faSDavid Schultz.Vt float 482a6bf1faSDavid Schultzcounterpart with an 492a6bf1faSDavid Schultz.Ql f 502a6bf1faSDavid Schultzappended to the name and a 514e05ab77SRuslan Ermilov.Vt "long double" 522a6bf1faSDavid Schultzcounterpart with an 532a6bf1faSDavid Schultz.Ql l 542a6bf1faSDavid Schultzappended. 552a6bf1faSDavid SchultzAs an example, the 562a6bf1faSDavid Schultz.Vt float 572a6bf1faSDavid Schultzand 584e05ab77SRuslan Ermilov.Vt "long double" 592a6bf1faSDavid Schultzcounterparts of 602a6bf1faSDavid Schultz.Ft double 612a6bf1faSDavid Schultz.Fn acos "double x" 622a6bf1faSDavid Schultzare 632a6bf1faSDavid Schultz.Ft float 642a6bf1faSDavid Schultz.Fn acosf "float x" 652a6bf1faSDavid Schultzand 664e05ab77SRuslan Ermilov.Ft "long double" 672a6bf1faSDavid Schultz.Fn acosl "long double x" , 682a6bf1faSDavid Schultzrespectively. 693be0479bSDavid SchultzThe classification macros and silent order predicates are type generic and 703be0479bSDavid Schultzshould not be suffixed with 713be0479bSDavid Schultz.Ql f 723be0479bSDavid Schultzor 733be0479bSDavid Schultz.Ql l . 7452611c60SDavid Schultz.de Cl 7552611c60SDavid Schultz.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" 7652611c60SDavid Schultz.Em "Name Description" 7752611c60SDavid Schultz.. 7852611c60SDavid Schultz.Ss Algebraic Functions 7952611c60SDavid Schultz.Cl 8052611c60SDavid Schultzcbrt cube root 8152611c60SDavid Schultzfma fused multiply-add 8252611c60SDavid Schultzhypot Euclidean distance 8352611c60SDavid Schultzsqrt square root 844e05ab77SRuslan Ermilov.El 853be0479bSDavid Schultz.Ss Classification Macros 8652611c60SDavid Schultz.Cl 8752611c60SDavid Schultzfpclassify classify a floating-point value 8852611c60SDavid Schultzisfinite determine whether a value is finite 8952611c60SDavid Schultzisinf determine whether a value is infinite 9052611c60SDavid Schultzisnan determine whether a value is \*(Na 9152611c60SDavid Schultzisnormal determine whether a value is normalized 9252611c60SDavid Schultz.El 9352611c60SDavid Schultz.Ss Exponent Manipulation Functions 9452611c60SDavid Schultz.Cl 9552611c60SDavid Schultzfrexp extract exponent and mantissa 9652611c60SDavid Schultzilogb extract exponent 9752611c60SDavid Schultzldexp multiply by power of 2 9832948b81SBruce Evanslogb extract exponent 9952611c60SDavid Schultzscalbln adjust exponent 10052611c60SDavid Schultzscalbn adjust exponent 10152611c60SDavid Schultz.El 10252611c60SDavid Schultz.Ss Extremum- and Sign-Related Functions 10352611c60SDavid Schultz.Cl 10452611c60SDavid Schultzcopysign copy sign bit 10552611c60SDavid Schultzfabs absolute value 10652611c60SDavid Schultzfdim positive difference 10752611c60SDavid Schultzfmax maximum function 10852611c60SDavid Schultzfmin minimum function 10952611c60SDavid Schultzsignbit extract sign bit 11052611c60SDavid Schultz.El 1113be0479bSDavid Schultz.Ss Not a Number Functions 1123be0479bSDavid Schultz.Cl 1133be0479bSDavid Schultznan generate a quiet \*(Na 1143be0479bSDavid Schultz.El 11552611c60SDavid Schultz.Ss Residue and Rounding Functions 11652611c60SDavid Schultz.Cl 11752611c60SDavid Schultzceil integer no less than 11852611c60SDavid Schultzfloor integer no greater than 11952611c60SDavid Schultzfmod positive remainder 12052611c60SDavid Schultzllrint round to integer in fixed-point format 12152611c60SDavid Schultzllround round to nearest integer in fixed-point format 12252611c60SDavid Schultzlrint round to integer in fixed-point format 12352611c60SDavid Schultzlround round to nearest integer in fixed-point format 12452611c60SDavid Schultzmodf extract integer and fractional parts 12552611c60SDavid Schultznearbyint round to integer (silent) 12652611c60SDavid Schultznextafter next representable value 12715a53f77SDavid Schultznexttoward next representable value 12852611c60SDavid Schultzremainder remainder 1293b9141eeSDavid Schultzremquo remainder with partial quotient 13052611c60SDavid Schultzrint round to integer 13152611c60SDavid Schultzround round to nearest integer 13252611c60SDavid Schultztrunc integer no greater in magnitude than 13352611c60SDavid Schultz.El 13452611c60SDavid Schultz.Pp 13552611c60SDavid SchultzThe 13652611c60SDavid Schultz.Fn ceil , 13752611c60SDavid Schultz.Fn floor , 13852611c60SDavid Schultz.Fn llround , 13952611c60SDavid Schultz.Fn lround , 14052611c60SDavid Schultz.Fn round , 14152611c60SDavid Schultzand 14252611c60SDavid Schultz.Fn trunc 14352611c60SDavid Schultzfunctions round in predetermined directions, whereas 14452611c60SDavid Schultz.Fn llrint , 14552611c60SDavid Schultz.Fn lrint , 14652611c60SDavid Schultzand 14752611c60SDavid Schultz.Fn rint 14852611c60SDavid Schultzround according to the current (dynamic) rounding mode. 14952611c60SDavid SchultzFor more information on controlling the dynamic rounding mode, see 15052611c60SDavid Schultz.Xr fenv 3 15152611c60SDavid Schultzand 15252611c60SDavid Schultz.Xr fesetround 3 . 15352611c60SDavid Schultz.Ss Silent Order Predicates 15452611c60SDavid Schultz.Cl 15552611c60SDavid Schultzisgreater greater than relation 15652611c60SDavid Schultzisgreaterequal greater than or equal to relation 15752611c60SDavid Schultzisless less than relation 15852611c60SDavid Schultzislessequal less than or equal to relation 15952611c60SDavid Schultzislessgreater less than or greater than relation 16052611c60SDavid Schultzisunordered unordered relation 16152611c60SDavid Schultz.El 16252611c60SDavid Schultz.Ss Transcendental Functions 16352611c60SDavid Schultz.Cl 16452611c60SDavid Schultzacos inverse cosine 16552611c60SDavid Schultzacosh inverse hyperbolic cosine 16652611c60SDavid Schultzasin inverse sine 16752611c60SDavid Schultzasinh inverse hyperbolic sine 16852611c60SDavid Schultzatan inverse tangent 16952611c60SDavid Schultzatanh inverse hyperbolic tangent 17052611c60SDavid Schultzatan2 atan(y/x); complex argument 17152611c60SDavid Schultzcos cosine 17252611c60SDavid Schultzcosh hyperbolic cosine 17352611c60SDavid Schultzerf error function 17452611c60SDavid Schultzerfc complementary error function 17552611c60SDavid Schultzexp exponential base e 17690232fdfSDavid Schultzexp2 exponential base 2 17752611c60SDavid Schultzexpm1 exp(x)\-1 17852611c60SDavid Schultzj0 Bessel function of the first kind of the order 0 17952611c60SDavid Schultzj1 Bessel function of the first kind of the order 1 18052611c60SDavid Schultzjn Bessel function of the first kind of the order n 18152611c60SDavid Schultzlgamma log gamma function 18252611c60SDavid Schultzlog natural logarithm 18352611c60SDavid Schultzlog10 logarithm to base 10 18452611c60SDavid Schultzlog1p log(1+x) 185177668d1SDavid Schultzlog2 base 2 logarithm 18652611c60SDavid Schultzpow exponential x**y 18752611c60SDavid Schultzsin trigonometric function 18852611c60SDavid Schultzsinh hyperbolic function 18952611c60SDavid Schultztan trigonometric function 19052611c60SDavid Schultztanh hyperbolic function 19152611c60SDavid Schultztgamma gamma function 19252611c60SDavid Schultzy0 Bessel function of the second kind of the order 0 19352611c60SDavid Schultzy1 Bessel function of the second kind of the order 1 19452611c60SDavid Schultzyn Bessel function of the second kind of the order n 19552611c60SDavid Schultz.El 19652611c60SDavid Schultz.Pp 197177668d1SDavid SchultzThe routines 198*63687c8bSDavid Schultzin this section might not produce a result that is correctly rounded, 19990232fdfSDavid Schultzso reproducible results cannot be guaranteed across platforms. 20090232fdfSDavid SchultzFor most of these functions, however, incorrect rounding occurs 20190232fdfSDavid Schultzrarely, and then only in very-close-to-halfway cases. 2022a6bf1faSDavid Schultz.Sh SEE ALSO 2032a6bf1faSDavid Schultz.Xr fenv 3 , 2043be0479bSDavid Schultz.Xr ieee 3 , 2053be0479bSDavid Schultz.Xr tgmath 3 2062a6bf1faSDavid Schultz.Sh HISTORY 2072a6bf1faSDavid SchultzA math library with many of the present functions appeared in 2084e05ab77SRuslan Ermilov.At v7 . 2094e05ab77SRuslan ErmilovThe library was substantially rewritten for 2104e05ab77SRuslan Ermilov.Bx 4.3 2114e05ab77SRuslan Ermilovto provide 2122a6bf1faSDavid Schultzbetter accuracy and speed on machines supporting either VAX 2132a6bf1faSDavid Schultzor IEEE 754 floating-point. 2142a6bf1faSDavid SchultzMost of this library was replaced with FDLIBM, developed at Sun 2152a6bf1faSDavid SchultzMicrosystems, in 2162a6bf1faSDavid Schultz.Fx 1.1.5 . 21752611c60SDavid SchultzAdditional routines, including ones for 21852611c60SDavid Schultz.Vt float 21952611c60SDavid Schultzand 22052611c60SDavid Schultz.Vt long double 22152611c60SDavid Schultzvalues, were written for or imported into subsequent versions of FreeBSD. 22224a0682cSRuslan Ermilov.Sh BUGS 22315a53f77SDavid SchultzThe 224177668d1SDavid Schultz.Fn cbrt 225177668d1SDavid Schultzfunction and many of the transcendental functions 226177668d1SDavid Schultzare not available in their 22724a0682cSRuslan Ermilov.Vt "long double" 22824a0682cSRuslan Ermilovvariants. 22924a0682cSRuslan Ermilov.Pp 23090232fdfSDavid SchultzMany of the routines to compute transcendental functions produce 23190232fdfSDavid Schultzinaccurate results in other than the default rounding mode. 23290232fdfSDavid Schultz.Pp 233177668d1SDavid SchultzOn the i386 platform, trigonometric argument reduction is not 234*63687c8bSDavid Schultzperformed accurately for huge arguments, resulting in 235*63687c8bSDavid Schultzlarge errors 236177668d1SDavid Schultzfor such arguments to 23724a0682cSRuslan Ermilov.Fn cos , 23824a0682cSRuslan Ermilov.Fn sin , 23924a0682cSRuslan Ermilovand 24024a0682cSRuslan Ermilov.Fn tan . 241