Home >>C Math Functions >C math ldexp() function

C math ldexp() function

C math ldexp() function

C math ldexp() function is used to return the value of given input x multiplied by 2 raised to the given input power of exponent.

Syntax:
double ldexp(double x, int exponent)

Parameter Values

Parameter Description
x It is the floating point value representing the significand.
exponent It is the value of the exponent.
Here is an example of Idexp() 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);
}

Output:
0.650000 * 2^3 = 5.200000
Example-2

#include <stdio.h>
#include <math.h>
int main () 
{
double x, ret;
int n;
x = 2.5;
n = 11;
ret = ldexp(x ,n);
printf("%f * 2^%d = %f\n", x, n, ret);
return(0);
}

Output:
2.500000 * 2^11 = 5120.000000

No Sidebar ads