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

Contents

## 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

## Examples

### 1. Find mantissa and exponent of float value

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 Code Copy

Output

``(mantissa, exponent) : (0.6875, 3)``

### 2. Find mantissa and exponent of zero

In the following program, we find the (mantissa, exponent) for a value of zero.

Python Program

``````import math

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

Output

``(mantissa, exponent) : (0.0, 0)``

### 3. Find mantissa and exponent of infinity

In the following program, we take a value of infinity in variable x, and find its mantissa, and exponent.

Python Program

``````import math

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

Output

``(mantissa, exponent) : (inf, 0)``

### 4. Find mantissa and exponent of nan

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

Python Program

``````import math

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

Output

``(mantissa, exponent) : (nan, 0)``

## Summary

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

## Related Tutorials

Code copied to clipboard successfully 👍