gdb ldexp_带有Python示例的math.ldexp()方法
gdb ldexp
Python math.ldexp()方法 (Python math.ldexp() method)
math.ldexp() method is a library method of math module, it is used to calculate expression x*(2**i), where x is a mantissa and i is an exponent. It accepts two numbers (x is either float or integer, i is an integer) and returns the result of the expression x*(2**i)).
math.ldexp()方法是數學模塊的庫方法,用于計算表達式x *(2 ** i) ,其中x是尾數, i是指數。 它接受兩個數字( x是浮點數或整數, i是整數),并返回表達式x *(2 ** i)的結果 。
Note: There is a method in math module math.frexp() that is used to get the pair of mantissa and exponent in a tuple. The math.ldexp() method is an inverse of math.frexp() method. In other words, w can understand that math.frexp() method returns mantissa and exponent of a number and math.ldexp() method reforms/creates the number again using x – mantissa and i – exponent.
注意: 數學模塊math.frexp()中有一種方法可用于獲取元組中的尾數對和指數對。 math.ldexp()方法與math.frexp()方法相反。 換句話說,w可以理解math.frexp()方法返回數字的尾數和指數,而math.ldexp()方法再次使用x –尾數和i –指數來重整 /創建數字。
Syntax of math.ldexp() method:
math.ldexp()方法的語法:
math.ldexp(x, i)Parameter(s): x, i – the numbers to be calculated the expression "x*(2**i)".
參數: x,i –要計算的數字,表達式為“ x *(2 ** i)” 。
Return value: float – it returns a float value that is the result of expression "x*(2**i)".
返回值: float-它返回一個浮點值,該值是表達式“ x *(2 ** i)”的結果 。
Example:
例:
Input:x = 2i = 3# function callprint(math.ldexp(x,i))Output:16.0 # (x*(2**i) = (2*(2**3)) = 16Python代碼演示math.ldexp()方法的示例 (Python code to demonstrate example of math.ldexp() method)
# python code to demonstrate example of # math.ldexp() method# importing math module import math# number x = 2 i = 3 # math.ldexp() method print(math.ldexp(x,i))x = 0 i = 0 # math.ldexp() method print(math.ldexp(x,i))x = 0.625 i = 4 # math.ldexp() method print(math.ldexp(x,i))x = -0.639625 i = 4 # math.ldexp() method print(math.ldexp(x,i))Output
輸出量
16.0 0.0 10.0 -10.234區分math.frexp()和math.ldexp()方法的Python代碼 (Python code to differentiate the math.frexp() and math.ldexp() methods)
Here, we have a number a and finding it's mantissa and exponent as a pair (x, i), and again making the same number by using math.ldexp() method that calculates the expression (x*(2**i))
在這里,我們有一個數字a,并找到它的尾數和指數對(x,i) ,然后再次使用math.ldexp()方法來計算表達式(x *(2 ** i)
# python code to demonstrate example of # math.ldexp() method# importing math module import matha = 10 frexp_result = math.frexp(a) print("frexp() result: ", frexp_result)# extracing its values x = frexp_result[0] i = frexp_result[1] print("Extracted part from frexp_result...") print("x = ", x) print("i = ", i)# now using method ldexp() ldexp_result = math.ldexp(x,i) print("ldexp() result: ", ldexp_result)Output
輸出量
frexp() result: (0.625, 4) Extracted part from frexp_result... x = 0.625 i = 4 ldexp() result: 10.0翻譯自: https://www.includehelp.com/python/math-ldexp-method-with-example.aspx
gdb ldexp
總結
以上是生活随笔為你收集整理的gdb ldexp_带有Python示例的math.ldexp()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 操作系统中的处理机调度调度_操作系统中的
- 下一篇: Python程序从给定的N个数字中找到最