C <math.h> - ldexp() Function
The C <math.h> ldexp() function returns the result of multiplying the significand (x) by 2 raised to the power of the exponent (exp), i.e., x * 2exp.
Syntax
double ldexp (double x, int exp); float ldexpf (float x, int exp); long double ldexpl (long double x, int exp);
Parameters
x |
Specify floating point value representing the significand. |
exp |
Specify value of the exponent. |
Return Value
Returns x * 2exp.
Example:
The example below shows the usage of ldexp() function.
#include <stdio.h> #include <math.h> int main (){ double x, result; int y; x = 0.9; y = 4; result = ldexp(x, y); printf("Significand: %lf\n", x); printf("Exponent: %d\n", y); printf("Result: %lf\n", result); return 0; }
The output of the above code will be:
Significand: 0.900000 Exponent: 0.900000 Result: 14.400000
❮ C <math.h> Library