C++ Standard Library C++ STL Library

C++ <cmath> - scalbn() Function



The C++ <cmath> scalbn() function returns the result of multiplying the significand (x) by FLT_RADIX raised to the power of the exponent (n). Mathematically, it can be expressed as:

scalbn(x,n) = x * FLT_RADIXn

On most platforms, FLT_RADIX is 2, which makes this function equivalent to ldexp.

Syntax

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

Parameters

x Specify the value representing the significand.
n Specify the value of the exponent.

Return Value

Returns x * FLT_RADIXn.

Example:

The example below shows the usage of scalbn() function.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  double x, result;
  int n;
  x = 0.9;
  n = 4;

  result = scalbn(x, n);

  cout<<"Significand: "<<x<<"\n";
  cout<<"Exponent: "<<n<<"\n";
  cout<<"Result: "<<result<<"\n";
  return 0;
}

The output of the above code will be:

Significand: 0.9
Exponent: 4
Result: 14.4

❮ C++ <cmath> Library