frexp(), frexpf(), frexpl() — Extract mantissa and exponent of the floating-point value

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both

Format

#include <math.h>

double frexp(double x, int *expptr);
float frexp(float x, int *expptr);               /* C++ only */
long double frexp(long double x, int *expptr);   /* C++ only */
float frexpf(float x, int *expptr);
long double frexpl(long double x, int *expptr);

General description

Breaks down the floating-point value x into a component m for the normalized fraction component and another term n for the exponent, such that the absolute value of m is greater than or equal to 0.5 and less than 1.0 or equal to 0, and x = m * 2n. The function stores the integer exponent n at the location to which expptr points.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Restriction: The frexpf() and frexpl() functions do not support the _FP_MODE_VARIABLE feature test macro.

Returned value

Returns the normalized fraction m. If x is 0, the function returns 0 for both the fraction and exponent. The fraction has the same sign as the argument x. The result of the function cannot have a range error.

Example

CELEBF41
/* CELEBF41

This example decomposes the floating-point value of x, 16.4, into its
normalized fraction 0.5125, and its exponent 5.
It stores the mantissa in y and the exponent in n.

*/

#include <math.h>
#include <stdio.h>

int main(void)
{
double x, m;
int n;

x = 16.4;
m = frexp(x, &n);

printf("The fraction is %lf and the exponent is %d\n", m, n);
}

Output
The mantissa is 0.512500 and the exponent is 5