math(3) BSD Library Functions Manual math(3)

## NAME

math-- mathematical library functions

## SYNOPSIS

#include<math.h>

## DESCRIPTION

The header file math.h provides function prototypes and macros for work- ing with floating point values. Each math.h function is provided in three variants: single, double and extended precision. The single and double precision variants operate on IEEE-754 single and double precision values, which correspond to the C typesfloatanddouble, respectively. On Intel Macs, the C typelongdoublecorresponds to 80-bit IEEE-754 dou- ble extended precision. On iOS devices using ARM processors,longdoubleis mapped todouble, as there is no hardware-supported wider type. Details of the floating point formats can be found via "man float". Users who need to repeatedly perform the same calculation on a large set of data will probably find that the vector math library (composed of vMathLib and vForce) yields better performance for their needs than sequential calls to the libm. Users who need to perform mathematical operations on complex floating- point numbers should consult the man pages for the complex portion of the math library, via "man complex".

## LIST OF FUNCTIONS

Each of the functions that use floating-point values are provided in sin- gle, double, and extended precision; the double precision prototypes are listed here. The man pages for the individual functions provide more details on their use, special cases, and prototypes for their single and extended precision versions.intfpclassify(double)intisfinite(double)intisinf(double)intisnan(double)intisnormal(double)intsignbit(double) These function-like macros are used to classify a single floating-point argument.doublecopysign(double,double)doublenextafter(double,double)copysign(x,y) returns the value equal in magnitude toxwith the sign ofy.nextafter(x,y) returns the next floating-point number afterxin the direction ofy. Both are correctly-rounded.doublenan(constchar*tag) Thenan() function returns a quiet NaN, without raising the invalid flag.doubleceil(double)doublefloor(double)doublenearbyint(double)doublerint(double)doubleround(double)longintlrint(double)longintlround(double)longlongintllrint(double)longlongintllround(double)doubletrunc(double) These functions provide various means to round floating-point values to integral values. They are correctly rounded.doublefmod(double,double)doubleremainder(double,double)doubleremquo(doublex,doubley,int*) These return a remainder of the division of x by y with an integral quo- tient.remquo() additionally provides access to a few lower bits of the quotient. They are correctly rounded.doublefdim(double,double)doublefmax(double,double)doublefmin(double,double)fmax(x,y) andfmin(x,y) return the maximum and minimum ofxandy, respectively.fdim(x,y) returns the positive difference ofxandy.Allarecorrectlyrounded.doublefma(doublex,doubley,doublez)fma(x,y,z) computes the value (x*y) + z as though without intermediate rounding. It is correctly rounded.doublefabs(double)doublesqrt(double)doublecbrt(double)doublehypot(double,double)fabs(x),sqrt(x), andcbrt(x) return the absolute value, square root, and cube root ofx, respectively.hypot(x,y) returns sqrt(x*x + y*y).fabs() andsqrt() are correctly rounded.doubleexp(double)doubleexp2(double)double__exp10(double)doubleexpm1(double)exp(x),exp2(x),__exp10(x), andexpm1(x) return e**x, 2**x, 10**x, and e**x - 1, respectively.doublelog(double)doublelog2(double)doublelog10(double)doublelog1p(double)log(x),log2(x), andlog10(x) return the natural, base-2, and base-10 logarithms ofx, respectively.log1p(x) returns the natural log of 1+x.doublelogb(double)intilogb(double)logb(x) andilogb(x) return the exponent ofx.doublemodf(double,double*)doublefrexp(double,int*)modf(x,&y) returns the fractional part ofxand stores the integral part iny.frexp(x,&n) returns the mantissa ofxand stores the exponent inn.Theyarecorrectlyrounded.doubleldexp(double,int)doublescalbn(double,int)doublescalbln(double,longint)ldexp(x,n),scalbn(x,n), andscalbln(x,n) return x*2**n. They are correctly rounded.doublepow(double,double)pow(x,y) returns x raised to the power y.doublecos(double)doublesin(double)doubletan(double)cos(x),sin(x), andtan(x) return the cosine, sine and tangent ofx, respectively. Note thatxis interpreted as specifying an angle in radi- ans.doublecosh(double)doublesinh(double)doubletanh(double)cosh(x),sinh(x), andtanh(x) return the hyperbolic cosine, hyperbolic sine and hyperbolic tangent ofx, respectively.doubleacos(double)doubleasin(double)doubleatan(double)doubleatan2(double,double)acos(x),asin(x), andatan(x) return the inverse cosine, inverse sine and inverse tangent ofx, respectively. Note that the result is an angle in radians.atan2(y,x) returns the inverse tangent of y/x in radians, with sign chosen according to the quadrant of (x,y).doubleacosh(double)doubleasinh(double)doubleatanh(double)acosh(x),asinh(x), andatanh(x) return the inverse hyperbolic cosine, inverse hyperbolic sine and inverse hyperbolic tangent ofx, respec- tively.doubletgamma(double)doublelgamma(double)tgamma(x) andlgamma(x) return the values of the gamma function and its logarithm evalutated atx, respectively.doublej0(double)doublej1(double)doublejn(int,double)doubley0(double)doubley1(double)doubleyn(int,double)j0(x),j1(x), andjn(x) return the values of the zeroth, first, and nth Bessel function of the first kind evaluated atx, respectively.y0(x),y1(x), andyn(x) return the values of the zeroth, first, and nth Bessel function of the second kind evaluated atx, respectively.doubleerf(double)doubleerfc(double)erf(x) anderfc(x) return the values of the error function and the com- plementary error function evaluated atx, respectively.

## MATHEMATICAL CONSTANTS

In addition to the functions listed above, math.h defines a number of useful constants, listed below. CONSTANT VALUE M_E base of natural logarithm, e M_LOG2E log2(e) M_LOG10E log10(e) M_LN2ln(2)M_LN10ln(10)M_PI pi M_PI_2 pi / 2 M_PI_4 pi / 4 M_1_PI 1 / pi M_2_PI 2 / pi M_2_SQRTPI 2 / sqrt(pi) M_SQRT2sqrt(2)M_SQRT1_2 sqrt(1/2)

## IEEE STANDARD 754 FLOATING-POINT ARITHMETIC

The libm functions declared in math.h provide mathematical library func- tions in single-, double-, and extended-precision IEEE-754 floating-point formats on Intel macs, and in single- and double-precision IEEE-754 floating-point formats on PowerPC macs.

## SEE ALSO

float(3),complex(3)

## STANDARDS

The <math.h> functions conform to the ISO/IEC 9899:2011 standard. BSD August 16, 2012 BSD

Mac OS X 10.9.1 - Generated Wed Jan 8 19:39:06 CST 2014