The math.ldexp() function returns a floating-point number equal to x*(2**i). The ldexp in the functions name stands for  "load exponent".


Where,  parameter  x  is an integer or a  floating-point number. Parameter i  is the integer exponent, it should be strictly an integer value, otherwise, a TypeError is raised.

The function returns a floating-point number equal to x*(2**i).

import math 

print(math.ldexp(3, 2))
print(math.ldexp(2.5, 5))
print(math.ldexp(4.1, 5))
print(math.ldexp(10, 10))

Math.ldexp is useful in Python for scaling a number using the exponent value. It is commonly used in scientific computing to quickly multiply a number by a power of two. It can also be used to scale a number up or down to the nearest integer, handle overflow, and adjust to the precision of the floating-point format.

The following example uses math.ldexp() to scale pi up by a factor of 8.  

import math

print(math.ldexp(math.pi, 8))