目录

1、三角函数 Trigonometric functions

1.1、 cos() 函数

1.2 sin() 正弦函数

1.3、 tan() 正切函数

1.4、 acos() 反余弦函数

1.5、asin() 反正弦函数

1.6、atan() 反正切函数

1.7、atan2() 带两个参数的反正切函数

2、双曲函数 Hyperbolic functions

2.1、双曲余弦函数

2.2、双曲正弦函数

2.3、双曲正切函数

3、指数函数与对数函数 Exponential and logarithmic functions

3.1、exp () 指数函数,以 e 为底数

3.2、frexp(param,n) 二进制浮点数表示方法 x=param*2^n

3.3、log(x) x的自然对数 (Natural logarithm of x)

3.4、log10() 常用对数,以10为底 ( Common logarithm of x )

3.5、modf() 返回x的小数部分,其符号与x相同 ,但是参数中可以添加整数部分的变量( The fractional part of x, with the same sign)

3.6、exp2() 返回2的x次方,2 raised to the power of x.

3.7、log2() x的二进制对数( The binary logarithm of x)

4、幂函数 Power functions

4.1、pow(base, power) 幂函数 The result of raising base to the power exponent

4.2、sqrt(x) 计算x的平方根

4.3、cbrt(x) 计算x的立方根

4.4、hypot(x,y) 计算直角三角形的斜边 ( The square root of (x^2+y^2) )

5、误差与伽马函数 Error and gamma functions

5.1、误差函数erf(x) ​

5.2、余差函数erfc(x) erfc(x) = 1-erf(x) 误差函数的补函数 ​

5.3、tgamma(x) 伽马函数 ( the gamma function ) ​

5.4、lgamma(x) log伽马函数 ( log-gamma function ) ​

6、四舍五入与余数函数Rounding and remainder functions

6.1、ceil(x) x上取整函数

6.2、floor(x) x的下取整函数

6.3、fmod(y, x) y/x的余数

6.4、round(x) x的四舍五入值 ​

7、绝对值、最小、最大 Absolute、Minimum, maximum

7.1、fabs(x) x的绝对值函数

7.2、abs(x) x的绝对值

7.3、fmax(x, y) 两个参数中的最大值 (The maximum numeric value of its arguments. Values among which the function selects a maximum )

7.4、fmin(x, y) 两个参数中的最小值


1、三角函数 Trigonometric functions

1.1、 cos() 函数

/* cos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* cos */
#define PI 3.14159265
int main ()
{double param, result;param = 60.0;result = cos ( param * PI / 180.0 );printf ("The cosine of %f degrees is %f.\n", param, result );return 0;
}

1.2 sin() 正弦函数

/* sin example */
#include <stdio.h>      /* printf */
#include <math.h>       /* sin */#define PI 3.14159265int main ()
{double param, result;param = 30.0;result = sin (param*PI/180);printf ("The sine of %f degrees is %f.\n", param, result );return 0;
}

1.3、 tan() 正切函数

/* tan example */
#include <stdio.h>      /* printf */
#include <math.h>       /* tan */#define PI 3.14159265int main ()
{double param, result;param = 45.0;result = tan ( param * PI / 180.0 );printf ("The tangent of %f degrees is %f.\n", param, result );return 0;
}

1.4、 acos() 反余弦函数

/* acos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* acos */#define PI 3.14159265int main ()
{double param, result;param = 0.5;result = acos (param) * 180.0 / PI;printf ("The arc cosine of %f is %f degrees.\n", param, result);return 0;
}

1.5、asin() 反正弦函数

/* asin example */
#include <stdio.h>      /* printf */
#include <math.h>       /* asin */#define PI 3.14159265int main ()
{double param, result;param = 0.5;result = asin (param) * 180.0 / PI;printf ("The arc sine of %f is %f degrees\n", param, result);return 0;
}

1.6、atan() 反正切函数

/* atan example */
#include <stdio.h>      /* printf */
#include <math.h>       /* atan */#define PI 3.14159265int main ()
{double param, result;param = 1.0;result = atan (param) * 180 / PI;printf ("The arc tangent of %f is %f degrees\n", param, result );return 0;
}

1.7、atan2() 带两个参数的反正切函数

/* atan2 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* atan2 */#define PI 3.14159265int main ()
{double x, y, result;x = -10.0;y = 10.0;result = atan2 (y,x) * 180 / PI;printf ("The arc tangent for (x=%f, y=%f) is %f degrees\n", x, y, result );return 0;
}

2、双曲函数 Hyperbolic functions

2.1、双曲余弦函数

