#import the math module
import math
#Use the frexp() function
print(math.frexp(3.142))
The math.frexp()
function returns the mantissa and the exponent of the input number in base 2.
math.frexp(x)
x |
An integer or a float. |
The function returns the mantissa and exponent of x
as a pair (m, e)
, where m
is a float with an absolute value between 0.5 (inclusive) and 1.0 (exclusive), and e
is an integer such that x == m * 2**e
. Where , m
is the mantissa and e
is the exponent.
import math
print(math.frexp(0))
print(math.frexp(0.5))
print(math.frexp(4))
print(math.frexp(-9))
print(math.frexp(10))
print(math.frexp(-44))
A TypeError
is raised if x
is not an integer or a float.
import math
math.frexp(2+3j)