function
<cmath> <ctgmath>
scalbn
double scalbn (double x , int n); float scalbnf (float x , int n);long double scalbnl (long double x, int n);
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); // additional overloads for integral types
Scale significand using floating-point base exponent
Scales x by FLT_RADIX raised to the power of n, returning the same as:
scalbn(x,n) = x * FLT_RADIX n
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.
On most platforms, FLT_RADIX is 2, making this function equivalent to ldexp .
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 ).
There also exists another version of this function: scalbln , which is identical, except that it takes a long int as second argument.
Parameters
- x
- Value representing the significand.
- exp
- Value of the exponent.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* scalbn example */
#include <stdio.h> /* printf */
#include <float.h> /* FLT_RADIX */
#include <math.h> /* scalbn */
int main ()
{
double param, result;
int n;
param = 1.50;
n = 4;
result = scalbn (param , n);
printf ("%f * %d^%d = %f\n", param, FLT_RADIX, n, result);
return 0;
}
Output:
1.500000 * 2^4 = 24.000000
See also
- ldexp
- Generate value from significand and exponent (function)
- logb
- Compute floating-point base logarithm (function)