C++ Math scalbn
The function calculates the result of multiplying a specified number by FLT_RADX raised to the exponent value.
Suppose a number is 'x' and exponent is 'n':
scalbn(x,n) = x * ( FLT_RADX)n
Syntax
float scalbn(float x, int n);
double scalbn(double x, int n);
long double scalbn(long double x, int n);
double scalbn(integral x, int n);
Parameter
x : The value of the significand.
n : The value of the exponent.
Return value
It calculates the result of x multiplied by FLT_RADX raised to the nth power.
Example 1
Let's examine a basic scenario where the value assigned to variable x is of integer data type.
#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
int x=4;
int n=2;
std::cout << "Value of x is : " <<x<< std::endl;
cout<<"4 * 2^2 = "<<scalbn(x,n);
return 0;
}
Output:
Value of x is : 4
4 * 2^2 = 16
In this instance, the variable x holds a value of 4. As a result, the scalbn function scales 4 by FLT_RADX to the power of 2.
Example 2
Let's consider a basic example where the variable x is of type float.
#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
float x=3.4;
int n=5;
std::cout << "Value of x is : " <<x<< std::endl;
cout<<"3.4 * 2^5 = "<<scalbn(x,n);
return 0;
}
Output:
Value of x is : 3.4
3.4 * 2^5 = 108.8
In this instance, the variable x is assigned the value of 3.4. Hence, the scalbn function multiplies 3.4 by FLT_RADIX to the power of 5.