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


scalb

You can use the scalb 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
The scalb function performs efficient scaling of its floating-point argument by a power of 2.

scalb(x,n) = x×2n

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 scalb(x,n) 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 the scalb function is a zero, a NaN, or an Infinity. In this table, n is any integer.
Special cases for the scalb function
OperationResultExceptions raised
scalb(+0,n) +0None
scalb(-0,n) -0 None
scalb(NaN,n) NaNNone[33]
scalb(+ ,n) + None
scalb(- ,n) - None

EXAMPLES
z = scalb(1, 3);  /* z = 1  23 = 8 */

[33] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996