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 x is not zero, the normalized fraction is x times a power of two, and its absolute value is always in the range 1/2 (inclusive) to 1 (exclusive). That's [0.5,1). Half-open intervals, main character energy. πŸ‘‘
  • If x is zero, the normalized fraction is zero, and zero is stored in e. Zero in, zero out, zero told.
  • If x is a NaN, a NaN is returned, and the value of *e is unspecified. 🫠 Don't go reading e after that, it's giving chaos.
  • If x is positive infinity (negative infinity), then positive infinity (negative infinity) is returned, and the value of *e is 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 an int for e, get back a fraction in [0.5,1) (by absolute value), and if x is 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms