Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 10 - Transcendental Functions / Exponential Functions


ldexp

You can use the ldexp 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
The ldexp function computes the value x×2n without computing 2n . This is an ANSI standard C library function.

ldexp(x,n) = x×2n

The scalb function (described on page 10-19) performs the same operation as this function. The frexp function performs the inverse operation; that is, it splits x into its fraction field and exponent field.

EXCEPTIONS
When x is finite and nonzero, either the result of ldexp(x,n) 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 the ldexp function is a zero, a NaN, or an Infinity. In this table, n is any integer.
Special cases for the ldexp function
OperationResultExceptions raised
ldexp(+0,n) +0None
ldexp(-0,n) -0 None
ldexp(NaN,n) NaNNone[31]
ldexp(+ ,n) + None
ldexp(- ,n) - 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.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996