Python math.frexp() Method

Python math 模块Python math Module

Python math.frexp(x)The method returns the mantissa and exponent of x as a pair (m, e).

The mathematical formula for this method is:number = m * 2**e。

Python Version: 2.6

Syntax

The syntax of the math.frexp() method is as follows:

math.frexp(x)

Parameter Description:

  • x-- Required, positive or negative. If x is not a number, TypeError is returned.

Return Value

A tuple, returning the mantissa and exponent of x as a (m, e) pair.

Example

The following example calculates the mantissa and exponent of a number:

Example

# Import the math package
import math

# Return the mantissa and exponent of the number
print(math.frexp(4))
print(math.frexp(-4))
print(math.frexp(7))

Output result:

(0.5, 3)
(-0.5, 3)
(0.875, 3)

Python math 模块Python math Module

Other Extensions