Python math.ldexp() Method
Python math.ldexp(x, i)The method returns x * (2**i),math.frexp()the inverse function of.
Python Version: 2.6
Syntax
The syntax of the math.ldexp() method is as follows:
math.ldexp(x, i)
Parameter Description:
- x-- Required, a positive or negative number. If the value is not a number, a TypeError is returned.
- i-- Required, a positive or negative number. If the value is not a number, a TypeError is returned.
Return Value
A floating-point value, returns x * (2**i)
Example
The following example calculates x * (2**i):
Example
# Import the math package
import math
# Return x * (2**i)
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))
import math
# Return x * (2**i)
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))
Output Result:
72.0 -20.0 60.0Other Extensions
Python math Module