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. echarts学习的一些笔记

    工具栏组件 Show 是否显示 Feature 具体显示的功能 saveAslmage  保存图片 Restore 还原 dataZoom  缩放视图 magicType 动态类型切换 toltip组 ...

  2. 读取静态Json文件

    创建web项目: string Json = string.Empty; string filePath = Server.MapPath("/***.json");//根目录下的 ...

  3. 使用Xilinx SDSoc在Xilinx zcu102开发板上编程HelloWorld

    关于Xilinx SDSoc的介绍我就不再复述了,我理解的也不一定准确,可以阅读官方文档了解SDSoc,你可以把它理解为一个集成开发环境 (IDE),通过SDSoc我们能够简单快速的对Xilinx的开 ...

  4. 洛谷P1044 栈(Catalan数)

    P1044 栈 题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重要 ...

  5. 洛谷P3172 [CQOI2015]选数(容斥)

    传送门 首先,进行如下处理 如果$L$是$K$的倍数,那么让它变成$\frac{L}{K}$,否则变成$\frac{L}{K}+1$ 把$H$变成$\frac{H}{K}$ 那么,现在的问题就变成了在 ...

  6. from appium import webdriver 报错

    from appium import webdriver 报错 看看你的文件是不是就叫appium

  7. Jmeter跨线程组传参

      我们知道,同一线程组中可以通过“正则表达式提取器”获取其中一个取样器的响应结果中的参数,直接传给线程组中的其他取样器.但其他线程组中的取样器也想使用同样的参数时,无法直接获取.举个例子: 提取“登 ...

  8. MySQL索引原理与慢查询

    =========索引原理与慢查询======= 阅读目录 -     一.介绍 -     二.索引的原理 -     三.索引的数据结构 -     四.聚集索引与辅助索引 -     五.MyS ...

  9. 题解 poj1845 Sumdiv (数论) (分治)

    传送门 大意:求A^B的所有因子之和,并对其取模 9901再输出 (这题又调了半天,把n和项数弄混了QAQ) 根据算数基本定理:A=(p1^k1)*(p2^k2)*(p3^k3)*...*(pn^kn ...

  10. Hive进阶_Hive的表连接

    等值连接 select e.empno, d.deptno from emp e, dept d where e.deptno=d.deptno; 不等值连接 select e.empno, e.en ...