Linux 常用C函数(常用数学函数篇1)

Linux 常用C函数(常用数学函数篇1)
2007-03-22 11:39
 
abs(计算整型数的绝对值)
相关函数
labs, fabs
表头文件
#include<stdlib.h>
定义函数
int abs (int j)
函数说明
abs()用来计算参数j的绝对值,然后将结果返回。
返回值
返回参数j的绝对值结果。
范例
#ingclude <stdlib.h>
main(){
int ansert;
answer = abs(-12);
printf("|-12| = %d/n", answer);
}
执行
|-12| = 12
 



acos(取反余弦函数数值)
相关函数
asin , atan , atan2 , cos , sin , tan
表头文件
#include <math.h>
定义函数
double acos (double x);
函数说明
acos()用来计算参数x的反余弦值,然后将结果返回。参数x范围为-1至1之间,超过此范围则会失败。
返回值
返回0至PI之间的计算结果,单位为弧度,在函数库中角度均以弧度来表示。
错误代码
EDOM参数x超出范围。
附加说明
使用GCC编译时请加入-lm。
范例
#include <math.h>
main (){
double angle;
angle = acos(0.5);
printf("angle = %f/n", angle);
}
执行
angle = 1.047198
 



asin(取反正弦函数值)
相关函数
acos , atan , atan2 , cos , sin , tan
表头文件
#include <math.h>
定义函数
double asin (double x)
函数说明
asin()用来计算参数x的反正弦值,然后将结果返回。参数x范围为-1至1之间,超过此范围则会失败。
返回值
返回-PI/2之PI/2之间的计算结果。
错误代码
EDOM参数x超出范围
附加说明
使用GCC编译时请加入-lm
范例
#include<math.h>
main()
{
double angle;
angle = asin (0.5);
printf("angle = %f/n",angle);
}
执行
angle = 0.523599
 



atan(取反正切函数值)
相关函数
acos,asin,atan2,cos,sin,tan
表头文件
#include<math.h>
定义函数
double atan(double x);
函数说明
atan()用来计算参数x的反正切值,然后将结果返回。
返回值
返回-PI/2至PI/2之间的计算结果。
附加说明
使用GCC编译时请加入-lm
范例
#include<math.h>
main()
{
double angle;
angle =atan(1);
printf("angle = %f/n",angle);
}
执行
angle = 1.570796
 



atan2(取得反正切函数值)
相关函数
acos,asin,atan,cos,sin,tan
表头文件
#include<math.h>
定义函数
double atan2(double y,double x);
函数说明
atan2()用来计算参数y/x的反正切值,然后将结果返回。
返回值
返回-PI/2 至PI/2 之间的计算结果。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double angle;
angle = atan2(1,2);
printf("angle = %f/n", angle);
}
执行
angle = 0.463648
 



ceil(取不小于参数的最小整型数)
相关函数
fabs
表头文件
#include <math.h>
定义函数
double ceil (double x);
函数说明
ceil()会返回不小于参数x的最小整数值,结果以double形态返回。
返回值
返回不小于参数x的最小整数值。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double value[ ]={4.8,1.12,-2.2,0};
int i;
for (i=0;value[i]!=0;i++)
printf("%f=>%f/n",value[i],ceil(value[i]));
}
执行
4.800000=>5.000000
1.120000=>2.000000
-2.200000=>-2.000000
 



cos(取余玄函数值)
相关函数
acos,asin,atan,atan2,sin,tan
表头文件
#include<math.h>
定义函数
double cos(double x);
函数说明
cos()用来计算参数x 的余玄值,然后将结果返回。
返回值
返回-1至1之间的计算结果。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer = cos(0.5);
printf("cos (0.5) = %f/n",answer);
}
执行
cos(0.5) = 0.877583
 



cosh(取双曲线余玄函数值)
相关函数
sinh,tanh
表头文件
#include<math.h>
定义函数
double cosh(double x);
函数说明
cosh()用来计算参数x的双曲线余玄值,然后将结果返回。数学定义式为:(exp(x)+exp(-x))/2。
返回值
返回参数x的双曲线余玄值。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer = cosh(0.5);
printf("cosh(0.5) = %f/n",answer);
}
执行
cosh(0.5) = 1.127626
 



exp(计算指数)
相关函数
log,log10,pow
表头文件
#include<math.h>
定义函数
double exp(double x);
函数说明
exp()用来计算以e为底的x次方值,即ex值,然后将结果返回。
返回值
返回e的x次方计算结果。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer;
answer = exp (10);
printf("e^10 =%f/n", answer);
}
执行
e^10 = 22026.465795
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值