frexp()

frexp() returns the mantissa and exponent of an input number.
frexp(n) # (m,e) 
n : is the input number
m : is the mantissa , a floating point number
e : is the exponent , an integer

Relation between input number with Mantissa and exponent
n == m * 2**e
Example
import math
print(math.frexp(4)) 
Output of this is here.
(0.5,3)
We can check the output
print((0.5)*(2**(3))) # 4.0
Examples with negative numbers
import math
print(math.frexp(-5))    # (-0.625,3)
print((-0.625)*(2**(3))) # -5.0
Using 0
import math
print(math.frexp(0))   # (0.0, 0)

Understanding math.frexp() in Python

Use Case: Scientific Computing
frexp() is useful in breaking down floating-point numbers, particularly in scientific computing or low-level operations where manipulating mantissa and exponents is required.

import math
mantissa, exponent = math.frexp(128.0)  # Outputs: (0.5, 8)
print(f"Mantissa: {mantissa}, Exponent: {exponent}")

Comparison with ldexp()

mantissa, exponent = math.frexp(8)
print(math.ldexp(mantissa, exponent))  # Outputs 8.0

Both functions are often paired to break down and reconstruct numbers.


We can also use ldexp() the inverse function of frexp() to get the number n
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer