scalbln() Function with Example in C++

C++ scalbln() function: Here, we are going to learn about the scalbln() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on May 25, 2020

C++ scalbln() function

scalbln() function is a library function of cmath header. It scales the significand using floating-point base exponent (long 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 of scalbln() function:

C++11:

     double scalbln (double x     , long int n);
      float scalbln (float x      , long int n);
long double scalbln (long double x, long int n);
     double scalbln (T x          , long 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.

Example:

    Input:
    double x = 10;
    long int n = 2;
    
    Function call:
    scalbln(x,n);
    
    Output:
    40

C++ code to demonstrate the example of scalbln() function

// C++ code to demonstrate the example of
// scalbln() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    double x;
    long int n;

    x = 10;
    n = 2;
    cout << "scalbln(" << x << "," << n << "): " << scalbln(x, n);
    cout << endl;

    x = 5.3;
    n = 2;
    cout << "scalbln(" << x << "," << n << "): " << scalbln(x, n);
    cout << endl;

    x = 15.46;
    n = 12.56;
    cout << "scalbln(" << x << "," << n << "): " << scalbln(x, n);
    cout << endl;

    x = -10.2;
    n = 2;
    cout << "scalbln(" << x << "," << n << "): " << scalbln(x, n);
    cout << endl;

    return 0;
}

Output

scalbln(10,2): 40
scalbln(5.3,2): 21.2
scalbln(15.46,12): 63324.2
scalbln(-10.2,2): -40.8

Reference: C++ scalbln() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.