Important: The information in this document is obsolete and should not be used for new development.
ldexp
You can use theldexp
function to perform efficient scaling by a power of 2.
double_t ldexp (double_t x, int n);
x
- Any floating-point number.
n
- An integer representing a power of 2 by which
x
should be multiplied.DESCRIPTION
Theldexp
function computes the value without computing . This is an ANSI standard C library function.
The
scalb
function (described on page 10-19) performs the same operation as this function. Thefrexp
function performs the inverse operation; that is, it splitsx
into its fraction field and exponent field.EXCEPTIONS
When x is finite and nonzero, either the result of is exact or it raises one of the following exceptions:
- inexact (if an overflow or underflow occurs)
- 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-10 shows the results when the floating-point argument to theldexp
function is a zero, a NaN, or an Infinity. In this table, n is any integer.
Special cases for the ldexp
functionOperation Result Exceptions raised +0 None None NaN None[31] + None None EXAMPLES
z = ldexp(3.0, 3); /* z = 3 23 = 24 */ z = ldexp(0.0, 3); /* z = 0 23 = 0 */
[31] If the NaN is a signaling NaN, the invalid exception is raised.