C++ <cmath> - scalbln() Function
The C++ <cmath> scalbln() function returns the result of multiplying the significand (x) by FLT_RADIX raised to the power of the exponent (n). Mathematically, it can be expressed as:
scalbln(x,n) = x * FLT_RADIXn
On most platforms, FLT_RADIX is 2, which makes this function equivalent to ldexp().
scalbn() is similar to this function, except scalbn() takes int as second argument.
Syntax
double scalbln (double x, long int n); float scalbln (float x, long int n); long double scalbln (long double x, long int n); double scalbln (T x, long int n);
Parameters
x |
Specify the value representing the significand. |
n |
Specify the value of the exponent. |
Return Value
Returns x * FLT_RADIXn.
Example:
The example below shows the usage of scalbln() function.
#include <iostream> #include <cmath> using namespace std; int main (){ double x, result; long int n; x = 0.9; n = 4; result = scalbln(x, n); cout<<"Significand: "<<x<<"\n"; cout<<"Exponent: "<<n<<"\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