Skip to content
Related Articles

Related Articles

scalbln() function in C++ STL
  • Last Updated : 12 Jul, 2018
GeeksforGeeks - Summer Carnival Banner

The scalbln() is a built-in function in C++ STL which takes two arguments and scales x by FLT_RADIX raised to the power n. The function returns the product of x and FLT_RADIX raised to the power n.

FLT_RADIX: It is the value of the radix (integer base) of the exponent representation.

Syntax:

scalbln (x, n)

Parameters: The function accepts two mandatory parameters which are described below:

  • x– It specifies the value representing the significand. The data-type can be double, float or long-double.
  • n– It specifies the exponent of FLT_RADIX. The parameter is of data-type long-int.

Return Type: The function returns the product of x and FLT_RADIX raised to the power n. The returned value is of the same data-type as of x.



Below programs illustrate the above function:

Program 1:




// C++ program to illustrate
// scalbln() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    long int n = 0;
    double x = 2.12, result;
    result = scalbln(x, n);
    cout << x << " * " << FLT_RADIX << "^" 
    << n << " = " << result << endl;
  
    return 0;
}
Output:
2.12 * 2^0 = 2.12

Program 2:




// C++ program to illustrate
// scalbln() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    long int n = 9999999;
    double x = 19.8, result;
    result = scalbln(x, n);
    cout << x << " * " << FLT_RADIX << "^" 
    << n << " = " << result << endl;
  
    return 0;
}
Output:
19.8 * 2^9999999 = inf
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :