Python math.frexp() – Mantissa and Exponent (m, e)

Python math.frexp()

math.frexp(x) function returns the mantissa and exponent of x as the pair (m, e).

x == m * 2^e

Syntax

The syntax to call frexp() function is

math.frexp(x)

where

ParameterRequiredDescription
xYesA numeric value.

Examples

In the following program, we find the (mantissa, exponent) for x=5.5.

Python Program

import math

x = 5.5
result = math.frexp(x)
print('(mantissa, exponent) :', result)
Run

Output

(mantissa, exponent) : (0.6875, 3)

(mantissa, exponent) for x=0.

Python Program

import math

x = 0
result = math.frexp(x)
print('(mantissa, exponent) :', result)
Run

Output

(mantissa, exponent) : (0.0, 0)

(mantissa, exponent) for x=infinity.

Python Program

import math

x = math.inf
result = math.frexp(x)
print('(mantissa, exponent) :', result)
Run

Output

(mantissa, exponent) : (inf, 0)

(mantissa, exponent) for x=NaN (Not a Number).

Python Program

import math

x = math.nan
result = math.frexp(x)
print('(mantissa, exponent) :', result)
Run

Output

(mantissa, exponent) : (nan, 0)

Summary

In this Python Examples tutorial, we learned the syntax of, and examples for math.frexp() function.