scalbn() function in C++


In this article we will be discussing the working, syntax and examples of scalbn() function in C++ STL.

What is scalbn()?

scalbn() function is an inbuilt function in C++ STL, which is defined in the <cmath> header file. scalbn() function is used to scale significantly using the floating point base exponent.

Significand is a part of a floating-point number consisting of its significant digits, depending upon the interpretation of the exponent significand can be an integer or a fraction.

The function calculates the product of num and FLT_RADIX to the power n, where FLT_RADIX is the base of all floating point data types and num is the significant value. And n exponent value

Syntax

double scalbn( double num, int n );
float scalbn( float num, int n );
long double scalbn( long double num, int n );

Parameters

The function accepts following parameter(s) −

  • num − It is the value of significand.
  • n − It is the value exponent.

Return value

This function returns num * FLT_RADIX^n if it is a success, else returns math_errhandling error.

Example

Input

scalbn(5, 7);

Output

640

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main(){
   int a = 7;
   int b = 5;
   int hold;
   hold = scalbn(b, a);
   cout <<"Equation is: "<< b << " * " << FLT_RADIX << "^" << a << " = "<<hold<< endl;
   return 0;
}

Output

Equation is: 5 * 2^7 = 640

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main(){
   float a = 2.3;
   float b = 7.8;
   float hold;
   hold = scalbn(b, a);
   cout <<"Equation is: "<< b << " * " << FLT_RADIX << "^" << a << " = "<<hold<< endl;
   return 0;
}

Output

Equation is: 7.8 * 2^2.3 = 31.2

Updated on: 17-Apr-2020

28 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements