3.3. Mathematical FunctionsΒΆ
The math library has several functions to do mathematical
calculations. Except for pow()
, each of these programs takes a
single double variable. The following sample of math functions
all return a double.
sqrt(x)
pow(x,y)
exp(x)
fabs(x)
log(x)
log10(x)
sin(x)
,cos(x)
,tan(x)
Trig functions, x is in radians.
The following file lists more math functions and definitions.
math_h.txt
Additional documentation may be found by searching the Internet or a variety of other sources of documentation.
Note
To use the math functions On Unix platforms, in addition to including the
math.h
header file in the program it is necessary and to link in the
math library with the -lm
option to the compiler.
#include <stdio.h>
#include <math.h>
int main(void)
{
printf("%6.3lf\t %6.3lf\t %6.3lf\n",
exp(1.0), log(2.72), log10(100.0));
return 0;
}
285 hudson:~> gcc -lm test.c
286 hudson:~> ./a.out
2.718 1.001 2.000