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 = 2
    i = 3

    # function call
    print(math.ldexp(x,i))

    Output:
    16.0 # (x*(2**i) = (2*(2**3)) = 16

Python代码演示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 math

a = 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值