Home »
C++ programming language
scalbn() Function with Example in C++
C++ scalbn() function: Here, we are going to learn about the scalbn() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on May 25, 2020
C++ scalbn() function
scalbn() function is a library function of cmath header. It scales the significand using floating-point base exponent (int) i.e. it is used to calculate the product of the given significand and FLT_RADIX raised to the power of the given exponent. It accepts two parameters significand and exponent and returns the result of significand * FLT_RADIXexponent.
Syntax
Syntax of scalbn() function:
C++11:
double scalbn (double x , int n);
float scalbn (float x , int n);
long double scalbn (long double x, int n);
double scalbn (T x , int n);
Parameter(s)
- x, n – represent the value of significand and exponent.
Return value
It returns the product of the given significand and FLT_RADIX raised to the power of the given exponent.
Sample Input and Output
Input:
double x = 10;
int n = 2;
Function call:
scalbn(x,n);
Output:
40
Example
C++ code to demonstrate the example of scalbn() function:
// C++ code to demonstrate the example of
// scalbn() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
double x;
int n;
x = 10;
n = 2;
cout << "scalbn(" << x << "," << n << "): " << scalbn(x, n);
cout << endl;
x = 5.3;
n = 2;
cout << "scalbn(" << x << "," << n << "): " << scalbn(x, n);
cout << endl;
x = 15.46;
n = 12.56;
cout << "scalbn(" << x << "," << n << "): " << scalbn(x, n);
cout << endl;
x = -10.2;
n = 2;
cout << "scalbn(" << x << "," << n << "): " << scalbn(x, n);
cout << endl;
return 0;
}
Output
scalbn(10,2): 40
scalbn(5.3,2): 21.2
scalbn(15.46,12): 63324.2
scalbn(-10.2,2): -40.8
Reference: C++ scalbn() function