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. 反射学习:(System.Reflection)

    反射为了动态(运行时动态) 原理:读取metadata(?)   Assembly assembly = Assembly.Load("TestReflections");//反射 ...

  2. Kubernetes 集群日志管理

    Kubernetes 开发了一个 Elasticsearch 附加组件来实现集群的日志管理.这是一个 Elasticsearch.Fluentd 和 Kibana 的组合.Elasticsearch ...

  3. js上传文件到后台时序列化数据

    let fd = new FormData() // 定义传递的序列化对象,for (let i = 0; i < addArr.length; i++) { // addArr是选中文件的输入 ...

  4. Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

    Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key. 1.rea ...

  5. 洛谷P1013 进制位

    P1013 进制位 题目描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: + L K V E L L K V E K K V E KL V V E ...

  6. Java-GC-标记清除算法

    ## 前置知识 静态变量在类被加载的时候分配内存.当我们启动一个App的时候,系统会创建一个进程,此进程会加载一个JVM的实例,然后代码就运行在JVM之上.也就是说类在被加载的时候,静态变量 --- ...

  7. hdu5726-GCD-ST表+二分

    先用st表处理出所有l-r的GCD值,然后二分求得这些值一共出现了多少次. #include<bits/stdc++.h> #define inf 0x3f3f3f3f ; using n ...

  8. mysql 启动停止脚本 and mysql 迁移 导入和导出

    ####监控脚本 [root@pdb~]# more /opt/VRTS/scripts/mysql_monitor.sh#!/bin/shn=`ps -ef |grep mysql|grep &qu ...

  9. XML文件的一些操作

    XML 是被设计用来传输和存储数据的, XML 必须含有且仅有一个 根节点元素(没有根节点会报错) 源码下载 http://pan.baidu.com/s/1ge2lpM7 好了,我们 先看一个 XM ...

  10. Java基础(Java概述、环境变量、注释、关键字、标识符、常量)

    第1天 Java基础语法 今日内容介绍 u Java开发环境搭建 u HelloWorld案例 u 注释.关键字.标识符 u 数据(数据类型.常量) 第1章 Java开发环境搭建 1.1 Java概述 ...