Python math.ldexp() メソッド
Python math.ldexp(x, i)メソッドは x * (2**i) を返します。math.frexp()の逆関数です。
Python バージョン: 2.6
構文
math.ldexp() メソッドの構文は次のとおりです:
math.ldexp(x, i)
パラメータの説明:
- x-- 必須、正の数または負の数。値が数値でない場合は、TypeError が返されます。
- i-- 必須、正の数または負の数。値が数値でない場合は、TypeError が返されます。
戻り値
浮動小数点値を返します。x * (2**i)
例
次の例は x * (2**i) を計算します:
例
# math パッケージをインポート
import math
# x * (2**i) を返す
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))
import math
# x * (2**i) を返す
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))
出力結果:
72.0 -20.0 60.0その他の拡張
Python math モジュール