scalbn() function in C++
Last Updated :
14 Feb, 2023
The scalbn() function is defined in the cmath header file. This function is used to calculate the product of given number x and FLT_RADIX raised to the power n. Syntax:-
float scalbn(float x, int n);
or
double scalbn(double x, int n);
or
long double scalbn(long double x, int n);
or
double scalbn(integral x, int n);
Parameters:- This method takes two parameters:
- x: This represents the value of significand.
- n: This represents the value of the exponent.
Return Value: This function returns the product of given number x and FLT_RADIX raised to the power n. with the help of formula:
scalbn(x, n) = x * FLT_RADIXn
Time Complexity: O(1)
Space Complexity: O(1)
Below programs illustrate the above function:- Example 1:-
cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 7;
int x = 5;
int ans;
ans = scalbn(x, n);
cout << x << " * "
<< FLT_RADIX << "^"
<< n << " = "
<< ans << endl;
return 0;
}
|
Example 2:-
cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 7;
double x = 3.9;
int ans;
ans = scalbn(x, n);
cout << x << " * "
<< FLT_RADIX << "^"
<< n << " = "
<< ans << endl;
return 0;
}
|
Share your thoughts in the comments
Please Login to comment...