frexpl Function

Gets the fraction and the exponent of a double precision floating-point number.

Include

<math.h>

Prototype

long double frexp (long double x, int *exp);

Arguments

x
floating-point value for which to return the fraction and exponent
exp
pointer to a stored integer exponent

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)
{
  long double x,y;
  int n;

  x = 50.0;
  y = frexpl(x, &n);
  printf("For frexpl of %Lf\n the fraction is %Lf\n ", x, y);
  printf("  and the exponent is %d\n\n", n);

  x = -2.5;
  y = frexpl(x, &n);
  printf("For frexpl of %Lf\n the fraction is %Lf\n ", x, y);
  printf("  and the exponent is %d\n\n", n);

  x = 0.0;
  y = frexpl(x, &n);
  printf("For frexpl of %Lf\n the fraction is %Lf\n ", x, y);
  printf("  and the exponent is %d\n\n", n);
}

Example Output

For frexpl of 50.000000
  the fraction is 0.781250
   and the exponent is 6

For frexpl of -2.500000
  the fraction is -0.625000
   and the exponent is 2

For frexpl of 0.000000
  the fraction is 0.000000
   and the exponent is 0