math.frexp()
function exists in Standard math Library of Python Programming Language. This function returns mantissa and exponent as a pair (m, e) of a given value x
, where mantissa m
is a floating point number and e
exponent is an integer value.
Syntax of frexp()
Function in Python
The syntax of
frexp()
function in Python is:math.frexp( x )
Parameters of frexp()
in Python
x
Any valid Python number (positive or negative). This parameter is required.Note: if the
x
parameter is not a number, frexp()
function will return a TypeError
.
Python frexp()
Function Compatibility
Python 2.x – Yes
Python 3.x – Yes
Python 3.x – Yes
Return Value of frexp()
Function in Python
frexp()
returns mantissa and exponent as a pair (m, e) value of a given number x
. Mantissa (m) is floating point number and exponent (e) is an integer.
Python frexp()
Function Example
# import math library import math print(math.frexp(25)) print(math.frexp(20.3)) print(math.frexp(-20)) print(math.frexp(-13.6))
The output of Python frexp()
Function:
(0.78125, 5)
(0.634375, 5)
(-0.625, 5)
(-0.85, 4)
Note that in output all the numbers whether they are negative or positive are converted into a pair value (m, e), where m, mantissa, is floating point number and e, exponent, is an integer.