idexp : <math.h> library function

The function double ldexp(double x, int exponent); returns the result of multiplying x with 2 raised to the power of exponent( x * 2exponent).

Function prototype of idexp

double ldexp(double x, int exponent);
  • x : A floating point value representing the mantisa.
  • exponent : An integer representing the value of exponent of 2.

Return value of idexp

It returns the value of x * 2exponent.

C program to show the use of idexp function

The following program shows the use of idexp function.

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

int main ()
  double x, result;
  int exponent;

  printf("Enter a number and exponent\n");
  scanf("%lf %d", &x, &exponent);
  /* It returns x*(2^exponent)  */
  result = ldexp(x, exponent);
  printf("%lf * 2^%d = %lf\n", x, exponent, result);
  return 0;

Program Output
Enter a number and exponent
3.5 4
3.500000 * 2^4 = 56.000000