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.\" 3. All advertising materials mentioning features or use of this software 133a8617a8SJordan K. Hubbard.\" must display the following acknowledgement: 143a8617a8SJordan K. Hubbard.\" This product includes software developed by the University of 153a8617a8SJordan K. Hubbard.\" California, Berkeley and its contributors. 163a8617a8SJordan K. Hubbard.\" 4. Neither the name of the University nor the names of its contributors 173a8617a8SJordan K. Hubbard.\" may be used to endorse or promote products derived from this software 183a8617a8SJordan K. Hubbard.\" without specific prior written permission. 193a8617a8SJordan K. Hubbard.\" 203a8617a8SJordan K. Hubbard.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 213a8617a8SJordan K. Hubbard.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 223a8617a8SJordan K. Hubbard.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 233a8617a8SJordan K. Hubbard.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 243a8617a8SJordan K. Hubbard.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 253a8617a8SJordan K. Hubbard.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 263a8617a8SJordan K. Hubbard.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 273a8617a8SJordan K. Hubbard.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 283a8617a8SJordan K. Hubbard.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 293a8617a8SJordan K. Hubbard.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 303a8617a8SJordan K. Hubbard.\" SUCH DAMAGE. 313a8617a8SJordan K. Hubbard.\" 323a8617a8SJordan K. Hubbard.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91 337f3dea24SPeter Wemm.\" $FreeBSD$ 343a8617a8SJordan K. Hubbard.\" 3590232fdfSDavid Schultz.Dd April 5, 2005 362a6bf1faSDavid Schultz.Dt MATH 3 372a6bf1faSDavid Schultz.Os 384e05ab77SRuslan Ermilov.if n \{\ 394e05ab77SRuslan Ermilov.char \[sr] "sqrt 404e05ab77SRuslan Ermilov.\} 412a6bf1faSDavid Schultz.Sh NAME 424e05ab77SRuslan Ermilov.Nm math 434e05ab77SRuslan Ermilov.Nd "floating-point mathematical library" 44dbc8f2b5SDavid Schultz.Sh LIBRARY 45dbc8f2b5SDavid Schultz.Lb libm 46dbc8f2b5SDavid Schultz.Sh SYNOPSIS 47dbc8f2b5SDavid Schultz.In math.h 482a6bf1faSDavid Schultz.Sh DESCRIPTION 49dbc8f2b5SDavid SchultzThese functions constitute the C math library. 502a6bf1faSDavid Schultz.Sh "LIST OF FUNCTIONS" 512a6bf1faSDavid SchultzEach of the following 522a6bf1faSDavid Schultz.Vt double 532a6bf1faSDavid Schultzfunctions has a 542a6bf1faSDavid Schultz.Vt float 552a6bf1faSDavid Schultzcounterpart with an 562a6bf1faSDavid Schultz.Ql f 572a6bf1faSDavid Schultzappended to the name and a 584e05ab77SRuslan Ermilov.Vt "long double" 592a6bf1faSDavid Schultzcounterpart with an 602a6bf1faSDavid Schultz.Ql l 612a6bf1faSDavid Schultzappended. 622a6bf1faSDavid SchultzAs an example, the 632a6bf1faSDavid Schultz.Vt float 642a6bf1faSDavid Schultzand 654e05ab77SRuslan Ermilov.Vt "long double" 662a6bf1faSDavid Schultzcounterparts of 672a6bf1faSDavid Schultz.Ft double 682a6bf1faSDavid Schultz.Fn acos "double x" 692a6bf1faSDavid Schultzare 702a6bf1faSDavid Schultz.Ft float 712a6bf1faSDavid Schultz.Fn acosf "float x" 722a6bf1faSDavid Schultzand 734e05ab77SRuslan Ermilov.Ft "long double" 742a6bf1faSDavid Schultz.Fn acosl "long double x" , 752a6bf1faSDavid Schultzrespectively. 7652611c60SDavid Schultz.de Cl 7752611c60SDavid Schultz. Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" 7852611c60SDavid Schultz.Em "Name Description" 7952611c60SDavid Schultz.. 8052611c60SDavid Schultz.Ss Algebraic Functions 8152611c60SDavid Schultz.Cl 8252611c60SDavid Schultzcbrt cube root 8352611c60SDavid Schultzfma fused multiply-add 8452611c60SDavid Schultzhypot Euclidean distance 8552611c60SDavid Schultzsqrt square root 864e05ab77SRuslan Ermilov.El 8752611c60SDavid Schultz.Ss Classification Functions 8852611c60SDavid Schultz.Cl 8952611c60SDavid Schultzfpclassify classify a floating-point value 9052611c60SDavid Schultzisfinite determine whether a value is finite 9152611c60SDavid Schultzisinf determine whether a value is infinite 9252611c60SDavid Schultzisnan determine whether a value is \*(Na 9352611c60SDavid Schultzisnormal determine whether a value is normalized 9452611c60SDavid Schultz.El 9552611c60SDavid Schultz.Ss Exponent Manipulation Functions 9652611c60SDavid Schultz.Cl 9752611c60SDavid Schultzfrexp extract exponent and mantissa 9852611c60SDavid Schultzilogb extract exponent 9952611c60SDavid Schultzldexp multiply by power of 2 10052611c60SDavid Schultzscalbln adjust exponent 10152611c60SDavid Schultzscalbn adjust exponent 10252611c60SDavid Schultz.El 10352611c60SDavid Schultz.Ss Extremum- and Sign-Related Functions 10452611c60SDavid Schultz.Cl 10552611c60SDavid Schultzcopysign copy sign bit 10652611c60SDavid Schultzfabs absolute value 10752611c60SDavid Schultzfdim positive difference 10852611c60SDavid Schultzfmax maximum function 10952611c60SDavid Schultzfmin minimum function 11052611c60SDavid Schultzsignbit extract sign bit 11152611c60SDavid Schultz.El 11252611c60SDavid Schultz.\" .Ss Not a Number 11352611c60SDavid Schultz.\" .Cl 11452611c60SDavid Schultz.\" nan return quiet \*(Na) 0 11552611c60SDavid Schultz.\" .El 11652611c60SDavid Schultz.Ss Residue and Rounding Functions 11752611c60SDavid Schultz.Cl 11852611c60SDavid Schultzceil integer no less than 11952611c60SDavid Schultzfloor integer no greater than 12052611c60SDavid Schultzfmod positive remainder 12152611c60SDavid Schultzllrint round to integer in fixed-point format 12252611c60SDavid Schultzllround round to nearest integer in fixed-point format 12352611c60SDavid Schultzlrint round to integer in fixed-point format 12452611c60SDavid Schultzlround round to nearest integer in fixed-point format 12552611c60SDavid Schultzmodf extract integer and fractional parts 12652611c60SDavid Schultznearbyint round to integer (silent) 12752611c60SDavid Schultznextafter next representable value 12815a53f77SDavid Schultznexttoward next representable value 12952611c60SDavid Schultzremainder remainder 1303b9141eeSDavid Schultzremquo remainder with partial quotient 13152611c60SDavid Schultzrint round to integer 13252611c60SDavid Schultzround round to nearest integer 13352611c60SDavid Schultztrunc integer no greater in magnitude than 13452611c60SDavid Schultz.El 13552611c60SDavid Schultz.Pp 13652611c60SDavid SchultzThe 13752611c60SDavid Schultz.Fn ceil , 13852611c60SDavid Schultz.Fn floor , 13952611c60SDavid Schultz.Fn llround , 14052611c60SDavid Schultz.Fn lround , 14152611c60SDavid Schultz.Fn round , 14252611c60SDavid Schultzand 14352611c60SDavid Schultz.Fn trunc 14452611c60SDavid Schultzfunctions round in predetermined directions, whereas 14552611c60SDavid Schultz.Fn llrint , 14652611c60SDavid Schultz.Fn lrint , 14752611c60SDavid Schultzand 14852611c60SDavid Schultz.Fn rint 14952611c60SDavid Schultzround according to the current (dynamic) rounding mode. 15052611c60SDavid SchultzFor more information on controlling the dynamic rounding mode, see 15152611c60SDavid Schultz.Xr fenv 3 15252611c60SDavid Schultzand 15352611c60SDavid Schultz.Xr fesetround 3 . 15452611c60SDavid Schultz.Ss Silent Order Predicates 15552611c60SDavid Schultz.Cl 15652611c60SDavid Schultzisgreater greater than relation 15752611c60SDavid Schultzisgreaterequal greater than or equal to relation 15852611c60SDavid Schultzisless less than relation 15952611c60SDavid Schultzislessequal less than or equal to relation 16052611c60SDavid Schultzislessgreater less than or greater than relation 16152611c60SDavid Schultzisunordered unordered relation 16252611c60SDavid Schultz.El 16352611c60SDavid Schultz.Ss Transcendental Functions 16452611c60SDavid Schultz.Cl 16552611c60SDavid Schultzacos inverse cosine 16652611c60SDavid Schultzacosh inverse hyperbolic cosine 16752611c60SDavid Schultzasin inverse sine 16852611c60SDavid Schultzasinh inverse hyperbolic sine 16952611c60SDavid Schultzatan inverse tangent 17052611c60SDavid Schultzatanh inverse hyperbolic tangent 17152611c60SDavid Schultzatan2 atan(y/x); complex argument 17252611c60SDavid Schultzcos cosine 17352611c60SDavid Schultzcosh hyperbolic cosine 17452611c60SDavid Schultzerf error function 17552611c60SDavid Schultzerfc complementary error function 17652611c60SDavid Schultzexp exponential base e 17790232fdfSDavid Schultzexp2 exponential base 2 17852611c60SDavid Schultzexpm1 exp(x)\-1 17952611c60SDavid Schultzj0 Bessel function of the first kind of the order 0 18052611c60SDavid Schultzj1 Bessel function of the first kind of the order 1 18152611c60SDavid Schultzjn Bessel function of the first kind of the order n 18252611c60SDavid Schultzlgamma log gamma function 18352611c60SDavid Schultzlog natural logarithm 18452611c60SDavid Schultzlog10 logarithm to base 10 18552611c60SDavid Schultzlog1p log(1+x) 18652611c60SDavid Schultz.\" log2 base 2 logarithm 18752611c60SDavid Schultzpow exponential x**y 18852611c60SDavid Schultzsin trigonometric function 18952611c60SDavid Schultzsinh hyperbolic function 19052611c60SDavid Schultztan trigonometric function 19152611c60SDavid Schultztanh hyperbolic function 19252611c60SDavid Schultztgamma gamma function 19352611c60SDavid Schultzy0 Bessel function of the second kind of the order 0 19452611c60SDavid Schultzy1 Bessel function of the second kind of the order 1 19552611c60SDavid Schultzyn Bessel function of the second kind of the order n 19652611c60SDavid Schultz.El 19752611c60SDavid Schultz.Pp 19852611c60SDavid SchultzUnlike the algebraic functions listed earlier, the routines 19990232fdfSDavid Schultzin this section may not produce a result that is correctly rounded, 20090232fdfSDavid Schultzso reproducible results cannot be guaranteed across platforms. 20190232fdfSDavid SchultzFor most of these functions, however, incorrect rounding occurs 20290232fdfSDavid Schultzrarely, and then only in very-close-to-halfway cases. 2032a6bf1faSDavid Schultz.Sh SEE ALSO 2042a6bf1faSDavid Schultz.Xr fenv 3 , 2052a6bf1faSDavid Schultz.Xr ieee 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 22490232fdfSDavid Schultz.Fn log2 22515a53f77SDavid Schultzand 2263b9141eeSDavid Schultz.Fn nan 22715a53f77SDavid Schultzfunctions are missing, and many functions are not available in their 22824a0682cSRuslan Ermilov.Vt "long double" 22924a0682cSRuslan Ermilovvariants. 23024a0682cSRuslan Ermilov.Pp 23190232fdfSDavid SchultzMany of the routines to compute transcendental functions produce 23290232fdfSDavid Schultzinaccurate results in other than the default rounding mode. 23390232fdfSDavid Schultz.Pp 23424a0682cSRuslan ErmilovOn some architectures, trigonometric argument reduction is not 23524a0682cSRuslan Ermilovperformed accurately, resulting in errors greater than 1 23624a0682cSRuslan Ermilov.Em ulp 23724a0682cSRuslan Ermilovfor large arguments to 23824a0682cSRuslan Ermilov.Fn cos , 23924a0682cSRuslan Ermilov.Fn sin , 24024a0682cSRuslan Ermilovand 24124a0682cSRuslan Ermilov.Fn tan . 242