1.\" Copyright (c) 1985 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91 33.\" $FreeBSD: src/lib/msun/man/math.3,v 1.27 2005/11/17 13:00:00 ru Exp $ 34.\" 35.Dd November 6, 2005 36.Dt MATH 3 37.Os 38.if n \{\ 39.char \[sr] "sqrt 40.\} 41.Sh NAME 42.Nm math 43.Nd "floating-point mathematical library" 44.Sh LIBRARY 45.Lb libm 46.Sh SYNOPSIS 47.In math.h 48.Sh DESCRIPTION 49These functions constitute the C math library. 50.Sh "LIST OF FUNCTIONS" 51Each of the following 52.Vt double 53functions has a 54.Vt float 55counterpart with an 56.Ql f 57appended to the name and a 58.Vt "long double" 59counterpart with an 60.Ql l 61appended. 62As an example, the 63.Vt float 64and 65.Vt "long double" 66counterparts of 67.Ft double 68.Fn acos "double x" 69are 70.Ft float 71.Fn acosf "float x" 72and 73.Ft "long double" 74.Fn acosl "long double x" , 75respectively. 76.de Cl 77.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" 78.Em "Name Description" 79.. 80.Ss Algebraic Functions 81.Cl 82cbrt cube root 83fma fused multiply-add 84hypot Euclidean distance 85sqrt square root 86.El 87.Ss Classification Functions 88.Cl 89fpclassify classify a floating-point value 90isfinite determine whether a value is finite 91isinf determine whether a value is infinite 92isnan determine whether a value is \*(Na 93isnormal determine whether a value is normalized 94.El 95.Ss Exponent Manipulation Functions 96.Cl 97frexp extract exponent and mantissa 98ilogb extract exponent 99ldexp multiply by power of 2 100logb extract exponent 101scalbln adjust exponent 102scalbn adjust exponent 103.El 104.Ss Extremum- and Sign-Related Functions 105.Cl 106copysign copy sign bit 107fabs absolute value 108fdim positive difference 109fmax maximum function 110fmin minimum function 111signbit extract sign bit 112.El 113.\" .Ss Not a Number 114.\" .Cl 115.\" nan return quiet \*(Na) 0 116.\" .El 117.Ss Residue and Rounding Functions 118.Cl 119ceil integer no less than 120floor integer no greater than 121fmod positive remainder 122llrint round to integer in fixed-point format 123llround round to nearest integer in fixed-point format 124lrint round to integer in fixed-point format 125lround round to nearest integer in fixed-point format 126modf extract integer and fractional parts 127nearbyint round to integer (silent) 128nextafter next representable value 129nexttoward next representable value 130remainder remainder 131remquo remainder with partial quotient 132rint round to integer 133round round to nearest integer 134trunc integer no greater in magnitude than 135.El 136.Pp 137The 138.Fn ceil , 139.Fn floor , 140.Fn llround , 141.Fn lround , 142.Fn round , 143and 144.Fn trunc 145functions round in predetermined directions, whereas 146.Fn llrint , 147.Fn lrint , 148and 149.Fn rint 150round according to the current (dynamic) rounding mode. 151For more information on controlling the dynamic rounding mode, see 152.Xr fenv 3 153and 154.Xr fesetround 3 . 155.Ss Silent Order Predicates 156.Cl 157isgreater greater than relation 158isgreaterequal greater than or equal to relation 159isless less than relation 160islessequal less than or equal to relation 161islessgreater less than or greater than relation 162isunordered unordered relation 163.El 164.Ss Transcendental Functions 165.Cl 166acos inverse cosine 167acosh inverse hyperbolic cosine 168asin inverse sine 169asinh inverse hyperbolic sine 170atan inverse tangent 171atanh inverse hyperbolic tangent 172atan2 atan(y/x); complex argument 173cos cosine 174cosh hyperbolic cosine 175erf error function 176erfc complementary error function 177exp exponential base e 178exp2 exponential base 2 179expm1 exp(x)\-1 180j0 Bessel function of the first kind of the order 0 181j1 Bessel function of the first kind of the order 1 182jn Bessel function of the first kind of the order n 183lgamma log gamma function 184log natural logarithm 185log10 logarithm to base 10 186log1p log(1+x) 187.\" log2 base 2 logarithm 188pow exponential x**y 189sin trigonometric function 190sinh hyperbolic function 191tan trigonometric function 192tanh hyperbolic function 193tgamma gamma function 194y0 Bessel function of the second kind of the order 0 195y1 Bessel function of the second kind of the order 1 196yn Bessel function of the second kind of the order n 197.El 198.Pp 199Unlike the algebraic functions listed earlier, the routines 200in this section may not produce a result that is correctly rounded, 201so reproducible results cannot be guaranteed across platforms. 202For most of these functions, however, incorrect rounding occurs 203rarely, and then only in very-close-to-halfway cases. 204.Sh SEE ALSO 205.Xr fenv 3 , 206.Xr ieee 3 207.Sh HISTORY 208A math library with many of the present functions appeared in 209.At v7 . 210The library was substantially rewritten for 211.Bx 4.3 212to provide 213better accuracy and speed on machines supporting either VAX 214or IEEE 754 floating-point. 215Most of this library was replaced with FDLIBM, developed at Sun 216Microsystems, in 217.Fx 1.1.5 . 218Additional routines, including ones for 219.Vt float 220and 221.Vt long double 222values, were written for or imported into subsequent versions of FreeBSD. 223.Sh BUGS 224The 225.Fn log2 226and 227.Fn nan 228functions are missing, and many functions are not available in their 229.Vt "long double" 230variants. 231.Pp 232Many of the routines to compute transcendental functions produce 233inaccurate results in other than the default rounding mode. 234.Pp 235On some architectures, trigonometric argument reduction is not 236performed accurately, resulting in errors greater than 1 237.Em ulp 238for large arguments to 239.Fn cos , 240.Fn sin , 241and 242.Fn tan . 243