Python math.frexp()
Published Nov 29, 2024
Contribute to Docs
In Python, the math.frexp() method calculates the mantissa and the exponent of a given number. The mathematical formula that is used in this method is n = m * 2^e, where n is the given number, m is the mantissa, and e is the exponent. The method returns the mantissa and the exponent in a tuple (m, e).
Syntax
math.frexp(x)
x: The number whose mantissa and exponent are to be calculated. If the input is not a number, the method returns aTypeError.
Example
The following example demonstrates the usage of the math.frexp() method:
import math# Calculating the mantissa and the exponent of different numbersprint(math.frexp(10))print(math.frexp(20))print(math.frexp(30))
The above code produces the following output:
(0.625, 4)(0.625, 5)(0.9375, 5)
Codebyte Example
Run the following codebyte example to understand the use of the math.frexp() method:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours