Python math.log1p() メソッド

Python math 模块Python math モジュール

Python math.log1p(x)メソッドは 1+x の自然対数(底を e とする)を返します。

構文

math.log1p() メソッドの構文は次のとおりです:

math.log1p(x)

パラメータの説明:

  • x-- 必須、数値。x が数値でない場合は TypeError を返します。値が 0 または負の数の場合は ValueError を返します。

戻り値

1+x の e を底とする自然対数を表す浮動小数点数 float を返します。

例

次の例では、1+x の e を底とする自然対数を返します:

例

# math パッケージをインポート
import math

# 1+x の e を底とする自然対数を出力
print(math.log1p(2.7183))
print(math.log1p(2))
print(math.log1p(1))

出力結果:

1.313266574586334
1.0986122886681098
0.6931471805599453

Python math 模块Python math モジュール

その他の拡張