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 的平方根。

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