C++ Math scalbln
The function calculates the result of multiplying a specified number by FLT_RADX raised to the exponent power.
Suppose a number is 'x' and exponent is 'n':
scalbn(x,n) = x * ( FLT_RADX)n
Syntax
float scalbln(float x, long int n);
double scalbln(double x, long int n);
long double scalbln(long double x, long int n);
double scalbln(integral x, long int n);
Parameter
x : The value of the significand.
n : The value of the exponent.
Return value
It calculates the result of multiplying x by FLT_RADX to the nth power.
Example 1
Let's explore a basic scenario where the variable x holds an integer data type.
#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
int x=3;
long n=3L;
std::cout << "Value of x is: " <<x<< std::endl;
cout<<"3 * 2^3 = "<<scalbn(x,n);
return 0;
}
Output:
Value of x is: 3
3 * 2^3 = 24
Example 2
Let's explore a straightforward scenario where the variable x is of the float data type.
#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
float x=7.2;
long n=2L;
std::cout << "Value of x is : " <<x<< std::endl;
cout<<"7.2 * 2^2 = "<<scalbln(x,n);
return 0;
}
Output:
Value of x is : 7.2
7.2 * 2^2 = 28.8