C++ scalbln()

The scalbln() function in C++ takes two arguments: x and n, and scales x by FLT_RADIX raised to the power n.

In simple terms, the scalbln() function returns the product of x and FLT_RADIX raised to the power n.

FLT_RADIX is the value of the radix (integer base) of the exponent representation.

The function is defined in <cmath> header file. Also, you need to use <cfloat> header file to use FLT_RADIX.

scalbln(x, n) = x * FLT_RADIXn

scalbln() prototype [As of C++ 11 standard]

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); // Here, T is an integral type

It is identical to scalbn() function except that it takes long int as second parameter.

scalbln() Parameters

The scalbln() takes two arguments:

  • x - The value representing the significand.
  • n - The value of exponent of FLT_RADIX.

scalbln() Return Value

The scalbln() function returns x * FLT_RADIXn.

If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL with the proper sign.

Example: How scalbln() works?

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

int main ()
	long int n = 133;
	double x = 3.056, result;
	result = scalbln (x, n);
	cout << x << " * " << FLT_RADIX << "^" << n << " = " << result << endl;
	return 0;

When you run the program, the output will be:

3.056 * 2^133 = 3.32769e+40
Did you find this article helpful?