ldexp()
« All Math methods
ldexp() returns the mantissa and exponent of an input number.
ldexp(m,e) # output n
n : is the output number
m : is the mantissa , a floating point number
e : is the exponent , an integer
Relation between output number with Mantissa ( m ) and exponent ( e )
n == m * 2**e
Example
import math
print(math.ldexp(2,3)) # 16.0
With negative numbers
print(math.ldexp(-2,3)) # -16.0
print(math.ldexp(2,-3)) # 0.25
The second argument ( exponent ) has to be an integer, we can't use float.
print(math.ldexp(2.2,-3.3))
This will generate an TypeError
We can also use frexp() the inverse function of ldexp() to get Mantissa and exponent of n
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com