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