/* cosh example */
#include <stdio.h>      /* printf */
#include <math.h>       /* cosh, log */int main ()
{double param, result;param = log(2.0);result = cosh (param);printf ("The hyperbolic cosine of %f is %f.\n", param, result );return 0;
}

2.2、双曲正弦函数

/* sinh example */
#include <stdio.h>      /* printf */
#include <math.h>       /* sinh, log */int main ()
{double param, result;param = log(2.0);result = sinh (param);printf ("The hyperbolic sine of %f is %f.\n", param, result );return 0;
}

2.3、双曲正切函数

/* tanh example */
#include <stdio.h>      /* printf */
#include <math.h>       /* tanh, log */int main ()
{double param, result;param = log(2.0);result = tanh (param);printf ("The hyperbolic tangent of %f is %f.\n", param, result);return 0;
}

3、指数函数与对数函数 Exponential and logarithmic functions

3.1、exp () 指数函数,以 e 为底数

/* exp example */
#include <stdio.h>      /* printf */
#include <math.h>       /* exp */int main ()
{double param, result;param = 5.0;result = exp (param);printf ("The exponential value of %f is %f.\n", param, result );return 0;
}

3.2、frexp(param,n) 二进制浮点数表示方法 x=param*2^n

/* frexp example */
#include <stdio.h>      /* printf */
#include <math.h>       /* frexp */int main ()
{double param, result;int n;param = 8.0;result = frexp (param , &n);printf ("%f = %f * 2^%d\n", param, result, n);return 0;
}

3.3、log(x) x的自然对数 (Natural logarithm of x)

/* log example */
#include <stdio.h>      /* printf */
#include <math.h>       /* log */int main ()
{double param, result;param = 5.5;result = log (param);printf ("log(%f) = %f\n", param, result );return 0;
}

3.4、log10() 常用对数,以10为底 ( Common logarithm of x )

/* log10 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* log10 */int main ()
{double param, result;param = 1000.0;result = log10 (param);printf ("log10(%f) = %f\n", param, result );return 0;
}

3.5、modf() 返回x的小数部分,其符号与x相同 ,但是参数中可以添加整数部分的变量( The fractional part of x, with the same sign)

/* modf example */
#include <stdio.h>      /* printf */
#include <math.h>       /* modf */int main ()
{double param, fractpart, intpart;param = 3.14159265;fractpart = modf (param , &intpart);printf ("%f = %f + %f \n", param, intpart, fractpart);return 0;
}

3.6、exp2() 返回2的x次方,2 raised to the power of x.

/* exp2 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* exp2 */int main ()
{double param, result;param = 8.0;result = exp2 (param);printf ("2 ^ %f = %f.\n", param, result );return 0;
}

3.7、log2() x的二进制对数( The binary logarithm of x)

/* log2 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* log2 */int main ()
{double param, result;param = 1024.0;result = log2 (param);printf ("log2 (%f) = %f.\n", param, result );return 0;
}

4、幂函数 Power functions

4.1、pow(base, power) 幂函数 The result of raising base to the power exponent

/* pow example */
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */int main ()
{printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );printf ("4.73 ^ 12 = %f\n", pow (4.73, 12.0) );printf ("32.01 ^ 1.54 = %f\n", pow (32.01, 1.54) );return 0;
}

4.2、sqrt(x) 计算x的平方根

/* sqrt example */
#include <stdio.h>      /* printf */
#include <math.h>       /* sqrt */int main ()
{double param, result;param = 1024.0;result = sqrt (param);printf ("sqrt(%f) = %f\n", param, result );return 0;
}

4.3、cbrt(x) 计算x的立方根

/* cbrt example */
#include <stdio.h>      /* printf */
#include <math.h>       /* cbrt */int main ()
{double param, result;param = 27.0;result = cbrt (param);printf ("cbrt (%f) = %f\n", param, result);return 0;
}

4.4、hypot(x,y) 计算直角三角形的斜边 ( The square root of (x^2+y^2) )

/* hypot example */
#include <stdio.h>      /* printf */
#include <math.h>       /* hypot */int main ()
{double leg_x, leg_y, result;leg_x = 3;leg_y = 4;result = hypot (leg_x, leg_y);printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);return 0;
}

5、误差与伽马函数 Error and gamma functions

5.1、误差函数erf(x) 

/* erf example */
#include <stdio.h>      /* printf */
#include <math.h>       /* erf */int main ()
{double param, result;param = 1.0;result = erf (param);printf ("erf (%f) = %f\n", param, result );return 0;
}

