Ver Fonte

【完善】:math 模块

SummerGift há 7 anos atrás
pai
commit
4f18aae497
1 ficheiros alterados com 181 adições e 29 exclusões
  1. 181 29
      docs/03-Basic_Module/04-math.md

+ 181 - 29
docs/03-Basic_Module/04-math.md

@@ -4,16 +4,44 @@
     **math** 模块提供了对 C 标准定义的数学函数的访问。  
     **math** 模块提供了对 C 标准定义的数学函数的访问。  
     本模块需要带有硬件 FPU,精度是32位,这个模块需要浮点功能支持。
     本模块需要带有硬件 FPU,精度是32位,这个模块需要浮点功能支持。
 
 
+## 常数
+
+### **math.e**  
+自然对数的底数。
+
+示例:
+```
+>>>import math
+>>>print(math.e)
+2.718282
+```
+### **math.pi**  
+圆周长与直径的比值。
+
+示例:
+
+```
+>>> print(math.pi)
+3.141593
+```
+
 ## 函数
 ## 函数
 
 
 ### **math.acos(x)**
 ### **math.acos(x)**
-  返回 ``x`` 的反余弦。
+传入弧度值,计算cos(x)的反三角函数。 
 
 
 ### **math.acosh(x)** 
 ### **math.acosh(x)** 
   返回 ``x`` 的逆双曲余弦。
   返回 ``x`` 的逆双曲余弦。
 
 
 ### **math.asin(x)**
 ### **math.asin(x)**
-  返回 ``x`` 的反正弦。
+传入弧度值,计算sin(x)的反三角函数。 
+示例:
+
+```
+>>> x = math.asin(0.5)
+>>> print(x)
+0.5235988
+```
 
 
 ### **math.asinh(x)**
 ### **math.asinh(x)**
   返回``x`` 的逆双曲正弦。
   返回``x`` 的逆双曲正弦。
@@ -28,19 +56,39 @@
   Return the inverse hyperbolic tangent of x.
   Return the inverse hyperbolic tangent of x.
 
 
 ### **math.ceil(x)**
 ### **math.ceil(x)**
-  Return an integer, being x rounded towards positive infinity.
+向上取整。 
+示例:
+
+```
+>>> x = math.ceil(5.6454)
+>>> print(x)
+6
+```
 
 
 ### **math.copysign(x, y)** 
 ### **math.copysign(x, y)** 
   Return x with the sign of y.
   Return x with the sign of y.
 
 
 ### **math.cos(x)**  
 ### **math.cos(x)**  
-  Return the cosine of x.
+传入弧度值,计算余弦。 
+示例:计算cos60°
+
+```
+>>> math.cos(math.radians(60))
+0.5
+```
 
 
 ### **math.cosh(x)**  
 ### **math.cosh(x)**  
   Return the hyperbolic cosine of x.
   Return the hyperbolic cosine of x.
 
 
 ### **math.degrees(x)**  
 ### **math.degrees(x)**  
-  Return radians x converted to degrees.
+弧度转化为角度。 
+示例:
+
+```
+>>> x = math.degrees(1.047198)
+>>> print(x)
+60.00002
+```
 
 
 ### **math.erf(x)**  
 ### **math.erf(x)**  
   Return the error function of x.
   Return the error function of x.
@@ -49,25 +97,66 @@
   Return the complementary error function of x.
   Return the complementary error function of x.
 
 
 ### **math.exp(x)**  
 ### **math.exp(x)**  
-  Return the exponential of x.
+计算e的x次方(幂)。 
+示例:
+
+```
+>>> x = math.exp(2)
+>>> print(x)
+7.389056
+```
 
 
 ### **math.expm1(x)**  
 ### **math.expm1(x)**  
-  Return exp(x) - 1.
+计算 math.exp(x) - 1。 
 
 
 ### **math.fabs(x)**  
 ### **math.fabs(x)**  
-  Return the absolute value of x.
+计算绝对值。 
+示例:
+
+```
+>>> x = math.fabs(-5)
+>>> print(x)
+5.0
+>>> y = math.fabs(5.0)
+>>> print(y)
+5.0
+```
 
 
 ### **math.floor(x)**  
 ### **math.floor(x)**  
-  Return an integer, being x rounded towards negative infinity.
+向下取整。 
+示例:
+
+```
+>>> x = math.floor(2.99)
+>>> print(x)
+2
+>>> y = math.floor(-2.34)
+>>> print(y)
+-3
+```
 
 
 ### **math.fmod(x, y)**  
 ### **math.fmod(x, y)**  
