C++ <cmath> - ldexp() Function
The C++ <cmath> 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 ldexp (float x, int exp); long double ldexp (long double x, int exp);
double ldexp (double x, int exp); float ldexp (float x, int exp); long double ldexp (long double x, int exp); //additional overloads for integral types double ldexp (T 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 <iostream> #include <cmath> using namespace std; int main (){ double x, result; int exp; x = 0.9; exp = 4; result = ldexp(x, exp); cout<<"Significand: "<<x<<"\n"; cout<<"Exponent: "<<exp<<"\n"; cout<<"Result: "<<result<<"\n"; return 0; }
The output of the above code will be:
Significand: 0.9 Exponent: 4 Result: 14.4
❮ C++ <cmath> Library