# Mathematical Functions

The standard library provides many mathematical functions. Most of them operate on real or complex floating-point numbers. However, there are also several functions with integer types, such as the functions to generate random numbers.

#### Mathematical Functions for Integer Types

The math functions for the integer types are declared in the header stdlib.h. Two of these functions, abs( ) and div( ), are declared in three variants to operate on the three signed integer types int, long, and long long. As following table shows, the functions for the type long have names beginning with the letter l; those for long long with ll. Furthermore, the header inttypes.h declares function variants for the type intmax_t, with names that begin with imax.

Purpose Functions declared in stdlib.h Functions declared in stdint.h
Absolute value abs( ), labs( ), llabs( ) imaxabs( )
Division div( ), ldiv( ), lldiv( ) imaxdiv( )
Random numbers rand( ), srand( )

#### Functions for real and complex floating-point types

Mathematical function C functions in math.h C functions in complex.h
Trigonometry sin( ), cos( ), tan( ), asin( ), acos( ), atan( ) csin( ), ccos( ), ctan( ) casin( ), cacos( ), catan( )
Hyperbolic trigonometry sinh( ), cosh( ), tanh( ), asinh( ), acosh( ), atanh( )

csinh( ), ccosh( ), ctanh( ), casinh( ), cacosh( ), catanh( )

Exponential function exp( ) cexp( )
Natural logarithm log( ) clog( )
Powers, square root pow( ), sqrt( ) cpow( ), csqrt( )
Absolute value fabs( ) cabs( )

#### Functions for real floating-point types

Mathematical function C function
Arctangent of a quotient atan2( )
Exponential functions exp2( ), expm1( ), frexp( ), ldexp( ), scalbn( ), scalbln( )
Logarithmic functions log10( ), log2( ), log1p( ), logb( ), ilogb( )
Roots cbrt( ), hypot( )
Error functions for normal distributions erf( ), erfc( )
Gamma function tgamma( ), lgamma( )
Remainder fmod( ), remainder( ), remquo( )
Separate integer and fractional parts modf( )
Next integer ceil( ), floor( )
Next representable number nextafter( ), nexttoward( )
Rounding functions trunc( ), round( ), lround( ), llround( ), nearbyint( ), rint( ), lrint( ), llrint( )
Positive difference fdim( )
Minimum and maximum fmin( ), fmax( )
Assign one number’s sign to another copysign( )
Generate a NaN nan( )

#### Functions for complex floating-point types

Mathematical function C function
Isolate real and imaginary parts creal( ), cimag( )
Argument (the angle in polar coordinates) carg( )
Conjugate conj( )
Project onto the Riemann sphere cproj( )
Share