9.6 Mathematics (<math.h>)

The <math.h> header file defines one macro and several mathematical functions. The functions take double arguments and return double-precision values.

The behavior of the functions in this header is defined for all representable values of their input arguments. Each function executes as if it were a single operation, without generating any externally visible exceptions.

For all functions, a domain error occurs if an input argument is outside the domain over which the mathematical function is defined. The description of each function lists any domain errors. On a domain error, the function returns an implementation- defined value; the value of the EDOM macro is stored in errno .

For all functions, a range error occurs if the result of the function cannot be represented as a double value. If the result overflows (the magnitude of the result is so large that it cannot be represented in an object of the specified type), the function returns the value of the macro HUGE_ VAL , with the same sign (except for the tan function) as the correct value of the function; the value of the ERANGE macro is stored in errno . If the result underflows (the magnitude of the result is so small that it cannot be represented in an object of the specified type), the function returns 0; whether the value of the ERANGE macro is stored in errno is implementation-defined.

Macros

HUGE_VAL


Expands to a positive double expression.

Trigonometric Functions

double acos(double x);


Returns the value, in radians, of the arc cosine of x in the range [0,]. A domain error occurs for arguments not in the interval [-1,+1].

double asin(double x);


Returns the value, in radians, of the arc sine of x in the range [-/2,+/2]. A domain error occurs for arguments not in the interval [-1,+1].

double atan(double x);


Returns the value, in radians, of the arc tangent of x in the range [-/2,+/2].

double atan2(double y, double x);


Returns the value, in radians, of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value. The value returned is in the range [-,+]. A domain error may occur if both arguments are 0.

double cos(double x);


Returns the value, in radians, of the cosine of x.

double sin(double x);


Returns the value, in radians, of the sine of x.

double tan(double x);


Returns the value, in radians, of the tangent of x.

Hyperbolic Functions

double cosh(double x);


Returns the value of the hyperbolic cosine of x. A range error occurs if the magnitude of x is too large.

double sinh(double x);


Returns the value of the hyperbolic sine of x. A range error occurs if the magnitude of x is too large.

double tanh(double x);


Returns the value of the hyperbolic tangent of x.

Exponential and Logarithmic Functions

double exp(double x);


Returns the value of the exponential function of x. A range error occurs if the magnitude of x is too large.

double frexp(double value, int *eptr);


Breaks the floating-point number value into a normalized fraction in the interval [1/2, 1) or 0, which it returns, and an integral power of 2, which it stores in the int object pointed to by eptr. If value is 0, both parts of the result are 0.

double ldexp(double x, int exp);


Multiplies a floating-point number by an integral power of 2, and returns the value x x 2[exp]. A range error may occur.

double log(double x);


Returns the natural logarithm of x. A domain error occurs if the argument is negative. A range error may occur if the argument is 0.

double log10(double x);


Returns the base-ten logarithm of x. A domain error occurs if x is negative. A range error may occur if x is 0.

double modf(double value, double *iptr);


Breaks the argument value into integral and fractional parts, each of which has the same sign as the argument. The modf function returns the signed fractional part and stores the integral part as a double in the object pointed to by iptr.

Power Functions

double pow(double x, double y);


Returns the value x[y]. A domain error occurs if x is negative and y is not an integral value. A domain error occurs if the result cannot be represented when x is 0 and y is less than or equal to 0. A range error may occur.

double sqrt(double x);


Returns the nonnegative square root of x. A domain error occurs if x is negative.

Nearest Integer, Absolute Value, and Remainder Functions

double ceil(double x);


Returns the smallest integral value not less than x.

double fabs(double x);


Returns the absolute value of a floating-point number x.

double floor(double x);


Returns the largest integral value not greater than x.

double fmod(double x, double y);


Computes the floating-point remainder of x /y. The fmod function returns the value x - i * y, for some integer i such that if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y. The function returns 0 if y is 0.


Previous Page | Next Page | Table of Contents | Index