ldexp(), ldexpf(), ldexpl() — Multiply by a power of two
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
Format
#include <math.h>
double ldexp(double x, int exp);
float ldexp(float x, int exp); /* C++ only */
long double ldexp(long double x, int exp); /* C++ only */
float ldexpf(float x, int exp);
long double ldexpl(long double x, int exp);
General description
Calculates the value of x*(2exp).
Restriction: The ldexpf() and ldexpl() functions
do not support the _FP_MODE_VARIABLE feature test macro.
Returned value
Returns the calculated value.
Otherwise, if the correct calculated value is outside the range of representable values, ±HUGE_VAL is returned, according to the sign of the value. The value ERANGE is stored in errno to indicate that the result was out of range.
Special behavior for XPG4.2:
- Error Code
- Description
- ERANGE
- The result underflowed. ldexp() returns 0.0.
Example
CELEBL02
/* CELEBL02
This example computes y = 1.5*&lpar.2**5&rpar.
*/
#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
1.500000 times 2 to the power of 5 is 48.000000