Python math - ldexp() Method
The Python math.ldexp() function returns a x 2b. The function only takes integer value of b. In special cases it returns the following:
- If the first argument is nan, nan is returned.
- If the first argument is infinite, then an infinity of the same sign is returned.
Syntax
math.ldexp(a, b)
Parameters
a |
Required. Specify value to be scaled by power of 2. |
b |
Required. Specify the integer value, the power of 2 used to scale a. |
Return Value
Returns a x 2b.
Example:
In the example below, ldexp() function returns a x 2b.
import math print(math.ldexp(2.55, 4)) print(math.ldexp(10, 3)) print(math.ldexp(15, 8))
The output of the above code will be:
40.8 80.0 3840.0
❮ Python Math Module