1.绝对值

①函数原型: int abs(int x);

函数功能: 求整数x的绝对值

int number=-1234;

abs(number);

②函数原型:double fabs(double x);

函数功能:求浮点数x的绝对值.

float number=-1234.0;

fabs(number);

③函数原型:double cabs(struct complex znum)

函数功能:求复数的绝对值

参数说明:zuum为用结构struct complex表示的复数,定义如下:

struct complex

{

double m;

double n;

}

#include <stdio.h>

#include <math.h>

int main()

{

struct complex z;

double val;

z.x=2.0;

z.y=1.0;

val=cabs(z);

printf("The absolute value of %.2lfi %.2lfj is %.2lf",z.x,z.y,val);

return 0;

}

2.取整和取余

函数原型: double ceil(double num)

函数功能: 得到不小于num的最小整数

函数返回: 用双精度表示的最小整数

函数原型: double floor(double x);

函数功能: 求出不大于x的最大整数.

函数返回: 该整数的双精度实数

函数原型:double fmod (double x, double y); 返回两参数相除x/y的余数,符号与x相同。如果y为0,则结果与具体的额实现有关

int main()

{

double number=123.54;

double down,up;

down=floor(number);

up=ceil(number);

printf("original number %10.2lf",number);//123.54

printf("number rounded down %10.2lf",down); //123

printf("number rounded up %10.2lf",up); //124

return 0;

}

函数名称: modf

函数原型: double modf(double val,double *iptr);

函数功能: 把双精度数val分解为整数部分和小数部分,把整数部分存到iptr指向的单元.

函数返回: val的小数部分

参数说明: val 待分解的数

所属文件: <math.h>

使用范例:

#include <math.h>

#include <stdio.h>

int main()

{

double fraction,integer;

double number=100000.567;

fraction=modf(number,&integer);

printf("The whole and fractional parts of %lf are %lf and %lf",number,integer,fraction);

return 0;

}

6.指数和对数

函数原型: double exp(double x);

函数功能: 求e的x次幂

函数原型: double fmod(double x,double y);

函数功能: 求整数x/y的余数

函数原型: double frexp(double val,int *eptr);

函数功能: 把双精度数val分解为数字部分(尾数)x和以2为底的指数n,即val=x*2^n,n存放在eptr指向的变量中.

函数名称: pow

函数原型: double pow(double x,double y);

函数功能: 计算以x为底数的y次幂,即计算x^y的值.

函数返回: 计算结果

参数说明: x-底数,y-幂数

所属文件: <math.h>

使用范例:

#include <math.h>

#include <stdio.h>

int main()

{

double x=2.0,y=3.0;

printf("%lf raised to %lf is %lf",x,y,pow(x,y));

return 0;

}

函数原型: double sqrt(double x);

函数功能: 计算x的开平方.

函数返回: 计算结果

参数说明: x>=0

所属文件: <math.h>

使用范例:

#include <math.h>

#include <stdio.h>

int main()

{

double x=4.0,result;

result=sqrt(x);

printf("The square root of %lf is %lf",x,result);

return 0;

}

//

log(10) 以 e 为底的 10 的对数;

log10(100) 以 10 为底的 100 的对数;

如果要算别的对数 log(8) / log(2) 以 2 为底的 8 的对数;

如果要计算自然常数 e exp(1);

//

函数原型: double log(double x);

函数功能: 求logeX(e指的是以e为底),即计算x的自然对数(ln X)

函数返回: 计算结果

参数说明:

所属文件: <math.h>

使用范例:

#include <math.h>

#include <stdio.h>

int main()

{

double result;

double x=8.6872;

result=log(x);

printf("The natural log of %lf is %lf",x,result);

return 0;

}

函数名称: log10

函数原型: double log10(double x);

函数功能: 求log10x(10指的是以10为底).计算x的常用对数

函数返回: 计算结果

参数说明:

所属文件: <math.h>

使用范例:

#include <math.h>

#include <stdio.h>

int main()

{

double result;

double x=800.6872;

result=log10(x);

printf("The common log of %lf is %lf",x,result);

return 0;

}

#include <stdio.h>

#include <math.h>

int main()

{

double result;

double x=4.0;

result=exp(x);

printf("'e' raised to the power of %lf(e^%lf)=%lf",x,x,result);

return 0;

}

#include <math.h>

#include <stdio.h>

int main()

{

double mantissa,number;

int exponent;

number=8.0;

mantissa=frexp(number,&exponent);

printf("The number %lf is",number);

printf("%lf times two to the",mantissa);

printf("power of %d",exponent);

return 0;

}

7.标准化浮点数

函数原型:double modf (double x, double *ip);

函数功能:将参数的整数部分通过指针回传, 返回小数部分,整数部分保存在*ip中

函数原型: double ldexp(double x,int exponent)

函数功能: 计算x*2的exponent次幂,即2*pow(2,exponent)的数值

#include <stdio.h>

#include <math.h>

int main()

{

double value;

double x=2;

value=ldexp(x,3);

printf("The ldexp value is: %lf",value);

return 0;

}

8.多项式

函数名称: poly

函数原型: double poly(double x,int degree,double coeffs[])

函数功能: 计算多项式

函数返回: 多项式的计算结果

参数说明: 计算c[n]*x^n+c[n-1]x^n-1+.....+c[1]*x+c[0]

