Math Scalbn Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Scalbn Function

Math Scalbn Function

BLUF: Mastering Math Scalbn Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Scalbn Function

C++ is renowned for its efficiency. Learn how Math Scalbn Function enables low-level control and high-performance computing in the tutorial below.

C++ Math scalbn

The function calculates the result of multiplying a specified number by FLT_RADX raised to the exponent value.

Suppose a number is 'x' and exponent is 'n':

Example

scalbn(x,n) = x * ( FLT_RADX)n

Syntax

Example

float scalbn(float x, int n);
double scalbn(double x, int n);
long double scalbn(long double x, int n);
double scalbn(integral x, int n);

Parameter

x : The value of the significand.

n : The value of the exponent.

Return value

It calculates the result of x multiplied by FLT_RADX raised to the nth power.

Example 1

Let's examine a basic scenario where the value assigned to variable x is of integer data type.

Example

#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
    int x=4;
    int n=2;
    std::cout << "Value of x is : " <<x<< std::endl;
    cout<<"4 * 2^2 = "<<scalbn(x,n);
    return 0;
}

Output:

Output

Value of x is : 4
4 * 2^2 = 16

In this instance, the variable x holds a value of 4. As a result, the scalbn function scales 4 by FLT_RADX to the power of 2.

Example 2

Let's consider a basic example where the variable x is of type float.

Example

#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
     float x=3.4;
     int n=5;
     std::cout << "Value of x is : " <<x<< std::endl;
     cout<<"3.4 * 2^5 = "<<scalbn(x,n);
     return 0;
}

Output:

Output

Value of x is : 3.4
3.4 * 2^5 = 108.8

In this instance, the variable x is assigned the value of 3.4. Hence, the scalbn function multiplies 3.4 by FLT_RADIX to the power of 5.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience