Chinaunix首页 | 论坛 | 博客
  • 博客访问: 444622
  • 博文数量: 72
  • 博客积分: 3186
  • 博客等级: 中校
  • 技术积分: 1039
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-07 16:53
文章分类

全部博文(72)

文章存档

2012年(1)

2011年(5)

2010年(10)

2009年(56)

我的朋友

分类: C/C++

2009-07-22 08:22:07



math.h
------------------------------------------------


math.h中定许了许多有用的数学常量。所有的都用'M_'开头的宏来定义。一般是double类型的。
# define M_E        2.7182818284590452354    /* e */
# define M_LOG2E    1.4426950408889634074    /* log_2 e */
# define M_LOG10E    0.43429448190325182765    /* log_10 e */
# define M_LN2        0.69314718055994530942    /* log_e 2 */
# define M_LN10        2.30258509299404568402    /* log_e 10 */
# define M_PI        3.14159265358979323846    /* pi */
# define M_PI_2        1.57079632679489661923    /* pi/2 */
# define M_PI_4        0.78539816339744830962    /* pi/4 */
# define M_1_PI        0.31830988618379067154    /* 1/pi */
# define M_2_PI        0.63661977236758134308    /* 2/pi */
# define M_2_SQRTPI    1.12837916709551257390    /* 2/sqrt(pi) */
# define M_SQRT2    1.41421356237309504880    /* sqrt(2) */
# define M_SQRT1_2    0.70710678118654752440    /* 1/sqrt(2) */


double sin(double x)
float sinf(float x)
long double sinl(long double x)
其中,x为弧度,返回值为-1~1.

double cos(double x)
float cosf(float x)
long double sinl(long double x)
其中,x为弧度,返回值为-1~1.

double tan(double x)
float tanf(float x)
long double tanl(long double x)
当x太靠近M_PI/2的奇数倍时,其值可能会溢出。


如果程序中需要同时计算sin和cos时,可以把它们放到一起计算而不需要分别调用sin cos两个函数。这样会更有效率。
void sincos(double x, double *sinx, double *cosx)
void sincosf(float x, float *sinx, float *cosx)
void sincosl(long double x, long double *sinx, long double *cosx)
以上这些函数返回值sin(x)的值在*sinx中,cos(x)的值在*cosx中,它们的范围都在-1~1之间。


下面为反正弦、反余弦、反正切。
double asin (double x)
float asinf (float x)
long double asinl (long double x)
返回值在(-pi/2, pi/2)之间, x的值在(-1, 1)之间


double acos (double x)
float acosf (float x)
long double acosl(long double x)
返回值在(0, pi)之间,x值在(-1, 1)之间


double atan (double x)
float atanf (float x)
long double atanl (long double x)
返回值在(-pi/2, pi/2)之间,x值无限制

double atan2 (double y, double x)
float atan2f (float y, float x)
long double atan2l(long double y, long double x)
计算y/x的反正切值。返回值在(-pi, pi)之间.x允许为0,如果x、y都为0,则返回0.
这个函数很方便,只要知道了y、x的值就可以直接算出弧度。



指数函数

double exp (double x)
float expf (float x)
long double expl (long double x)
计算以e为底的指数值,即e的x次方。注意参数太大会导致其溢出。


double exp2 (double x)
float exp2f (float x)
long double exp2l (long double x)
计算以2为底数的指数值,即2的x次方。相当于 exp (x * log (2))


double exp10 (doublex)
float exp10f (float x)
long double exp10l (long double x)
double pow10 (double x)
float pow10f (float x)
long double pow10l (long double x)
计算以10为底的指数值,即10的x次方,exp10 (x) 相当于 exp (x * log(10))



对数函数

double log (double x)
float logf (float x)
long double logl (long double x)
以e为底数的对数。
若x为负数,则为范围错误
x为0,返回负无穷
x太接近0,则可能会溢出

double log10 (double x)
float log10f (float x)
long double log10l (long double x)
以10为底的对数

double log2 (double x)
float log2f (float x)
long double log2l (long double x)
以2为底数

double logb (double x)
float logbf (float x)
long double logbl (long double x)
-----------------------------------------不知道这个什么意思

-------------------------
double pow (double base, double power)
float powf (float base, float power)
long double powl (long double base, long double power)
计算base的power次方
当base是负数且不是整型的时候,将得出复数,返回错误。


double sqrt (double x)
float sqrtf (float x)
long double sqrtl (long double x)
计算x的平方根。x为负数则报错。(虽然理论值为复数)


double cbrt (double x)
float cbrtf (float x)
long double cbrtl (long double x)
计算x的立方根。

double hypot (double x, double y)
float hypotf (float x, float y)
long double hypotl (long double x, long double y)
返回值为 sqrt(x*x + y*y),即计算原点到(x, y)的长度。用这个函数代替公式来计算长度非常方便且明智。


double expm1 (double x)
float expm1f (float x)
long double expm1l (long double x)
返回值 exp(x) - 1

注意:库中许多数学函数是存在误差的。

阅读(3113) | 评论(0) | 转发(0) |
0

上一篇:ctype.h

下一篇:C 除数为0

给主人留下些什么吧!~~