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. 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.Dd December 7, 2017 29.Dt MATH 3 30.Os 31.Sh NAME 32.Nm math 33.Nd "floating-point mathematical library" 34.Sh LIBRARY 35.Lb libm 36.Sh SYNOPSIS 37.In math.h 38.Sh DESCRIPTION 39The math library includes the following components: 40.Bl -column "<complex.h>" "polymorphic (type-generic) versions of functions" -compact -offset indent 41.In math.h Ta basic routines and real-valued functions 42.In complex.h Ta complex number support 43.In tgmath.h Ta polymorphic (type-generic) versions of functions 44.In fenv.h Ta routines to control rounding and exceptions 45.El 46The rest of this manual page describes the functions provided by 47.In math.h . 48Please consult 49.Xr complex 3 , 50.Xr tgmath 3 , 51and 52.Xr fenv 3 53for information on the other components. 54.Sh "LIST OF FUNCTIONS" 55Each of the following 56.Vt double 57functions has a 58.Vt float 59counterpart with an 60.Ql f 61appended to the name and a 62.Vt "long double" 63counterpart with an 64.Ql l 65appended. 66As an example, the 67.Vt float 68and 69.Vt "long double" 70counterparts of 71.Ft double 72.Fn acos "double x" 73are 74.Ft float 75.Fn acosf "float x" 76and 77.Ft "long double" 78.Fn acosl "long double x" , 79respectively. 80The classification macros and silent order predicates are type generic and 81should not be suffixed with 82.Ql f 83or 84.Ql l . 85.de Cl 86.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" 87.Em "Name Description" 88.. 89.Ss Algebraic Functions 90.Cl 91cbrt cube root 92fma fused multiply-add 93hypot Euclidean distance 94sqrt square root 95.El 96.Ss Classification Macros 97.Cl 98fpclassify classify a floating-point value 99isfinite determine whether a value is finite 100isinf determine whether a value is infinite 101isnan determine whether a value is \*(Na 102isnormal determine whether a value is normalized 103.El 104.Ss Exponent Manipulation Functions 105.Cl 106frexp extract exponent and mantissa 107ilogb extract exponent 108ldexp multiply by power of 2 109logb extract exponent 110scalbln adjust exponent 111scalbn adjust exponent 112.El 113.Ss Extremum- and Sign-Related Functions 114.Cl 115copysign copy sign bit 116fabs absolute value 117fdim positive difference 118fmax maximum function 119fmin minimum function 120signbit extract sign bit 121.El 122.Ss Not a Number Functions 123.Cl 124nan generate a quiet \*(Na 125.El 126.Ss Residue and Rounding Functions 127.Cl 128ceil integer no less than 129floor integer no greater than 130fmod positive remainder 131llrint round to integer in fixed-point format 132llround round to nearest integer in fixed-point format 133lrint round to integer in fixed-point format 134lround round to nearest integer in fixed-point format 135modf extract integer and fractional parts 136nearbyint round to integer (silent) 137nextafter next representable value 138nexttoward next representable value 139remainder remainder 140remquo remainder with partial quotient 141rint round to integer 142round round to nearest integer 143trunc integer no greater in magnitude than 144.El 145.Pp 146The 147.Fn ceil , 148.Fn floor , 149.Fn llround , 150.Fn lround , 151.Fn round , 152and 153.Fn trunc 154functions round in predetermined directions, whereas 155.Fn llrint , 156.Fn lrint , 157and 158.Fn rint 159round according to the current (dynamic) rounding mode. 160For more information on controlling the dynamic rounding mode, see 161.Xr fenv 3 162and 163.Xr fesetround 3 . 164.Ss Silent Order Predicates 165.Cl 166isgreater greater than relation 167isgreaterequal greater than or equal to relation 168isless less than relation 169islessequal less than or equal to relation 170islessgreater less than or greater than relation 171isunordered unordered relation 172.El 173.Ss Transcendental Functions 174.Cl 175acos inverse cosine 176acosh inverse hyperbolic cosine 177asin inverse sine 178asinh inverse hyperbolic sine 179atan inverse tangent 180atanh inverse hyperbolic tangent 181atan2 atan(y/x); complex argument 182cos cosine 183cosh hyperbolic cosine 184erf error function 185erfc complementary error function 186exp exponential base e 187exp2 exponential base 2 188expm1 exp(x)\-1 189j0 Bessel function of the first kind of the order 0 190j1 Bessel function of the first kind of the order 1 191jn Bessel function of the first kind of the order n 192lgamma log gamma function 193log natural logarithm 194log10 logarithm to base 10 195log1p log(1+x) 196log2 base 2 logarithm 197pow exponential x**y 198sin trigonometric function 199sinh hyperbolic function 200tan trigonometric function 201tanh hyperbolic function 202tgamma gamma function 203y0 Bessel function of the second kind of the order 0 204y1 Bessel function of the second kind of the order 1 205yn Bessel function of the second kind of the order n 206.El 207.Pp 208The routines 209in this section might not produce a result that is correctly rounded, 210so reproducible results cannot be guaranteed across platforms. 211For most of these functions, however, incorrect rounding occurs 212rarely, and then only in very-close-to-halfway cases. 213.Sh SEE ALSO 214.Xr complex 3 , 215.Xr fenv 3 , 216.Xr ieee 3 , 217.Xr qmath 3 , 218.Xr tgmath 3 219.Sh HISTORY 220A math library with many of the present functions appeared in 221.At v7 . 222The library was substantially rewritten for 223.Bx 4.3 224to provide 225better accuracy and speed on machines supporting either VAX 226or IEEE 754 floating-point. 227Most of this library was replaced with FDLIBM, developed at Sun 228Microsystems, in 229.Fx 1.1.5 . 230Additional routines, including ones for 231.Vt float 232and 233.Vt long double 234values, were written for or imported into subsequent versions of FreeBSD. 235.Sh BUGS 236Many of the routines to compute transcendental functions produce 237inaccurate results in other than the default rounding mode. 238.Pp 239On the i386 platform, trigonometric argument reduction is not 240performed accurately for huge arguments, resulting in 241large errors 242for such arguments to 243.Fn cos , 244.Fn sin , 245and 246.Fn tan . 247