nextafterd32(), nextafterd64(), nextafterd128() — Next representable decimal floating-point value

Standards

Standards / Extensions C or C++ Dependencies
C/C++ DFP both z/OS® V1.8

Format

#define __STDC_WANT_DEC_FP__
#include <math.h>

_Decimal32  nextafterd32(_Decimal32 x, _Decimal32 y); 
_Decimal64  nextafterd64(_Decimal64 x, _Decimal64 y);
_Decimal128 nextafterd128(_Decimal128 x, _Decimal128 y);
_Decimal32  nextafter(_Decimal32 x, _Decimal32 y);  /* C++ only */
_Decimal64  nextafter(_Decimal64 x, _Decimal64 y);  /* C++ only */
_Decimal128 nextafter(_Decimal128 x, _Decimal128 y);/* C++ only */

General description

The nextafter() function computes the next representable decimal floating-point value following x in the direction of y. Thus, if y is less than x, nextafter() returns the largest representable decimal floating-point number less than x.
Notes:
  1. To use IEEE decimal floating-point, the hardware must have the Decimal Floating-Point Facility installed.
  2. These functions work in IEEE decimal floating-point format. See "IEEE Decimal Floating-Point" for more information.

Returned value

The nextafter() functions return the next representable value following x in the direction of y.

If... Then...
x equals y copysign(x,y) is returned.
x is less than y the next representable value after x is returned.
x is greater than y the largest representable decimal floating-point number less than x is returned.
x or y is a NaN either x or y is returned.

Example

⁄* CELEBN07

   This example illustrates the nextafterd128() function.

*⁄

#define  __STDC_WANT_DEC_FP__
#include <math.h>
#include <stdio.h>

int main(void)
{
   _Decimal128 x = 123456789.70DL, dir = 123456790.00DL, z;

   z = nextafterd128(x, dir);

   printf("The next number after %DDf in the direction %DDf\n is %DDf\n",
          x, dir, z);
}

Related information