D.2 The math.h Module
#include <math.h>
This module defines a collection of standard mathematical functions, which use floating-point values, and associated constants.
Constants
|
double M_PI An approximation for the value of . |
|
double M_PI_2 The value of divided by 2. |
|
double M_PI_4 The value of divided by 4. |
|
double M_E The value , which is the base of the natural logarithms. |
Functions
Power Functions
|
double sqrt(double x); Computes and returns the square root of
x. |
|
double pow(double x, double y); Computes and returns the power .
|
|
double cbrt(double x); Computes and returns the cube root of
x. |
|
double hypot(double x, double y); Computes and returns the hypotenuse of a right-angled triangle with sides of length and .
|
Trigonometric Functions
|
double sin(double x); Computes and returns the sine of an angle given in radians.
|
|
double cos(double x); Computes and returns the cosine of an angle given in radians.
|
|
double tan(double x); Computes and returns the tangent of an angle given in radians.
|
|
double asin(double x); Computes and returns the angle with the given sine.
|
|
double acos(double x); Computes and returns the angle with the given cosine.
|
|
double atan(double x); Computes and returns the angle with the given tangent.
|
|
double atan2(double y, double x); Computes and returns the angle with the given tangent, .
|
Rounding and Remainder Functions
|
double ceil(double x); Returns the smallest integer (as a floating-point value).
|
|
double floor(double x); Returns the largest integer (as a floating-point value).
|
|
double trunc(double x); Rounds toward zero.
|
|
double round(double x); Rounds to the nearest integer, away from zero.
|
Exponential and Logarithmic Functions
|
double log(double x);
|
|
double log10(double x);
|
|
double log2(double x);
|
|
double exp(double x);
|
|
double exp2(double x);
|
Absolute Functions
|
double fabs(double x);
|
Detailed Description
double sqrt(double x);
Computes and returns the square root of
x.- Parameters:
- x
- The numerical value for which the square root is to be computed.
- Returns:
-
The square root of
x.
double pow(double x, double y);
Computes and returns the power . If ,
y can be any value. If x is zero, y must be . If , y must be an integer.- Parameters:
- x
- The numerical value of the base that raised to a power.
- y
- The numerical value of the exponent to which the based is raised.
- Returns:
- The value of .
double cbrt(double x);
Computes and returns the cube root of
x.- Parameters:
- x
- The numerical value whose cubic root is computed.
- Returns:
-
The cube root of
xor .
double hypot(double x, double y);
Computes and returns the hypotenuse of a right-angled triangle with sides of length and .
- Parameters:
- x, y
- The numerical values corresponding to the legs of a right-angled triangle for which the hypotenuse is computed.
- Returns:
- The square root of .
double sin(double x);
Computes and returns the sine of an angle given in radians.
- Parameters:
- x
- An angle in radians.
- Returns:
- The sine of the argument.
double cos(double x);
Computes and returns the cosine of an angle given in radians.
- Parameters:
- x
- An angle in radians.
- Returns:
- The cosine of the argument.
double tan(double x);
Computes and returns the tangent of an angle given in radians.
- Parameters:
- x
- An angle in radians.
- Returns:
- The tangent of the argument.
double asin(double x);
Computes and returns the angle with the given sine.
- Parameters:
- x
- A floating-point value between -1 and 1.
- Returns:
- The arc sine of the argument in radians; the value is in the range .
double acos(double x);
Computes and returns the angle with the given cosine.
- Parameters:
- x
- A floating-point value between -1 and 1.
- Returns:
- The arc cosine of the argument in radians; the value is in the range .
double atan(double x);
Computes and returns the angle with the given tangent.
- Parameters:
- x
- A floating-point value.
- Returns:
- The arc tangent of the argument in radians; the value is in the range .
double atan2(double y, double x);
Computes and returns the angle with the given tangent, . The signs of the two arguments are used to determine the quadrant of the result. If x can equal zero, or if it is necessary to distinguish "northwest" from "southeast" and "northeast" from "southwest", use this function instead of
atan(y/x).- Parameters:
- x, y
- Two floating-point values.
- Returns:
- The angle, in radians, in the range .
double ceil(double x);
Returns the smallest integer (as a floating-point value).
- Parameters:
- x
- The floating-point value to round up.
- Returns:
- The smallest integral value that is not less than (as a floating-point value).
double floor(double x);
Returns the largest integer (as a floating-point value).
- Parameters:
- x
- The floating-point value to round down.
- Returns:
- The largest integral value less than or equal to (as a floating-point value).
double trunc(double x);
Rounds toward zero.
- Parameters:
- x
- The floating-point value to truncate.
- Returns:
- The nearest integer value that is not larger in magnitude than (as a floating-point value).
double round(double x);
Rounds to the nearest integer, away from zero.
- Parameters:
- x
- The floating-point value to round.
- Returns:
- The value of rounded to the nearest integer (as a floating-point value).
double log(double x);
- Parameters:
- x
double log10(double x);
- Parameters:
- x
double log2(double x);
- Parameters:
- x
double exp(double x);
- Parameters:
- x
double exp2(double x);
- Parameters:
- x
double fabs(double x);
- Parameters:
- x