Latest web development tutorials

C library functions - ldexp ()

C standard library - <math.h> C standard library - <math.h>

description

C library functionsdouble ldexp (double x, int exponent ) Returns the xmultiplied by 2 to the power of theexponent.

statement

Here is ldexp () function's declaration.

double ldexp(double x, int exponent)

parameter

  • x - represents a valid digit floating-point value.
  • exponent - the value of the index.

return value

This function returns x * 2 exp.

Examples

The following example demonstrates the use of ldexp () function.

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

int main ()
{
   double x, ret;
   int n;

   x = 0.65;
   n = 3;
   ret = ldexp(x ,n);
   printf("%f * 2^%d = %f\n", x, n, ret);
   
   return(0);
}

Let's compile and run the above program, which will result in the following:

0.650000 * 2^3 = 5.200000

C standard library - <math.h> C standard library - <math.h>