frexp(3)
β¨ frexp(3) β¨ β okay bestie, we're splitting floats today π
Hi hi! So this page is all about frexp, and it lives in section 3 of the manual (that's the "library functions" girlies π
). Buckle up, it's actually cute.
πΈ NAME πΈ
frexp, frexpf, frexpl β these three iconic functions convert a floating-point number into its fractional and integral components. It's giving "take this number apart, respectfully" π
π LIBRARY π
Math library, aka libm, and you link it with -lm. No cap, you do have to link it.
π¦ SYNOPSIS π¦
#include <math.h>
double frexp(double x, int *e);
float frexpf(float x, int *e);
long double frexpl(long double x, int *e);
π Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
frexpf(), frexpl():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
(yes, the glibc β€ 2.19 girlies had to do it the old way, we don't talk about it π«Ά)
π DESCRIPTION π
So these functions take your number x and split it into two things: a normalized fraction, and an exponent. The exponent goes and lives inside e, which you passed as a pointer. That's it, that's the whole vibe. β¨
Like, x becomes <fraction> Γ 2^<exponent>, and the fraction part is the one frexp hands back to you. Obsessed with how tidy that is.
π RETURN VALUE π
These functions return the normalized fraction, and this part is important bestie:
- If your argument
xis not zero, the normalized fraction isxtimes a power of two, and its absolute value is always in the range1/2(inclusive) to1(exclusive). That's[0.5,1). Half-open intervals, main character energy. π - If
xis zero, the normalized fraction is zero, and zero is stored ine. Zero in, zero out, zero told. - If
xis a NaN, a NaN is returned, and the value of*eis unspecified. π« Don't go readingeafter that, it's giving chaos. - If
xis positive infinity (negative infinity), then positive infinity (negative infinity) is returned, and the value of*eis again unspecified. Same warning, same vibe check. β οΈ
π ERRORS π
No errors occur. Literally none. She's unbothered, she's thriving, she simply does not fail. π
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7).
frexp(),frexpf(),frexpl()β Thread safety β MT-Safe π₯
So yes, she's thread-safe. Multi-threaded besties, you may proceed. β¨
β STANDARDS β
C11, POSIX.1-2008. Certified, stamped, official. π
πΈ HISTORY πΈ
C99, POSIX.1-2001.
And the variant that returns double is also conformant to SVr4, 4.3BSD, and C89. She's been around, she's got range, she's an elder icon. π¦
π EXAMPLES π
The program below produces results such as the following:
$ ./a.out 2560
frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560
$ ./a.out -4
frexp(-4, &e) = -0.5: -0.5 * 2^3 = -4
Look at that. 0.625 is in [0.5,1), -0.5 is in [0.5,1) by absolute value. She said range-consistent and she MEANT it. ππ
π§ Program source π§
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
double x, r;
int e;
x = strtod(argv[1], NULL);
r = frexp(x, &e);
printf("frexp(%g, &e) = %g: %g * %d^%d = %g\n", x, r, r, 2, e, x);
exit(EXIT_SUCCESS);
}
Not me noticing <float.h> is included and never usedβ¦ she's just there for moral support, we love her anyway π
π SEE ALSO π
π Quick recap so you don't fumble: pass a pointer to anintfore, get back a fraction in[0.5,1)(by absolute value), and ifxis zero, NaN, or an infinity, read the RETURN VALUE section again before you touch*e. Fr fr.
And that's the whole page, bestie! This one came from the Linux man-pages, version 6.20, dated 2026-02-08 β so you know it's fresh. Go split some floats. You're gonna slay. πβ¨π«Ά
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms