scalbln() function in C++ STL

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

2.12 * 2^0 = 2.12

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

19.8 * 2^9999999 = inf


My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.