Gets the fraction and the exponent of a double precision floating-point number.
Include
<math.h>
Prototype
double frexp (double x, int *exp);
Arguments
x
exp
Return Value
Returns the fraction, exp
points to the exponent. If
x
is 0, the function returns 0 for both the fraction and
exponent.
Remarks
The absolute value of the fraction is in the range of 1/2 (inclusive) to 1 (exclusive). No domain or range error will occur.
Example
#include <math.h>
#include <stdio.h>
int main(void)
{
double x,y;
int n;
x = 50.0;
y = frexp (x, &n);
printf("For frexp of %f\n the fraction is %f\n ", x, y);
printf(" and the exponent is %d\n\n", n);
x = -2.5;
y = frexp (x, &n);
printf("For frexp of %f\n the fraction is %f\n ", x, y);
printf(" and the exponent is %d\n\n", n);
x = 0.0;
y = frexp (x, &n);
printf("For frexp of %f\n the fraction is %f\n ", x, y);
printf(" and the exponent is %d\n\n", n);
}
Example Output
For frexp of 50.000000
the fraction is 0.781250
and the exponent is 6
For frexp of -2.500000
the fraction is -0.625000
and the exponent is 2
For frexp of 0.000000
the fraction is 0.000000
and the exponent is 0