Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#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);
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.
⁄* 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);
}
The mantissa is 0.512500 and the exponent is 5