The math.ldexp()
function returns a floating-point number equal to x*(2**i). The ldexp in the functions name stands for "load exponent".
math.ldexp(x,i)
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).
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.