Format
#include <math.h>
double ldexp(double x, int exp);
Language Level: ANSI
Threadsafe: Yes.
Description
The ldexp() function calculates the value of x * (2exp).
Return Value
The ldexp() function returns the value of x*(2exp). If an overflow results, the function returns +HUGE_VAL for a large result or -HUGE_VAL for a small result, and sets errno to ERANGE.
Example that uses ldexp()
This example computes y as 1.5 times 2 to the fifth power (1.5*25):
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y;
int p;
x = 1.5;
p = 5;
y = ldexp(x,p);
printf("%lf times 2 to the power of %d is %lf\n", x, p, y);
}
/******************** Output should be similar to: **************
1.500000 times 2 to the power of 5 is 48.000000
*/
Related Information