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