frexp C Library Function

The function double frexp(double x, int *exponent); breaks the floating point number x into its mantisa (an absolute floating point number between 0.5(included) and 1.0(excluded)) and an integer exponent of 2. It decompose x such that:
x = mantisa * 2exponent

Function prototype of frexp

double frexp(double x, int *exponent);
  • x : A floating point value to be decomposed.
  • exponent : A pointer to an integer where the value of the exponent to be stored.

Return value of frexp

It returns the value of mantissa and also stores the exponent of 2 in the integer pointer passed to it as argument.
If x is zero, both mantisa and exponent are zero.
If x is negative, the mantisa returned by this function is negative.

C program using frexp function

The following program shows the use of frexp function to decompose a floating point number.

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

int main ()
  double value, fraction;
  int exponent;

  printf("Enter a number\n");
  scanf("%lf", &value);
  fraction = frexp(value , &exponent);
  printf("%lf = %lf * 2^%d\n", value, fraction, exponent);
  return 0;

Enter a number
512.000000 = 0.500000 * 2^10