本文共 2659 字,大约阅读时间需要 8 分钟。
gdb ldexp
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 that is used to get the pair of mantissa and exponent in a tuple. The math.ldexp() method is an inverse of . In other words, w can understand that returns mantissa and exponent of a number and math.ldexp() method reforms/creates the number again using x – mantissa and i – exponent.
注意: 数学模块中有一种方法可用于获取元组中的尾数对和指数对。 math.ldexp()方法与相反。 换句话说,w可以理解返回数字的尾数和指数,而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 = 2 i = 3 # function call print(math.ldexp(x,i)) Output: 16.0 # (x*(2**i) = (2*(2**3)) = 16
# python code to demonstrate example of # math.ldexp() method# importing math moduleimport math# numberx = 2i = 3# math.ldexp() methodprint(math.ldexp(x,i))x = 0i = 0# math.ldexp() methodprint(math.ldexp(x,i))x = 0.625i = 4# math.ldexp() methodprint(math.ldexp(x,i))x = -0.639625i = 4# math.ldexp() methodprint(math.ldexp(x,i))
Output
输出量
16.00.010.0-10.234
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 moduleimport matha = 10frexp_result = math.frexp(a)print("frexp() result: ", frexp_result)# extracing its valuesx = 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.625i = 4ldexp() result: 10.0
翻译自:
gdb ldexp
转载地址:http://ruxzd.baihongyu.com/