头文件math.h中含有大量的数学函数声明。
数学函数
-----------------------------------------------------------------------------------------------------
函数 运算
-----------------------------------------------------------------------------------------------------
floor(x) 返回不大于x的double类型最大整数值
ceil(x) 返回不小于x的double类型最小整数值
fabs(x) 返回x的绝对值
log(x) 返回x的(以e为底)自然对数
log10(x) 返回x以10为底的对数
exp(x) 返回e的x次的值
sqrt(x) 返回x的平方根
pow(x,y) 返回x的y次
-------------------------------------------------------------------------------------------------------
测试的程序如下:
#include<stdio.h>
#include <math.h>
int main()
{
double x=2.5f;
double y=-2.5f;
printf("\n the floor is %lf and %lf",floor(x),floor(y));
printf("\n the ceil is %lf and %lf",ceil(x),ceil(y));
printf("\n the fabs is %lf and %lf",fabs(x),fabs(y));
printf("\n the log is %lf and %lf",log(x),log(100000));
printf("\n the log10 is %lf and %lf",log10(x),log10(100000));
printf("\n the exp is %lf and %lf",exp(x),exp(y));
printf("\n the sqrt is %lf and %lf",sqrt(x),sqrt(100));
return 0;
}
运行的结果如下:
the floor is 2.000000 and -3.000000
the ceil is 3.000000 and -2.000000
the fabs is 2.500000 and 2.500000
the log is 0.916291 and 11.512925
the log10 is 0.397940 and 5.000000
the exp is 12.182494 and 0.082085
the sqrt is 1.581139 and 10.000000