ADVERTISEMENT
ADVERTISEMENT

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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.