math.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. """
  2. math 模块提供了对 C 标准定义的数学函数的访问。
  3. 本模块需要带有硬件 FPU,精度是32位,这个模块需要浮点功能支持。
  4. """
  5. e = ... # type: int
  6. pi = ... # type: int
  7. def acos(x) -> None:
  8. """传入弧度值,计算cos(x)的反三角函数。"""
  9. ...
  10. def acosh(x) -> None:
  11. """返回 x 的逆双曲余弦。"""
  12. ...
  13. def asin(x) -> None:
  14. """传入弧度值,计算sin(x)的反三角函数。 示例:
  15. - x = math.asin(0.5)
  16. - print(x)
  17. 0.5235988"""
  18. ...
  19. def asinh(x) -> None:
  20. """返回 x 的逆双曲正弦。"""
  21. ...
  22. def atan(x) -> None:
  23. """返回 x 的逆切线。"""
  24. ...
  25. def atan2(y, x) -> None:
  26. """Return the principal value of the inverse tangent of y/x."""
  27. ...
  28. def atanh(x) -> None:
  29. """Return the inverse hyperbolic tangent of x."""
  30. ...
  31. def ceil(x) -> None:
  32. """向上取整。 示例:
  33. - x = math.ceil(5.6454)
  34. - print(x)
  35. - 6
  36. """
  37. ...
  38. def copysign(x, y) -> None:
  39. """Return x with the sign of y."""
  40. ...
  41. def cos(x) -> None:
  42. """传入弧度值,计算余弦。 示例:计算cos60°
  43. - math.cos(math.radians(60))
  44. - 0.5
  45. """
  46. ...
  47. def cosh(x) -> None:
  48. """Return the hyperbolic cosine of x."""
  49. ...
  50. def degrees(x) -> None:
  51. """弧度转化为角度。 示例:
  52. - x = math.degrees(1.047198)
  53. - print(x)
  54. - 60.00002"""
  55. ...
  56. def erf(x) -> None:
  57. """Return the error function of x."""
  58. ...
  59. def erfc(x) -> None:
  60. """Return the complementary error function of x."""
  61. ...
  62. def exp(x) -> None:
  63. """计算e的x次方(幂)。
  64. 示例:
  65. - x = math.exp(2)
  66. - print(x)
  67. - 7.389056"""
  68. ...
  69. def expm1(x) -> None:
  70. """计算 math.exp(x) - 1。"""
  71. ...
  72. def fabs(x) -> None:
  73. """计算绝对值。 示例:
  74. - x = math.fabs(-5)
  75. - print(x)
  76. - 5.0
  77. - y = math.fabs(5.0)
  78. - print(y)
  79. - 5.0
  80. """
  81. ...
  82. def floor(x) -> None:
  83. """向下取整。 示例:
  84. - x = math.floor(2.99)
  85. - print(x)
  86. 2
  87. - y = math.floor(-2.34)
  88. - print(y)
  89. -3
  90. """
  91. ...
  92. def fmod(x, y) -> None:
  93. """取x除以y的模。 示例:
  94. - x = math.fmod(4, 5)
  95. - print(x)
  96. 4.0
  97. """
  98. ...
  99. def frexp(x) -> None:
  100. """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."""
  101. ...
  102. def gamma(x) -> None:
  103. """返回伽马函数。 示例:
  104. - x = math.gamma(5.21)
  105. - print(x)
  106. 33.08715。
  107. """
  108. ...
  109. def isfinite(x) -> None:
  110. """Return True if x is finite."""
  111. ...
  112. def isinf(x) -> None:
  113. """Return True if x is infinite."""
  114. ...
  115. def isnan(x) -> None:
  116. """Return True if x is not-a-number"""
  117. ...
  118. def ldexp(x, exp) -> None:
  119. """Return x * (2**exp)."""
  120. ...
  121. def lgamma(x) -> None:
  122. """返回伽马函数的自然对数。 示例:
  123. - x = math.lgamma(5.21)
  124. - print(x)
  125. 3.499145"""
  126. ...
  127. def log(x) -> None:
  128. """计算以e为底的x的对数。 示例:
  129. - x = math.log(10)
  130. - print(x)
  131. 2.302585"""
  132. ...
  133. def log10(x) -> None:
  134. """计算以10为底的x的对数。 示例:
  135. - x = math.log10(10)
  136. - print(x)
  137. 1.0"""
  138. ...
  139. def log2(x) -> None:
  140. """计算以2为底的x的对数。 示例:
  141. - x = math.log2(8)
  142. - print(x)
  143. 3.0"""
  144. ...
  145. def modf(x) -> None:
  146. """Return a tuple of two floats, being the fractional and integral parts of x. Both return values have the same sign as x."""
  147. ...
  148. def pow(x, y) -> None:
  149. """计算 x 的 y 次方(幂)。 示例:
  150. - x = math.pow(2, 3)
  151. - print(x)
  152. 8.0"""
  153. ...
  154. def radians(x) -> None:
  155. """角度转化为弧度。 示例:
  156. - x = math.radians(60)
  157. - print(x)
  158. 1.047198"""
  159. ...
  160. def sin(x) -> None:
  161. """传入弧度值,计算正弦。 示例:计算sin90°
  162. - math.sin(math.radians(90))
  163. 1.0"""
  164. ...
  165. def sinh(x) -> None:
  166. """Return the hyperbolic sine of x."""
  167. ...
  168. def sqrt(x) -> None:
  169. """计算平方根。 示例:
  170. - x = math.sqrt(9)
  171. - print(x)
  172. 3.0"""
  173. ...
  174. def tan(x) -> None:
  175. """传入弧度值,计算正切。 示例:计算tan60°
  176. - math.tan(math.radians(60))
  177. 1.732051"""
  178. ...
  179. def tanh(x) -> None:
  180. """Return the hyperbolic tangent of x."""
  181. ...
  182. def trunc(x) -> None:
  183. """取整。 示例:
  184. - x = math.trunc(5.12)
  185. - print(x)
  186. 5
  187. - y = math.trunc(-6.8)
  188. - print(y)
  189. -6"""
  190. ...