英文原文:http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html
原文作者:Eric Huss
中文译者:柳惊鸿 Poechant
版权声明:本文的原文版权归Eric Huss所有,中文译文版权归Poechant所有。转载请注明来自"柳大的CSDN博客":http://blog.csdn.net/poechant
7. math.h
数学头文件定义了很多数学函数。
宏:
HUGE_VAL
函数:
acos();
asin();
atan();
atan2();
ceil();
cos();
cosh();
exp();
fabs();
floor();
fmod();
frexp();
ldexp();
log();
log10();
modf();
pow();
sin();
sinh();
sqrt();
tan();
tanh();
7.1.错误条件
所有math.h函数产生错误的情形都是类似的。
当传递给函数的参数超出了函数要求的参数定义域时,变量errno被设置为EDOM。函数的返回值是依实现而定的。
当返回值太大而超出了double的数值范围时,函数返回宏值HUGE_VAL,并且设置变量errno为ERANGE来表示溢出。如果值太小以至于无法表示为double,则函数返回0。在这种情况下,errno是否被设置为ERANGE是依实现而定。
errno,EDOM,和ERANGE在头文件errno.h中定义。
注意在所有没有定义域限制的情形(即默认情况)下,参数的值被double类型的最大值和最小值所限制。
7.2.三角函数
7.2.1. acos
声明:
double acos(double x);
返回:
弧度值“x”的余弦值。
定义域和值域:
定义域为[-1, +1]。值域是[0, PI]。
7.2.2. asin
声明:
double asin(doublex);
返回:
弧度值“x”的反正弦值。
定义域和值域:
定义域为[-1, +1]。值域为[-PI/2, +PI/2]。
7.2.3. atan
声明:
double atan(double x);
返回:
弧度值“x”的反正切值。
定义域和值域:
定义域无限制。值域为[-PI/2, +PI/2]。
7.2.4. atan2
声明:
double atan2(doubly y, double x);
返回:
返回弧度值“y/x”的正负两种情况中符合值域范围的反正切值。
定义域和值域:
“y”和“x”都不能是0。值域为[-PI/2, +PI/2]。
7.2.5. cos
声明:
double cos(double x);
返回:
返回弧度值“x”的余弦值。
定义域和值域:
定义域无限制。值域为[-1, +1]。
7.2.6. cosh
声明:
double cosh(double x);
返回“x”的双曲余弦值。
定义域和值域:
无限制。
7.2.7. sin
声明:
double sin(double x);
返回弧度值“x”的正弦值。
定义域和值域:
无定义域限制,值域为[-1, +1]。
7.2.8. sinh
声明:
double sinh(double x);
返回“x”的双曲正弦值。
定义域和值域:
无。
7.2.9. tan
声明:
double tan(double x);
返回“x”弧度值的正切值。
定义域和值域:
无。
7.2.10. tanh
声明:
double tanh(double x);
返回:
“x”的双曲正切值。
定义域和值域:
定义域无限制。值域为[-1, +1]。
7.3. Exponential, Logarithmic, and Power Functions
7.3.1. exp
声明:
double exp(double x);
返回:
自然常熟“e”的“x”次幂。
定义域和值域:
无限制。
7.3.2. frexp
声明:
double frexp(double x, int *exponent);
“x”在frexp函数中会被分拆出科学记数法中的尾数和指数两部分。exponent指针所指向的值为指数。可表示为“x = 尾数 * 2^指数”。
返回:
返回尾数。另外“exponent”被设置为指数值。
定义域与值域:
尾数的范围是[0.5, 1)。
7.3.3. ldexp
声明:
double ldexp(double x, intexponent);
返回:
“x”乘以2的exponent次幂,即 x * 2 ^ exponent。
定义域和值域:
无限制。
7.3.4. log
声明:
double log(double x);
返回:
以自然常数“e”为底数的x的对数值,即x的自然对数。
定义域和值域:
无限制。
7.3.5. log10
声明:
double log10(double x);
返回:
以10为底数的“x”的对数值。
定义域和值域:
无限制。
7.3.6. modf
声明:
double modf(double x, double *integer);
“x”被拆分为整数部分和小数部分。
返回:
“x”小数部分,并且将integer所指的double数值设置为“x”的整数部分。
定义域和值域:
无限制。
7.3.7. pow
声明:
double pow(double x, double y);
返回:
“x”的“y”次幂。
定义域和值域:
如果“y”是一个大于0小于1的数,那么“x”不能为负值。如果“y”小于等于0,那么“x”不能为0。
7.3.8. sqrt
声明:
double sqrt(double x);
返回:
“x”的算数平方根。
定义域和值域:
参数为非负值。返回值总为正。
7.4.其他数学函数
7.4.1. ceil
声明:
double ceil(double x);
返回:
大于等于“x”的最小整数。
定义域和值域:
无限制。
7.4.2. fabs
声明:
double fabs(double x);
返回:
“x”的绝对值。
定义域和值域:
无定义域限制,而返回值总是正的。
7.4.3. floor
声明:
double floor(double x);
返回:
小于等于“x”的最大整数。
定义域和值域:
无限制。
7.4.4. fmod
声明:
double fmod(double x, double y);
返回:
“x”除以“y”所得的余数(模)。
定义域和值域:
值域无限制。如果返回值为0,则会产生范围错误,或者返回0值(具体依实现而定)。
该系列译文在持续更新中⋯⋯
C标准库参考指南系列译文(1)assert.h
C标准库参考指南系列译文(2)ctype.h
C标准库参考指南系列译文(3)errno.h
C标准库参考指南系列译文(4)float.h
C标准库参考指南系列译文(5)limits.h
C标准库参考指南系列译文(6)locale.h
C标准库参考指南系列译文(7)math.h
C标准库参考指南系列译文(8)setjmp.h
C标准库参考指南系列译文(9)signal.h
C标准库参考指南系列译文(10)stdarg.h
C标准库参考指南系列译文(11)stddef.h
C标准库参考指南系列译文(12)stdio.h(A)
版权声明:本文的原文版权归Eric Huss所有,中文译文版权归Poechant所有。转载请注明来自"柳大的CSDN博客":http://blog.csdn.net/poechant
-