The frexp() function splits a floating-point number into a mantissa (normalized fraction) and a binary exponent, so that x = mantissa × 2exp. It mirrors how computers store floats internally and pairs with ldexp() to rebuild the value.
01
Split x
Mantissa.
02
math.h
Link -lm.
03
Base 2
2^exp.
04
[0.5, 1)
Mantissa.
05
ldexp
Inverse.
06
vs modf
Different.
Fundamentals
Definition and Usage
Think of scientific notation in base 2: any nonzero number can be written as a fraction between 0.5 and 1 times a power of two. For 123.45, frexp returns mantissa ≈ 0.964 and exponent 7, because 0.964 × 27 ≈ 123.45.
The exponent is stored through a pointer parameter int *exp. The function returns the mantissa as a double. Reassemble with ldexp(mantissa, exponent).
💡
Beginner Tip
Do not confuse frexp with modf. modf(3.75, &i) gives decimal parts 0.75 and 3. frexp gives a binary mantissa and power-of-two exponent—closer to how IEEE-754 floats work.
Foundation
📝 Syntax
Standard C declaration:
C
double frexp(double x, int *exp);
Related variants
C
float frexpf(float x, int *exp); /* <math.h> */
long double frexpl(long double x, int *exp); /* <math.h> */
Parameters
x — the value to decompose.
exp — pointer to int where the binary exponent is stored.
Return Value
Normalized mantissa m such that x = m × 2*exp.
For nonzero x, |m| is in [0.5, 1).
frexp(0, &exp) returns 0.0 and sets *exp to 0.
Headers and linking
#include <math.h>
Compile: gcc frexp.c -std=c11 -o frexp -lm
Cheat Sheet
⚡ Quick Reference
Call
Mantissa (approx.)
Exponent
frexp(123.45, &e)
0.964
7
frexp(8.0, &e)
0.5
4
frexp(0.0, &e)
0.0
0
ldexp(m, e)
Rebuilds m × 2e
modf(3.75, &i)
Decimal split (not frexp)
Decompose
frexp(x, &e)
Split x
Recompose
ldexp(m, e)
m * 2^e
Decimal
modf(x, &i)
Int + frac
Formula
x = m * pow(2,e)
Identity
Hands-On
Examples Gallery
Compile every example with gcc file.c -std=c11 -o out -lm. Mantissa/exponent decomposition appears in low-level numeric code and custom float parsers.
📚 Getting Started
Extract mantissa and exponent from a floating-point value.
Example 1 — Split 123.45 into Mantissa and Exponent
Not the same as modf() (decimal split) or logb() (exponent only).
Link with -lm on GCC/Clang Unix-like builds.
Performance
⚡ Optimization
frexp() is a thin wrapper over bit-level float representation on most platforms. Use it when you need true IEEE decomposition; do not hand-roll mantissa extraction unless you fully understand float internals and edge cases.
Wrap Up
Conclusion
frexp() decomposes a double into a binary mantissa and exponent so that x = m × 2e. Pair it with ldexp() to rebuild values, and distinguish it from modf()’s decimal split.
Continue with hypot() for distance calculations, or explore ldexp() as the inverse operation.
Assume mantissa is always positive (sign follows x)
Expect mantissa in [0.5, 1) when x is zero
Ignore NaN/INF edge cases in robust code
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about frexp()
Mantissa and exponent split in C, explained simply.
5
Core concepts
🔢01
x = m·2e
Identity.
Basics
📚02
[0.5, 1)
|m| range.
Rule
📈03
int *exp
Out param.
API
📄04
ldexp
Inverse.
Pair
🔄05
vs modf
Binary.
Compare
❓ Frequently Asked Questions
frexp(x, &exp) splits x into a normalized mantissa (return value) and a binary exponent (stored in *exp) such that x = mantissa * 2^exp. For example, frexp(123.45, &e) returns about 0.964 with e = 7.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double frexp(double x, int *exp).
For nonzero x, the absolute value of the returned mantissa is in [0.5, 1). For x = 0, frexp returns 0.0 and sets *exp to 0.
frexp splits x into mantissa and exponent. ldexp does the reverse: ldexp(m, e) returns m * 2^e. They are inverse operations: ldexp(frexp(x, &e), e) reconstructs x.
frexp decomposes x into a binary mantissa and power-of-two exponent (scientific-style base 2). modf splits x into a decimal integer part and fractional part. Different decompositions for different tasks.
frexp(0.0, &exp) returns 0.0 and sets *exp to 0. This is a special case outside the usual [0.5, 1) mantissa range.
Did you know?
IEEE-754 double values store a sign bit, an 11-bit exponent, and a 52-bit fraction. frexp() exposes the same idea at the math-library level: a normalized mantissa and a power-of-two exponent—without you reading raw bits.