-  Return the remainder of x/y.
+取x除以y的模。 
+示例:
+
+```
+>>> x = math.fmod(4, 5)
+>>> print(x)
+4.0
+```
 
 
 ### **math.frexp(x)**  
 ### **math.frexp(x)**  
   Decomposes a floating-point number into its mantissa and exponent. The returned value is the tuple (m, e) such that x == m * 2**e exactly. If x == 0 then the function returns (0.0, 0), otherwise the relation 0.5 <= abs(m) < 1 holds.
   Decomposes a floating-point number into its mantissa and exponent. The returned value is the tuple (m, e) such that x == m * 2**e exactly. If x == 0 then the function returns (0.0, 0), otherwise the relation 0.5 <= abs(m) < 1 holds.
 
 
 ### **math.gamma(x)**  
 ### **math.gamma(x)**  
-  Return the gamma function of x.
+返回伽马函数。 
+示例:
+
+```
+>>> x = math.gamma(5.21)
+>>> print(x)
+33.08715
+```
 
 
 ### **math.isfinite(x)**  
 ### **math.isfinite(x)**  
   Return True if x is finite.
   Return True if x is finite.
@@ -82,51 +171,114 @@
   Return x * (2**exp).
   Return x * (2**exp).
 
 
 ### **math.lgamma(x)**  
 ### **math.lgamma(x)**  
-  Return the natural logarithm of the gamma function of x.
+返回伽马函数的自然对数。 
+示例:
+
+```
+>>> x = math.lgamma(5.21)
+>>> print(x)
+3.499145
+```
 
 
 ### **math.log(x)**  
 ### **math.log(x)**  
-  Return the natural logarithm of x.
+计算以e为底的x的对数。 
+示例:
+
+```
+>>> x = math.log(10)
+>>> print(x)
+2.302585
+```
 
 
 ### **math.log10(x)**  
 ### **math.log10(x)**  
-  Return the base-10 logarithm of x.
+计算以10为底的x的对数。 
+示例:
+
+```
+>>> x = math.log10(10)
+>>> print(x)
+1.0
+```
 
 
 ### **math.log2(x)**  
 ### **math.log2(x)**  
-  Return the base-2 logarithm of x.
+ 计算以2为底的x的对数。 
+示例:
+
+```
+>>> x = math.log2(8)
+>>> print(x)
+3.0
+```
 
 
 ### **math.modf(x)**  
 ### **math.modf(x)**  
   Return a tuple of two floats, being the fractional and integral parts of x. Both return values have the same sign as x.
   Return a tuple of two floats, being the fractional and integral parts of x. Both return values have the same sign as x.
 
 
 ### **math.pow(x, y)**  
 ### **math.pow(x, y)**  
-  Returns x to the power of y.
+计算 x 的 y 次方(幂)。 
+示例:
+
+```
+>>> x = math.pow(2, 3)
+>>> print(x)
+8.0
+```
 
 
 ### **math.radians(x)**  
 ### **math.radians(x)**  
-  Return degrees x converted to radians.
+角度转化为弧度。 
+示例:
+
+```
+>>> x = math.radians(60)
+>>> print(x)
+1.047198
+```
 
 
 ### **math.sin(x)**  
 ### **math.sin(x)**  
-  Return the sine of x.
+传入弧度值,计算正弦。 
+示例:计算sin90°
+
+```
+>>> math.sin(math.radians(90))
+1.0
+```
 
 
 ### **math.sinh(x)**  
 ### **math.sinh(x)**  
   Return the hyperbolic sine of x.
   Return the hyperbolic sine of x.
 
 
 ### **math.sqrt(x)**  
 ### **math.sqrt(x)**  
-  Return the square root of x.
+计算平方根。 
+示例:
+
+```
+>>> x = math.sqrt(9)
+>>> print(x)
+3.0
+```
 
 
 ### **math.tan(x)**  
 ### **math.tan(x)**  
-  Return the tangent of x.
+传入弧度值,计算正切。 
+示例:计算tan60°
+
+```
+>>> math.tan(math.radians(60))
+1.732051
+```
 
 
 ### **math.tanh(x)**  
 ### **math.tanh(x)**  
   Return the hyperbolic tangent of x.
   Return the hyperbolic tangent of x.
 
 
 ### **math.trunc(x)**  
 ### **math.trunc(x)**  
-  返回一个整数, x 接近于0。
-
-## 常数
-
-### **math.e**  
-  自然对数的底
-
-### **math.pi**  
-  圆周率
+取整。 
+示例:
+
+```
+>>> x = math.trunc(5.12)
+>>> print(x)
+5
+>>> y = math.trunc(-6.8)
+>>> print(y)
+-6
+```
 
 
 更多内容可参考  [math](http://docs.micropython.org/en/latest/pyboard/library/math.html) 。
 更多内容可参考  [math](http://docs.micropython.org/en/latest/pyboard/library/math.html) 。