ldexp in c

What is ldexp in c programming?

ldexp in c is used to calculate x multiplied by 2 raised to the power of exponent.

This function is defined in math.h header file.

Prototype

double ldexp(double x, int expo);

Parameters

ldexp function takes one floating point value, one exponent value.

Return value

It returns x multiplied by 2 raised to the power of exponent.


Example program for ldexp in c

#include<stdio.h>
#include<math.h>
int main()
{
  double x=0.55,res;
  int a=2;
  res=ldexp(x,a);
  printf("The result is %f \n",res);
  return 0;
}
Example for ldexp in c programming language
Output for example for ldexp in c programming language

While using gcc use below command to add math header.

gcc file_name.c -lm

Code explanation

The ldexp function is called and calculated value of given input data which is raised to the value 2 is being printed onto the console.

Idexp() Man page


Difference between ldexp and exp in c

ldexp in c is used to calculate x multiplied by 2 raised to the power of the exponent. exp function is used to calculate the exponential value of a given number.

ldexp function takes two parameters. exp function takes one parameter.

Prototypes are as follows

double ldexp(double x, int expo);

double exp(double value1);
ldexpexp
Used to calculate x multiplied by 2 raised to the power of exponent.Used to calculate exponential value of a given number.
double ldexp(double x, int expo);double exp(double value1);

People also ask for

What is the difference between ldexp and frexp in c?

ldexp in c is used to calculate x multiplied by 2 raised to the power of the exponent. frexp in c is used to calculate the mantissa and the integer pointed to by exponent i.e. x=mantissa*2^exponent.