5.2、余差函数erfc(x) erfc(x) = 1-erf(x) 误差函数的补函数 

/* erfc example */
#include <stdio.h>      /* printf */
#include <math.h>       /* erfc */int main ()
{double param, result;param = 1.0;result = erfc (param);printf ("erfc(%f) = %f\n", param, result );return 0;
}

5.3、tgamma(x) 伽马函数 ( the gamma function ) 

/* tgamma example */
#include <stdio.h>      /* printf */
#include <math.h>       /* tgamma */int main ()
{double param, result;param = 0.5;result = tgamma (param);printf ("tgamma(%f) = %f\n", param, result );return 0;
}

5.4、lgamma(x) log伽马函数 ( log-gamma function ) 

/* lgamma example */
#include <stdio.h>      /* printf */
#include <math.h>       /* lgamma */int main ()
{double param, result;param = 0.5;result = lgamma (param);printf ("lgamma(%f) = %f\n", param, result );return 0;
}

6、四舍五入与余数函数Rounding and remainder functions

6.1、ceil(x) x上取整函数

/* ceil example */
#include <stdio.h>      /* printf */
#include <math.h>       /* ceil */int main ()
{printf ( "ceil of 2.3 is %.1f\n", ceil(2.3) );printf ( "ceil of 3.8 is %.1f\n", ceil(3.8) );printf ( "ceil of -2.3 is %.1f\n", ceil(-2.3) );printf ( "ceil of -3.8 is %.1f\n", ceil(-3.8) );return 0;
}

6.2、floor(x) x的下取整函数

/* floor example */
#include <stdio.h>      /* printf */
#include <math.h>       /* floor */int main ()
{printf ( "floor of 2.3 is %.1lf\n", floor (2.3) );printf ( "floor of 3.8 is %.1lf\n", floor (3.8) );printf ( "floor of -2.3 is %.1lf\n", floor (-2.3) );printf ( "floor of -3.8 is %.1lf\n", floor (-3.8) );return 0;
}

6.3、fmod(y, x) y/x的余数

/* fmod example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fmod */int main ()
{printf ( "fmod of 5.3 / 2 is %f\n", fmod (5.3,2) );printf ( "fmod of 18.5 / 4.2 is %f\n", fmod (18.5,4.2) );return 0;
}

6.4、round(x) x的四舍五入值 

/* round vs floor vs ceil vs trunc */
#include <stdio.h>      /* printf */
#include <math.h>       /* round, floor, ceil, trunc */int main ()
{const char * format = "%.1f \t%.1f \t%.1f \t%.1f \t%.1f\n";printf ("value\tround\tfloor\tceil\ttrunc\n");printf ("-----\t-----\t-----\t----\t-----\n");printf (format, 2.3,round( 2.3),floor( 2.3),ceil( 2.3),trunc( 2.3));printf (format, 3.8,round( 3.8),floor( 3.8),ceil( 3.8),trunc( 3.8));printf (format, 5.5,round( 5.5),floor( 5.5),ceil( 5.5),trunc( 5.5));printf (format,-2.3,round(-2.3),floor(-2.3),ceil(-2.3),trunc(-2.3));printf (format,-3.8,round(-3.8),floor(-3.8),ceil(-3.8),trunc(-3.8));printf (format,-5.5,round(-5.5),floor(-5.5),ceil(-5.5),trunc(-5.5));return 0;
}

7、绝对值、最小、最大 Absolute、Minimum, maximum

7.1、fabs(x) x的绝对值函数

/* fabs example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fabs */int main ()
{printf ("The absolute value of 3.1416 is %f\n", fabs (3.1416) );printf ("The absolute value of -10.6 is %f\n", fabs (-10.6) );return 0;
}

7.2、abs(x) x的绝对值

// cmath's abs example
#include <iostream>     // std::cout
#include <cmath>        // std::absint main ()
{std::cout << "abs (3.1416) = " << std::abs (3.1416) << '\n';std::cout << "abs (-10.6)  = " << std::abs (-10.6) << '\n';return 0;
}

7.3、fmax(x, y) 两个参数中的最大值 (The maximum numeric value of its arguments. Values among which the function selects a maximum )

/* fmax example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fmax */int main ()
{printf ("fmax (100.0, 1.0) = %f\n", fmax(100.0,1.0));printf ("fmax (-100.0, 1.0) = %f\n", fmax(-100.0,1.0));printf ("fmax (-100.0, -1.0) = %f\n", fmax(-100.0,-1.0));return 0;
}

7.4、fmin(x, y) 两个参数中的最小值

