常用数学函数篇abs acos asin atan ceil cos exp frexp ldexp log pow sin sinh sqrt tan tanh
abs(计算整型数的绝对值)
相关函数
labs, fabs
表头文件
#include<stdlib.h>
定义函数
int abs (int j)
函数说明
abs()用来计算参数j的绝对值,然后将结果返回。
返回值
返回参数j的绝对值结果。
范例
#ingclude <stdlib.h>
main(){
int ansert;
answer = abs(-);
printf("|-12| = %d\n", answer);
}
执行
|-| =
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();
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/ 至PI/ 之间的计算结果。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double angle;
angle = atan2(,);
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()
{
};
int i;
;value[i]!=;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))/。
返回值
返回参数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 ();
printf("e^10 =%f\n", answer);
}
执行
e^ = 22026.465795
frexp(将浮点型数分为底数与指数)
相关函数
ldexp,modf
表头文件
#include<math.h>
定义函数
double frexp( double x, int *exp);
函数说明
frexp()用来将参数x 的浮点型数切割成底数和指数。底数部分直接返回,指数部分则借参数exp 指针返回,将返回值乘以2 的exp次方即为x的值。
返回值
返回参数x的底数部分,指数部分则存于exp指针所指的地址。
附加说明
使用GCC编译时请加入-lm。
范例
#include <math.h>
main()
{
int exp;
double fraction;
fraction = frexp (,&exp);
printf("exp = %d\n",exp);
printf("fraction = %f\n", fraction);
}
执行
exp =
fraction = 0.500000 /* 0.5*(2^11)=1024*/
ldexp(计算2的次方值)
相关函数
frexp
表头文件
#include<math.h>
定义函数
double ldexp(double x,int exp);
函数说明
ldexp()用来将参数x乘上2的exp次方值,即x*2exp。
返回值
返回计算结果。
附加说明
使用GCC编译时请加入-lm。
范例:
/* 计算3*(2^2)=12 */
#include<math.h>
main()
{
int exp;
double x,answer;
answer = ldexp(,);
printf("3*2^(2) = %f\n",answer);
}
执行
*^() = 12.000000
log(计算以e 为底的对数值)
相关函数
exp,log10,pow
表头文件
#include <math.h>
定义函数
double log (double x);
函数说明
log()用来计算以e为底的x 对数值,然后将结果返回。
返回值
返回参数x的自然对数值。
错误代码
EDOM 参数x为负数,ERANGE 参数x为零值,零的对数值无定义。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer;
answer = log ();
printf("log(100) = %f\n",answer);
}
执行
log() = 4.605170
log10(计算以10 为底的对数值)
相关函数
exp,log,pow
表头文件
#include<math.h>
定义函数
double log10(double x);
函数说明
log10()用来计算以10为底的x对数值,然后将结果返回。
返回值
返回参数x以10为底的对数值。
错误代码
EDOM参数x为负数。RANGE参数x为零值,零的对数值无定义。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer;
answer = log10();
printf("log10(100) = %f\n",answer);
}
执行
log10() = 2.000000
pow(计算次方值)
相关函数
exp,log,log10
表头文件
#include<math.h>
定义函数
double pow(double x,double y);
函数说明
pow()用来计算以x为底的y次方值,即xy值,然后将结果返回。
返回值
返回x的y次方计算结果。
错误代码
EDOM 参数x为负数且参数y不是整数。
附加说明
使用GCC编译时请加入-lm。
范例
#include <math.h>
main()
{
double answer;
answer =pow(,);
printf("2^10 = %f\n", answer);
}
执行
^ = 1024.000000
sin(取正玄函数值)
相关函数
acos,asin,atan,atan2,cos,tan
表头文件
#include<math.h>
定义函数
double sin(double x);
函数说明
sin()用来计算参数x的正玄值,然后将结果返回。
返回值
返回- 至1之间的计算结果。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer = sin (0.5);
printf("sin(0.5) = %f\n",answer);
}
执行
sin(0.5) = 0.479426
sinh(取双曲线正玄函数值)
相关函数
cosh,tanh
表头文件
#include<math.h>
定义函数
double sinh( double x);
函数说明
sinh()用来计算参数x的双曲线正玄值,然后将结果返回。数学定义式为:(exp(x)-exp(-x))/。
返回值
返回参数x的双曲线正玄值。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer = sinh (0.5);
printf("sinh(0.5) = %f\n",answer);
}
执行
sinh(0.5) = 0.521095
sqrt(计算平方根值)
相关函数
hypotq
表头文件
#include<math.h>
定义函数
double sqrt(double x);
函数说明
sqrt()用来计算参数x的平方根,然后将结果返回。参数x必须为正数。
返回值
返回参数x的平方根值。
错误代码
EDOM 参数x为负数。
附加说明
使用GCC编译时请加入-lm。
范例
/* 计算200的平方根值*/
#include<math.h>
main()
{
double root;
root = sqrt ();
printf("answer is %f\n",root);
}
执行
answer is 14.142136
tan(取正切函数值)
相关函数
atan,atan2,cos,sin
表头文件
#include <math.h>
定义函数
double tan(double x);
函数说明
tan()用来计算参数x的正切值,然后将结果返回。
返回值
返回参数x的正切值。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer = tan(0.5);
printf("tan (0.5) = %f\n",answer);
}
执行
tan(0.5) = 0.546302
tanh(取双曲线正切函数值)
相关函数
cosh,sinh
表头文件
#include<math.h>
定义函数
double tanh(double x);
函数说明
tanh()用来计算参数x的双曲线正切值,然后将结果返回。数学定义式为:sinh(x)/cosh(x)。
返回值
返回参数x的双曲线正切值。
附加说明
使用GCC编译时请加入-lm。
范例
#include<math.h>
main()
{
double answer = tanh(0.5);
printf("tanh(0.5) = %f\n",answer);
}
执行
tanh(0.5) = 0.462117
常用数学函数篇abs acos asin atan ceil cos exp frexp ldexp log pow sin sinh sqrt tan tanh的更多相关文章
- php常用数学函数
php常用数学函数1. bcadd 任意精度数的相加2. bcsub 任意精度数的减法3. bcmul 乘法, bcdiv除法 4. bcmod 取余数. (比%功能更强大)5. bcpow 幂函数运 ...
- VB.Net常用数学函数整理
System.Math 类中定义了用于数学计算的函数.Math 类包括三角函数.对数函数和其他常用数学函数.下列函数是在 System 名称空间的 Math 类中定义的函数. 注意:要使用这些函数 ...
- Delphi 常用函数(数学函数)round、trunc、ceil和floor
源:Delphi 常用函数(数学函数)round.trunc.ceil和floor Delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里 ...
- R语言常用数学函数
语言的数学运算和一些简单的函数整理如下: 向量可以进行那些常规的算术运算,不同长度的向量可以相加,这种情况下最短的向量将被循环使用. > x <- 1:4 > a <- 1 ...
- C语言常用数学函数及其用法
转自:http://blog.sina.com.cn/s/blog_8b5a0d0001011779.html 三角函数:(所有参数必须为弧度) 1.acos 函数申明:acos (double ...
- C/C++常用数学函数
math.h/cmath(C++)数学函数库 1 三角函数 double sin (double); double cos (double); double tan (double) ...
- ios math.h 常用数学函数
1. 三角函数 double sin (double);正弦 double cos (double);余弦 double tan (double);正切 2 .反三角函数 double as ...
- C语言入门(6)——C语言常用数学函数
在编码过程中会经遇到数学运算,幸运的是C语言提供了非常丰富的数学函数库. 在数学中使用函数有时候书写可以省略括号,而C语言要求一定要加上括号,例如sin(pi/2)这种形式.在C语言的术语中,pi/2 ...
- oracle常用数学函数
数学函数 ABS:(返回绝对值) --返回绝对值 select abs(-1.11) from dual; CEIL:(向上取整) --向上取整 select ceil(3.1415) from du ...
随机推荐
- 【LOJ】#2052. 「HNOI2016」矿区
题解 之前尝试HNOI2016的时候弃坑的一道,然后给补回来 (为啥我一些计算几何就写得好长,不过我写啥都长orz) 我们尝试给这个平面图分域,好把这个平面图转成对偶图 怎么分呢,我今天也是第一次会 ...
- docker 安装错误Transaction Check Error
安装docker提示:Transaction Check Error: file /usr/bin/docker from install of docker-io-1.7.1-2.el6.x86_6 ...
- tensorflow初始化参数内存占满问题
最近使用tensorflow构建了一个浅层的网络,初始化参数的时候发现两个1080ti 22G的显存马上占满 后来发现解决办法为:在创建session的时候把显存设置为自适应即可,如下 config ...
- 《Android源码设计模式》--状态模式--责任链模式--解释器模式--命令模式--观察者模式--备忘录模式--迭代器模式
[状态模式] No1: Wifi设置界面是一个叫做WifiSetting的Fragment实现的 No2: 在不同的状态下对于扫描Wifi这个请求的处理是完全不一样的.在初始状态下扫描请求被直接忽略, ...
- python脚本获取本机公网ip
1.获取公网IP地址方式,访问:http://txt.go.sohu.com/ip/soip 2.python脚本实现: #!/usr/bin/python # -*- coding:utf8 -*- ...
- 安卓RecylerView嵌套和事件处理
最近遇到了一个需求:RecylerView的某一项为listView,即listView嵌套,且要求内部ListView可以滑动,高度固定. 如果直接简单的写完,会发现有两个问题: 1.内部listV ...
- java 将class打包成jar包
一.进入到java jdk安装目录(用cmd命令进入) c:cd C:\Program Files\Java\jdk1.8.0_45\bin 二.运行打包命令(将D盘下com中的class 打包成xy ...
- 机器学习之路:tensorflow 深度学习中 分类问题的损失函数 交叉熵
经典的损失函数----交叉熵 1 交叉熵: 分类问题中使用比较广泛的一种损失函数, 它刻画两个概率分布之间的距离 给定两个概率分布p和q, 交叉熵为: H(p, q) = -∑ p(x) log q( ...
- Django-高级特性
分页 1.固定显示分页数目 2.点击相应分页取出对应数据 具体实现: from django.utils.safestring import mark_safe class Pagination(ob ...
- luoguP4696 [CEOI2011]Matching KMP+树状数组
可以非常轻易的将题意转化为有多少子串满足排名相同 注意到$KMP$算法只会在当前字符串的某尾添加和删除字符 因此,如果添加和删除后面的字符对于前面的字符没有影响时,我们可以用$KMP$来模糊匹配 对于 ...