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 April 11, 2026 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 (legacy) 119fmaximum maximum function (prefers \*(Na) 120fmaximum_mag maximum magnitude (prefers \*(Na) 121fmaximum_num maximum function (avoids \*(Na) 122fmin minimum function (legacy) 123fminimum minimum function (prefers \*(Na) 124fminimum_mag minimum magnitude (prefers \*(Na) 125fminimum_num minimum function (avoids \*(Na) 126signbit extract sign bit 127.El 128.Ss Not a Number Functions 129.Cl 130nan generate a quiet \*(Na 131.El 132.Ss Residue and Rounding Functions 133.Cl 134ceil integer no less than 135floor integer no greater than 136fmod positive remainder 137llrint round to integer in fixed-point format 138llround round to nearest integer in fixed-point format 139lrint round to integer in fixed-point format 140lround round to nearest integer in fixed-point format 141modf extract integer and fractional parts 142nearbyint round to integer (silent) 143nextafter next representable value 144nexttoward next representable value 145remainder remainder 146remquo remainder with partial quotient 147rint round to integer 148round round to nearest integer 149trunc integer no greater in magnitude than 150.El 151.Pp 152The 153.Fn ceil , 154.Fn floor , 155.Fn llround , 156.Fn lround , 157.Fn round , 158and 159.Fn trunc 160functions round in predetermined directions, whereas 161.Fn llrint , 162.Fn lrint , 163and 164.Fn rint 165round according to the current (dynamic) rounding mode. 166For more information on controlling the dynamic rounding mode, see 167.Xr fenv 3 168and 169.Xr fesetround 3 . 170.Ss Silent Order Predicates 171.Cl 172isgreater greater than relation 173isgreaterequal greater than or equal to relation 174isless less than relation 175islessequal less than or equal to relation 176islessgreater less than or greater than relation 177isunordered unordered relation 178.El 179.Ss Transcendental Functions 180.Cl 181acos inverse cosine 182acosh inverse hyperbolic cosine 183asin inverse sine 184asinh inverse hyperbolic sine 185atan inverse tangent 186atanh inverse hyperbolic tangent 187atan2 atan(y/x); complex argument 188cos cosine 189cosh hyperbolic cosine 190erf error function 191erfc complementary error function 192exp exponential base e 193exp2 exponential base 2 194expm1 exp(x)\-1 195j0 Bessel function of the first kind of the order 0 196j1 Bessel function of the first kind of the order 1 197jn Bessel function of the first kind of the order n 198lgamma log gamma function 199log natural logarithm 200log10 logarithm to base 10 201log1p log(1+x) 202log2 base 2 logarithm 203pow exponential x**y 204sin trigonometric function 205sinh hyperbolic function 206tan trigonometric function 207tanh hyperbolic function 208tgamma gamma function 209y0 Bessel function of the second kind of the order 0 210y1 Bessel function of the second kind of the order 1 211yn Bessel function of the second kind of the order n 212.El 213.Pp 214The routines 215in this section might not produce a result that is correctly rounded, 216so reproducible results cannot be guaranteed across platforms. 217For most of these functions, however, incorrect rounding occurs 218rarely, and then only in very-close-to-halfway cases. 219.Sh SEE ALSO 220.Xr complex 3 , 221.Xr fenv 3 , 222.Xr ieee 3 , 223.Xr qmath 3 , 224.Xr tgmath 3 225.Sh HISTORY 226A math library with many of the present functions appeared in 227.At v7 . 228The library was substantially rewritten for 229.Bx 4.3 230to provide 231better accuracy and speed on machines supporting either VAX 232or IEEE 754 floating-point. 233Most of this library was replaced with FDLIBM, developed at Sun 234Microsystems, in 235.Fx 1.1.5 . 236Additional routines, including ones for 237.Vt float 238and 239.Vt long double 240values, were written for or imported into subsequent versions of FreeBSD. 241.Sh BUGS 242Many of the routines to compute transcendental functions produce 243inaccurate results in other than the default rounding mode. 244.Pp 245On the i386 platform, trigonometric argument reduction is not 246performed accurately for huge arguments, resulting in 247large errors 248for such arguments to 249.Fn cos , 250.Fn sin , 251and 252.Fn tan . 253