所属文件: <math.h>

#include <stdio.h>

#include <math.h>

int main()

{

double array[]={-1.0,5.0,-2.0,1.0};

double result;

result=poly(2.0,3,array);

printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf",result);

return 0;

}

9.数学错误计算处理

@函数名称: matherr

函数原型: int matherr(struct exception *e)

函数功能: 数学错误计算处理程序

函数返回:

参数说明: 该函数不能被直接调用,而是被库函数_matherr()调用

所属文件: <math.h>

#include<math.h>

int matherr(struct exception *a)

{

return 1;

}

C语言中math.h中常用的函数的更多相关文章

  1. python第二十课——math模块中常用的函数

    属性: e:自然数 pi:圆周率 函数: ceil():向上取整 floor():向下取整 sqrt():开平方根 radians():角度转弧度 degrees():弧度转角度 import mat ...

  2. C语言string.h中常用字符函数介绍

    原文:http://www.cnblogs.com/xuwenmin888/archive/2013/05/03/3057883.html strcpy 函数名: strcpy 功 能: 拷贝一个字符 ...

  3. go语言中strings包中的Trim函数的作用是什么

    答:Trim函数原型如下: func Trim(s string, cutset string) string 去掉字符串s中首部以及尾部与字符串cutset中每个相匹配的字符,如: s=" ...

  4. Mysql中常用的函数汇总

    Mysql中常用的函数汇总: 一.数学函数abs(x) 返回x的绝对值bin(x) 返回x的二进制(oct返回八进制,hex返回十六进制)ceiling(x) 返回大于x的最小整数值exp(x) 返回 ...

  5. SQL点滴30—SQL中常用的函数

    原文:SQL点滴30-SQL中常用的函数 该文章转载自http://www.cnblogs.com/jiajiayuan/archive/2011/06/16/2082488.html 别人的总结,很 ...

  6. string中常用的函数

    string中常用的函数 发现在string在处理这符串是很好用,就找了一篇文章放在这里了.. 用 string来代替char * 数组,使用sort排序算法来排序,用unique 函数来去重1.De ...

  7. jQuery中常用的函数方法

    jQuery中常用的函数方法总结 Ajax处理 load(url,[data],[callback]) url (String) : 待装入 HTML 网页网址. data (Map) : (可选) ...

  8. math.h中的常量

    类似于Matlab中经常用到的一些常量,C++里边也是有的.(经查源文件无意中看到) 写入如下代码: #include<iostream> #include<iomanip> ...

  9. 自己模拟实现math.h中的函数

    之前一直都很迷惑pow()函数时怎么实现的,对于整数次的幂我还能很容易做到,但是对于分数次幂就不是那么好做了.需要一些高等数学级数的知识. 我这里实现了求ln(x), pow(double x, do ...

随机推荐

  1. JavaScript 检验变量

    创建: 2019/02/20 迁入: 删除[WIP]标签(因为随时更新, 不存在完成不完成)   从[JavaScript 式与运算符]迁入typeof 更新: 2019/03/25 补充静态变量与参 ...

  2. SPOJ SERGRID 【BFS】

    思路: 在一个方向上走K步,基础BFS. 注意标记: 注意路径: PS:显著注释是记录路径. #include<bits/stdc++.h> using namespace std; co ...

  3. 从RAID看垂直伸缩到水平伸缩的演化

    磁盘的读写过程,最消耗时间的地方就是在磁盘中磁道寻址的过程,而一旦寻址完成,写入数据的速度很快. 连续写入:写入只寻址一次 存储位置与逻辑位置相邻 不用多次寻址 随机写入:每写一次 便寻址一次 增加了 ...

  4. [UE4]如何替换角色Mesh上的Material材质

    http://www.dawnarc.com/2016/10/ue4%E5%A6%82%E4%BD%95%E6%9B%BF%E6%8D%A2%E8%A7%92%E8%89%B2mesh%E4%B8%8 ...

  5. C++ com

    http://www.cnblogs.com/hlxs/p/3783920.html 昨天看了<COM本质论>的第一章"COM是一个更好的C++",觉得很有必要做一些笔 ...

  6. 配置vmware的固定ip

    一 .概述 为什么要配置固定IP呀?这个很容易解释啊,因为配置集群要设置固定IP(主结点需要管理子结点,通过固定IP识别机器),因为你访问虚拟机方便(不固定IP访问前还需要先查下虚拟机当前分配IP,比 ...

  7. 通过T4模板解决EF模型序列号的循环引用问题

    在模型的T4模板(如model.tt)中插入如下代码,这样由模板生成的模型代码中的导航属性将自动带有[JsonIgnore]标识,不会被序列化 1. 添加命名空间的引用 找到以下代码,添加using ...

  8. css 文本溢出时显示省略号

    .text-ellipsis { width:100px; height:60px; overflow: hidden;//隐藏滚动条 text-overflow:ellipsis; white-sp ...

  9. 5.用通配符进行过滤 ---SQL

    一.LIKE操作符 通配符(wildcard) 用来匹配值的一部分的特殊字符.搜索模式(search pattern)由字面值.通配符或两者组合构成的搜索条件.通配符本身实际上是SQL的WHERE子句 ...

  10. BestCoder Round #81 (div.2) 1003 String

    题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...