MATH(3) Library Functions Manual MATH(3)

mathmathematical library functions

#include <math.h>

The header file math.h provides function prototypes and macros for working 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 types float and double, respectively.

On Intel Macs, the C type long double corresponds to 80-bit IEEE-754 double extended precision. On iOS devices using ARM processors, long double is mapped to double, 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".

Each of the functions that use floating-point values are provided in single, 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.

int (double)
int (double)
int (double)
int (double)
int (double)
int (double)

These function-like macros are used to classify a single floating-point argument.

double (double, double)
double (double, double)

(x, y) returns the value equal in magnitude to x with the sign of y. (x, y) returns the next floating-point number after x in the direction of y. Both are correctly-rounded.

double (const char *tag)

The () function returns a quiet NaN, without raising the invalid flag.

double (double)
double (double)
double (double)
double (double)
double (double)
long int (double)
long int (double)
long long int (double)
long long int (double)
double (double)

These functions provide various means to round floating-point values to integral values. They are correctly rounded.

double (double, double)
double (double, double)
double remquo(double x, double y, int *)

These return a remainder of the division of x by y with an integral quotient. () additionally provides access to a few lower bits of the quotient. They are correctly rounded.

double (double, double)
double fmax(double, double)
double fmin(double, double)

(x, y) and (x, y) return the maximum and minimum of x and y, respectively. fdim(x, y) returns the positive difference of x and y. All are correctly rounded.

double (double x, double y, double z)

(x, y, z) computes the value (x*y) + z as though without intermediate rounding. It is correctly rounded.

double (double)
double (double)
double (double)
double (double, double)

(x), (x), and (x) return the absolute value, square root, and cube root of x, respectively. (x, y) returns sqrt(x*x + y*y). fabs() and sqrt() are correctly rounded.

double (double)
double (double)
double (double)
double (double)

(x), (x), (x), and (x) return e**x, 2**x, 10**x, and e**x - 1, respectively.

double (double)
double (double)
double (double)
double (double)

(x), (x), and (x) return the natural, base-2, and base-10 logarithms of x, respectively. (x) returns the natural log of 1+x.

double (double)
int (double)

(x) and (x) return the exponent of x.

double (double, double *)
double (double, int *)

(x, &y) returns the fractional part of x and stores the integral part in y. (x, &n) returns the mantissa of x and stores the exponent in n. They are correctly rounded.

double (double, int)
double (double, int)
double (double, long int)

(x, n), (x, n), and (x, n) return x*2**n. They are correctly rounded.

double (double, double)

(x,y) returns x raised to the power y.

double (double)
double (double)
double (double)

(x), (x), and (x) return the cosine, sine and tangent of x, respectively. Note that x is interpreted as specifying an angle in radians.

double (double)
double (double)
double (double)

(x), (x), and (x) return the hyperbolic cosine, hyperbolic sine and hyperbolic tangent of x, respectively.

double (double)
double (double)
double (double)
double (double, double)

(x), (x), and (x) return the inverse cosine, inverse sine and inverse tangent of x, respectively. Note that the result is an angle in radians. (y, x) returns the inverse tangent of y/x in radians, with sign chosen according to the quadrant of (x,y).

double (double)
double (double)
double (double)

(x), (x), and (x) return the inverse hyperbolic cosine, inverse hyperbolic sine and inverse hyperbolic tangent of x, respectively.

double (double)
double (double)

(x) and (x) return the values of the gamma function and its logarithm evalutated at x, respectively.

double (double)
double (double)
double (int, double)
double (double)
double (double)
double (int, double)

(x), (x), and (x) return the values of the zeroth, first, and nth Bessel function of the first kind evaluated at x, respectively. (x), (x), and (x) return the values of the zeroth, first, and nth Bessel function of the second kind evaluated at x, respectively.

double (double)
double (double)

(x) and (x) return the values of the error function and the complementary error function evaluated at x, respectively.

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_LN2	ln(2)
M_LN10	ln(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_SQRT2	sqrt(2)
M_SQRT1_2	sqrt(1/2)

The libm functions declared in math.h provide mathematical library functions 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.

float(3), complex(3)

The <math.h> functions conform to the ISO/IEC 9899:2011 standard.

August 16, 2012 macOS 15.2