C Programming/Further math

The  header contains prototypes for several functions that deal with mathematics. In the 1990 version of the ISO standard, only the  versions of the functions were specified; the 1999 version added the   and   versions. To use these math functions, you must link your program with the math library. For some compilers (including GCC), you must specify the additional parameter.

The math functions may produce one of two kinds of errors. Domain errors occur when the parameters to the functions are invalid, such as a negative number as a parameter to sqrt (the square root function). Range errors occur when the result of the function cannot be expressed in that particular floating-point type, such as pow(1000.0, 1000.0) if the maximum value of a double is around 10308.

The functions can be grouped into the following categories:

The and   functions
The  functions return the arccosine of their arguments in radians, and the   functions return the arcsine of their arguments in radians. All functions expect the argument in the range [-1,+1]. The arccosine returns a value in the range [0,π]; the arcsine returns a value in the range [-π/2,+π/2].

The and   functions
The  functions return the arctangent of their arguments in radians, and the   function return the arctangent of   in radians. The  functions return a value in the range [-π/2,+π/2] (the reason why ±π/2 are included in the range is because the floating-point value may represent infinity, and atan(±∞) = ±π/2); the   functions return a value in the range [-π,+π]. For, a domain error may occur if both arguments are zero.

The,, and   functions
The,  , and   functions return the cosine, sine, and tangent of the argument, expressed in radians.

Hyperbolic functions
The cosh, sinh and tanh functions compute the hyperbolic cosine, the hyperbolic sine, and the hyperbolic tangent of the argument respectively. For the hyperbolic sine and cosine functions, a range error occurs if the magnitude of the argument is too large.

The acosh functions compute the inverse hyperbolic cosine of the argument. A domain error occurs for arguments less than 1.

The asinh functions compute the inverse hyperbolic sine of the argument.

The atanh functions compute the inverse hyperbolic tangent of the argument. A domain error occurs if the argument is not in the interval [-1, +1]. A range error may occur if the argument equals -1 or +1.

The,, and   functions
The  functions compute the base-e exponential function of   (ex). A range error occurs if the magnitude of  is too large.

The  functions compute the base-2 exponential function of   (2x). A range error occurs if the magnitude of  is too large.

The  functions compute the base-e exponential function of the argument, minus 1. A range error occurs if the magnitude of  is too large.

The,,  ,  , and   functions
These functions are heavily used in software floating-point emulators, but are otherwise rarely directly called.

Inside the computer, each floating point number is represented by two parts: The value of a floating point number $$v$$ is $$v = {\rm significand} \times 2^{\rm exponent}$$.
 * The significand is either in the range [1/2, 1), or it equals zero.
 * The exponent is an integer.

The  functions break the argument floating point number   into those two parts, the exponent and significand. After breaking it apart, it stores the exponent in the  object pointed to by , and returns the significand. In other words, the value returned is a copy of the given floating point number but with an exponent replaced by 0. If  is zero, both parts of the result are zero.

The  functions multiply a floating-point number by a integral power of 2 and return the result. In other words, it returns copy of the given floating point number with the exponent increased by ex. A range error may occur.

The  functions break the argument   into integer and fraction parts, each of which has the same sign as the argument. They store the integer part in the object pointed to by  and return the fraction part. The  is a floating-point type, rather than an "int" type, because it might be used to store an integer like 1 000 000 000 000 000 000 000 which is too big to fit in an int.

The  and   compute   ×. is the base of the floating-point system; if it is 2, the functions are equivalent to.

Most C floating point libraries also implement the IEEE754-recommended nextafter, nextUp, and nextDown functions. 

The,,  , and   functions
The  functions compute the base-e natural logarithm of the argument and return the result. A domain error occurs if the argument is negative. A range error may occur if the argument is zero.

The  functions compute the base-e natural logarithm of one plus the argument and return the result. A domain error occurs if the argument is less than -1. A range error may occur if the argument is -1.

