w3resource

C ldexp() function

C ldexp() function - Load exponent of a floating-point number

Syntax:

double ldexp(double x, int exponent)

The ldexp() function is used to calculate the value of x * (2aexp).

Parameters:

Name Description Required /Optional
x Floating-point value. Required
exponent Integer exponent. Required

Return value from ldexp()

  • returns the value of x * (2aexp).

Example: ldexp() function

The following example shows the usage of ldexp() function.

#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double x, y;
   int p;
 
   x = 3;
   p = 2;
   y = ldexp(x,p); 
   printf("%lf times 2 to the power of %d is %lf\n", x, p, y);
  
   x = 3;
   p = 3;
   y = ldexp(x,p); 
   printf("\n%lf times 2 to the power of %d is %lf\n", x, p, y);
   
   x = 1.5;
   p = 5;
   y = ldexp(x,p);
 
   printf("\n%lf times 2 to the power of %d is %lf\n", x, p, y);
}

Output:

3.000000 times 2 to the power of 2 is 12.000000

3.000000 times 2 to the power of 3 is 24.000000

1.500000 times 2 to the power of 5 is 48.000000

C Programming Code Editor:

Previous C Programming: C frexp()
Next C Programming: C log()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming/math/c-ldexp.php