/* fmin example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fmin */int main ()
{printf ("fmin (100.0, 1.0) = %f\n", fmin(100.0,1.0));printf ("fmin (-100.0, 1.0) = %f\n", fmin(-100.0,1.0));printf ("fmin (-100.0, -1.0) = %f\n", fmin(-100.0,-1.0));return 0;
}

C/C++ 数学库文件 (math.h)相关推荐

  1. C 标准库——cmath/math.h

    C 标准库-- string.h C 标准库 -- time.h C 标准库 -- limits.h C 标准库 -- stdio.h C 标准库-- stdlib.h(包括 rand srand 的 ...

  2. C语言数学函数库<math.h>及常用函数

    C语言数学函数库<math.h>及常用函数 一.<math.h> C语言中常用的一个数学函数库,里面涵盖了常用的数学运算,如求对数.指数.绝对值.三角函数.两数中最大数等.使用 ...

  3. C语言标准库<math.h>

    C语言标准库<math.h> 简介 <math.h>头文件定义了各种数学函数和一个宏,在这个库中所有可用的功能都带有一个double类型的参数,且都返回double类型的结果. ...

  4. linux c之加入了加入原文件 math.h调用abs()函数出现implicit declaration of function错误

    今天在vim 写C语言的时候 代码我已经导入了#include<math.h> 但是当我调用ads()函数的时候出现了下面错误 解决办法: 把abs函数改写成fabs函数就行,然后去网上找 ...

  5. C语言库文件ctype.h中重要的库函数

    C Primer Plus第七章分支跳转章节中,提到了ctype.h头文件中的一些用于判断字符类型的库函数接口. isalnum() 字母数字 isalpha() 字母 isblank() 标准的空白 ...

  6. 深入了解arduino舵机控制库文件Servo.h

    舵机是我们在控制领域高频率使用的器件,尤其对于arduino玩家不可或缺.简单的使用方法我们在前面的博文中都已经做过介绍. 常规使用 一般控制 一般步骤为包涵一个servo.h的头文件,然后绑定端口, ...

  7. c语言用pow求x的y次幂,使用系统函数pow(x,y)计算x的y次方的值,注意包含头文件math.h...

    #include //c语言 #include int main() { double m,x,y; printf("请输入两个数:"); scanf ("%d %d&q ...

  8. Fluent UDF中直接调用math.h中的误差函数erf、erfc

    我们知道误差函数定义为 这是一个带积分的函数,Fluent UDF中想自己写代码实现起来相当不方便,精度还不一定能保证.幸好C++11中为我们将这个函数内置在数学头文件math.h中,但是想要兼容C+ ...

  9. c语言标准库详解(八):数学公式math.h

    c语言标准库详解(八):数学公式<math.h> 概述 头文件<math.h>中声明了一些数学函数和宏. 宏 EDOM 和 ERANGE(在头文件<error.h> ...

最新文章

  1. flash绘图API:绘制植物
  2. 随机一段字符串,浏览器点击复制
  3. 数据治理需要注意什么问题
  4. 本科生毕业论文查重率多少合适?
  5. USTC2017 writeup
  6. 免费的短信验证码接口
  7. 合唱队形(最大上升子序列)
  8. ant design vue 中a-tree搜索查询
  9. 灭屏流程 - 安卓R
  10. 使用XMind 打开MindManager 格式文件(.mmap)
  11. 自制舵机(伺服电机)控制系统的一点感想
  12. 用于传感器互操作性问题的指纹匹配系统的大规模研究
  13. FTT暴雷加密熊市雪上加霜?如何对抗系统风险
  14. 万字长文解读DeepMind与谷歌的AI拉锯战
  15. IDA调试修改内存数据
  16. 面试笔试题中的LRU算法及其缺页次数替换
  17. 【QT】QT菜单栏、状态栏、工具栏
  18. 1013---IBM X3850 X6 重新构建Raid5---过程记录
  19. 互联网的女性主义特征(转载)
  20. leetcode 5.最长回文子串

热门文章

  1. 文件系统中FATFS结构体注释
  2. Robot Framework(十五):使用RF进行接口测试(下)
  3. JAVA 合并两个List
  4. CentOS 8 网卡命令使用
  5. 新加坡中央银行联手德勤、纳斯达克开发区块链资产结算业务
  6. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.xx.mapp
  7. iOS杂谈14—iOS设备的UDID是什么?苹果为什么拒绝获取iOS设备UDID的应用?如何替代UDID?
  8. 融云 IM 即时通讯的跨应用通信能力
  9. CSS float浮动布局
  10. Games104现代游戏引擎入门-lecture1介绍