all Python 3Numbers & mathfunction
math.ldexp
representation
The inverse of frexp: x·2**i (builds a number from its mantissa and exponent).
Syntax
math.ldexp(...)
Scaling by a power of two is exact — only the exponent moves, the significant bits stay put — which makes ldexp safer than x * 2 ** i, where a large i builds a huge intermediate integer first. Overflowing the float range raises OverflowError; going too small degrades gradually through subnormal numbers and finally to 0.0.
Examples
import math
print(math.ldexp(0.5, 3)) # → 4.0
print(math.ldexp(1, 10)) # → 1024.0
print(math.ldexp(3, -2)) # → 0.75
m, e = math.frexp(10); print(math.ldexp(m, e)) # → 10.0
print(math.ldexp(1, 5000)) # → OverflowError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy