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