2020-3-31 11:53:09 [显示全部楼层]
2432浏览
查看: 2432|回复: 0

[uPyCraft IDE] ESP32 常用的模块 math 3.1.5

[复制链接]

在math模块中提供了一些使用浮点数的基本数学函数。

常数

  • math.e — 自然对数的底数。

示例:

>>> import math
>>> print(math.e)
2.718282
  • math.pi — 圆周长与直径的比值。

示例:

>>> print(math.pi)
3.141593

函数

1. math.sqrt(x)

函数说明:计算平方根。
示例:

>>> x = math.sqrt(9)
>>> print(x)
3.0

2. math.pow(x, y)

函数说明:计算x的y次方(幂)。
示例:

>>> x = math.pow(2, 3)
>>> print(x)
8.0

3. math.exp(x)

函数说明:计算e的x次方(幂)。
示例:

>>> x = math.exp(2)
>>> print(x)
7.389056

4. math.expm1(x)

函数说明:计算math.exp(x)-1。

5. math.log(x)

函数说明:计算以e为底的x的对数。
示例:

>>> x = math.log(10)
>>> print(x)
2.302585

6. math.log2(x)

函数说明:计算以2为底的x的对数。
示例:

>>> x = math.log2(8)
>>> print(x)
3.0

7. math.log10(x)

函数说明:计算以10为底的x的对数。
示例:

>>> x = math.log10(10)
>>> print(x)
1.0

8. math.radians(x)

函数说明:角度转化为弧度。
示例:

>>> x = math.radians(60)
>>> print(x)
1.047198

9. math.degrees(x)

函数说明:弧度转化为角度。
示例:

>>> x = math.degrees(1.047198)
>>> print(x)
60.00002

10. math.sin(x)

函数说明:传入弧度值,计算正弦。
示例:计算sin90°

>>> math.sin(math.radians(90))
1.0

11. math.cos(x)

函数说明:传入弧度值,计算余弦。
示例:计算cos60°

>>> math.cos(math.radians(60))
0.5

12. math.tan(x)

函数说明:传入弧度值,计算正切。
示例:计算tan60°

>>> math.tan(math.radians(60))
1.732051

13. math.asin(x)

函数说明:传入弧度值,计算sin(x)的反三角函数。
示例:

>>> x = math.asin(0.5)
>>> print(x)
0.5235988

14. math.acos(x)

函数说明:传入弧度值,计算cos(x)的反三角函数。

15. math.atan(x)

函数说明:传入弧度值,计算tan(x)的反三角函数。

16. math.ceil(x)

函数说明:向上取整。
示例:

>>> x = math.ceil(5.6454)
>>> print(x)

6

17. math.floor(x)

函数说明:向下取整。
示例:

>>> x = math.floor(2.99)
>>> print(x)
2
>>> y = math.floor(-2.34)
>>> print(y)
-3

18. math.fabs(x)

函数说明:计算绝对值。
示例:

>>> x = math.fabs(-5)
>>> print(x)
5.0
>>> y = math.fabs(5.0)
>>> print(y)
5.0

19. math.fmod(x, y)

函数说明:取x除以y的模。
示例:

>>> x = math.fmod(4, 5)
>>> print(x)
4.0

20. math.trunc(x)

函数说明:取整。
示例:

>>> x = math.trunc(5.12)
>>> print(x)
5
>>> y = math.trunc(-6.8)
>>> print(y)
-6

21. math.gamma(x)

函数说明:返回伽马函数。
示例:

>>> x = math.gamma(5.21)
>>> print(x)
33.08715

22. math.lgamma(x)

函数说明:返回伽马函数的自然对数。
示例:

x = math.lgamma(5.21)
print(x)
3.499145
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail