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 / Miscellaneous Functions


nextafter

You can use the nextafter functions to find out the next value that can be represented after a given value in a particular floating-point type.

float       nextafterf (float x, float y);
double      nextafterd (double x, double y);
x
Any floating-point number.
y
Any floating-point number.
DESCRIPTION
The nextafter functions (one for each data type) generate the next representable neighbor of x in the direction of y in the proper format.

The floating-point values representable in single and double formats constitute a finite set of real numbers. The nextafter functions illustrate this fact by returning the next representable value.

If x = y , nextafter(x,y) returns x if x and y are not signed zeros.

EXCEPTIONS
When x and y are finite and nonzero, either the result of nextafter(x,y) is exact or it raises one of the following exceptions:

  • inexact (if an overflow or underflow exception occurs)
  • overflow (if x is finite and the result is infinite)
  • underflow (if the result is inexact, must be represented as a denormalized number
    or 0, and x y)

SPECIAL CASES
Table 10-39 shows the results when one of the arguments to a nextafter function is a zero, a NaN, or an Infinity. In this table, x and y are finite, nonzero floating-point numbers.
Table 10-39 Special cases for the nextafter functions
OperationResultExceptions raised
nextafter(+0,y) Next representable number in direction of yUnderflow
nextafter(x,+0) Next representable number in direction of 0None
nextafter(-0,y) Next representable number in direction of yUnderflow
nextafter(-0,+0) +0None
nextafter(x,-0) Next representable number in direction of 0None
nextafter(+0,-0) -0 None
nextafter(NaN,y) NaN[63]None[64]
nextafter(x,NaN) NaNNone
nextafter(+ ,y) Largest respresentable numberNone[64]
nextafter(x,+ ) Next representable number greater than xNone
nextafter(- ,y) Smallest representable numberNone
nextafter(x,- ) Next representable number smaller than xNone

EXAMPLES
z = nextafterf(1.0, +  );/* z = 1.000000000000000000000012 
                              1.000000119209289551 */
z = nextafterd(1.0, +  );/* z = 1.00000000...0000000000000000012 
                              1.000000000000000222 */ 

[63] If both arguments are NaNs, the value of the first NaN is returned.
[64] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996