The  functions compute the common (base-10) logarithm of the argument and return the result. A domain error occurs if the argument is negative. A range error may occur if the argument is zero.

The  functions compute the base-2 logarithm of the argument and return the result. A domain error occurs if the argument is negative. A range error may occur if the argument is zero.

The and   functions
The  functions extract the exponent of   as a signed int value. If  is zero, they return the value  ; if   is infinite, they return the value  ; if   is not-a-number they return the value  ; otherwise, they are equivalent to calling the corresponding   function and casting the returned value to type. A range error may occur if  is zero. and  are macros defined in  ;   is a macro defined in.

The  functions extract the exponent of   as a signed integer value in floating-point format. If  is subnormal, it is treated as if it were normalized; thus, for positive finite , 1 ≤   ×   &lt;. is the radix for floating-point numbers, defined in the  header.

The functions
The  functions compute   raised to the power   and return the result. A domain error occurs if  is negative and   is not an integral value. A domain error occurs if the result cannot be represented when  is zero and   is less than or equal to zero. A range error may occur.

The functions
The  functions compute the positive square root of   and return the result. A domain error occurs if the argument is negative.

The functions
The  functions compute the cube root of   and return the result.

The functions
The  functions compute the square root of the sums of the squares of   and , without overflow or underflow, and return the result.

The and   functions
The  functions compute the smallest integral value not less than   and return the result; the   functions compute the largest integral value not greater than   and return the result.

The functions
The  functions compute the absolute value of a floating-point number   and return the result.

The functions
The  functions compute the floating-point remainder of   and return the value   - i * , for some integer i such that, if   is nonzero, the result has the same sign as   and magnitude less than the magnitude of. If  is zero, whether a domain error occurs or the   functions return zero is implementation-defined.

The,,  , and   functions
The  functions round their argument to an integer value in floating-point format, using the current rounding direction and without raising the "inexact" floating-point exception.

The  functions are similar to the   functions except that they can raise the "inexact" floating-point exception if the result differs in value from the argument.

The  and   functions round their arguments to the nearest integer value according to the current rounding direction. If the result is outside the range of values of the return type, the numeric result is undefined and a range error may occur if the magnitude of the argument is too large.

The,, and   functions
The  functions round the argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.

The  and   functions round the argument to the nearest integer value, rounding halfway cases away from zero, regardless of the current rounding direction. If the result is outside the range of values of the return type, the numeric result is undefined and a range error may occur if the magnitude of the argument is too large.

The functions
The  functions round their argument to the integer value in floating-point format that is nearest but no larger in magnitude than the argument.

The functions
The  functions compute the remainder   REM   as defined by IEC 60559. The definition reads, "When y ≠ 0, the remainder r = x REM y is defined regardless of the rounding mode by the mathematical reduction r = x - ny, where n is the integer nearest the exact value of x/y; whenever |n - x/y| = ½, then n is even. Thus, the remainder is always exact. If r = 0, its sign shall be that of x." This definition is applicable for all implementations.

The functions
The  functions return the same remainder as the   functions. In the object pointed to by, they store a value whose sign is the sign of  /  and whose magnitude is congruent modulo 2n to the magnitude of the integral quotient of  / , where n is an implementation-defined integer greater than or equal to 3.

Error and gamma functions
The  functions compute the error function of the argument $$\frac{2}{\sqrt{\pi}}\int_{0}^x e^{-t^2}\,\mathrm dt$$

The  functions compute the complimentary error function of the argument (that is, 1 - erf x). For the  functions, a range error may occur if the argument is too large.

The  functions compute the natural logarithm of the absolute value of the gamma of the argument (that is, loge|Γ(x)|). A range error may occur if the argument is a negative integer or zero.

The  functions compute the gamma of the argument (that is, Γ(x)). A domain error occurs if the argument is a negative integer or if the result cannot be represented when the argument is zero. A range error may occur.