Important: The information in this document is obsolete and should not be used for new development.
scalb
You can use thescalb
function to perform efficient scaling by a power of 2.
double_t scalb (double_t x, long int n);
x
- Any floating-point number.
n
- An integer representing a power of 2 by which
x
should be multiplied.DESCRIPTION
Thescalb
function performs efficient scaling of its floating-point argument by a power of 2.
Using the
scalb
function is more efficient than performing the actual arithmetic.This function performs the same operation as the
ldexp
transcendental function described on page 10-16.EXCEPTIONS
When x is finite and nonzero, either the result of is exact or it raises one of the following exceptions:
- inexact (if the result causes an overflow or underflow exception)
- overflow (if the result is outside the range of the data type)
- underflow (if the result is inexact and must be represented as a denormalized number or 0)
SPECIAL CASES
Table 10-12 shows the results when the floating-point argument to thescalb
function is a zero, a NaN, or an Infinity. In this table, n is any integer.
Special cases for the scalb
functionOperation Result Exceptions raised +0 None None NaN None[33] + None None
EXAMPLES
z = scalb(1, 3); /* z = 1 23 = 8 */
[33] If the NaN is a signaling NaN, the invalid exception is raised.