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 returning x * (2**i)
Example
The following example computes x * (2**i):
Example
Import the math package
import
math
Return x * (2**i)
(
math
.
ldexp
(
9
,
3
)
)
(
math
.
ldexp
(
5
,
2
)
)
(
math
.
ldexp
(
15
,
2
)
)
Output result:
72.0
-20.0
60.0
Python math Module