Power and logarithmic functions - 幂函数与对数函数

Power and logarithmic functions - 幂函数与对数函数

math - Mathematical functions - 数学函数
https://docs.python.org/3/library/math.html

1. math.exp(x)

Return e raised to the power x, where e = 2.718281… is the base of natural logarithms. This is usually more accurate than math.e ** x or pow(math.e, x).
返回 ex 幂,其中 e = 2.718281... 是自然对数的基数。这通常比 math.e ** xpow(math.e, x) 更精确。

2. math.log(x[, base])

With one argument, return the natural logarithm of x (to base e).
使用一个参数,返回 x 的自然对数 (底为 e )。

With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base).
使用两个参数,返回给定的 base 的对数 x ,计算为 log(x)/log(base)

3. math.log2(x)

Return the base-2 logarithm of x. This is usually more accurate than log(x, 2).
返回 x 以 2 为底的对数。这通常比 log(x, 2) 更准确。

4. math.log10(x)

Return the base-10 logarithm of x. This is usually more accurate than log(x, 10).
返回 x 底为 10 的对数。这通常比 log(x, 10) 更准确。

5. math.pow(x, y)

Return x raised to the power y. Exceptional cases follow Annex ‘F’ of the C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN. If both x and y are finite, x is negative, and y is not an integer then pow(x, y) is undefined, and raises ValueError.
将返回 xy 次幂。特殊情况尽可能遵循 C99 标准的附录 'F'。特别是, pow(1.0, x)pow(x, 0.0) 总是返回 1.0 ,即使 x 是零或 NaN。如果 xy 都是有限的,x 是负数, y 不是整数那么 pow(x, y) 是未定义的,并且引发 ValueError 。

Unlike the built-in ** operator, math.pow() converts both its arguments to type float. Use ** or the built-in pow() function for computing exact integer powers.
与内置的 ** 运算符不同,math.pow() 将其参数转换为 float 类型。使用 ** 或内置的 pow() 函数来计算精确的整数幂。

6. math.sqrt(x)

Return the square root of x.
返回 x 的平方根。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章