Easy Tutorial
❮ C Function Abort C Function Ispunct ❯

C Library Function - ldexp()

C Standard Library - <math.h>

Description

The C library function double ldexp(double x, int exponent) returns x multiplied by 2 raised to the power of exponent.

Declaration

Here is the declaration for the ldexp() function.

double ldexp(double x, int exponent)

Parameters

Return Value

The function returns x * 2^exponent.

Example

The following example demonstrates the use of the 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 produce the following result:

0.650000 * 2^3 = 5.200000

C Standard Library - <math.h>

❮ C Function Abort C Function Ispunct ❯