function
<cmath> <ctgmath>

scalbln

     double scalbln  (double x     , long int n);
      float scalblnf (float x      , long int n);
long double scalblnl (long double x, long int n);
     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); // additional overloads for integral types
Scale significand using floating-point base exponent (long)
Scales x by FLT_RADIX raised to the power of n, returning the result of computing:

scalbn(x,n) = x * FLT_RADIXn

Presumably, x and n are the components of a floating-point number in the system; In such a case, this function may be optimized to be more efficient than the theoretical operations to compute the value explicitly.

There also exists another version of this function: scalbn, which is identical, except that it takes an int as second argument.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

Value representing the significand.</dd>
exp
Value of the exponent.

Return Value

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 (or HUGE_VALF or HUGE_VALL) with the proper sign, and an overflow range error may occur (if too small, the function returns zero, and an underflow range error may occur).

If a range error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: either FE_OVERFLOW or FE_UNDERFLOW is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* scalbln example */
#include <stdio.h>      /* printf */
#include <float.h>      /* FLT_RADIX */
#include <math.h>       /* scalbn */

int main ()
{
  double param, result;
  long n;

  param = 1.50;
  n = 4L;
  result = scalbln (param , n);
  printf ("%f * %d^%d = %f\n", param, FLT_RADIX, n, result);
  return 0;
}


Output:

1.500000 * 2^4 = 24.000000

See also