nextafterd32, nextafterd64, nextafterd128, nexttowardd32, nexttowardd64, and nexttowardd128 Subroutines

Purpose

Compute the next representable decimal floating-point number.

Syntax

#include <math.h>
_Decimal32 nextafterd32 (x, y)
_Decimal32 x;
_Decimal32 y;

_Decimal64 nextafterd64 (x, y)
_Decimal64 x;
_Decimal64 y;

_Decimal128 nextafterd128 (x, y)
_Decimal128 x;
_Decimal128 y;

_Decimal32 nexttowardd32 (x, y)
_Decimal32 x;
_Decimal128 y;

_Decimal64 nexttowardd64 (x, y)
_Decimal64 x;
_Decimal128 y;

_Decimal128 nexttowardd128 (x, y)
_Decimal128 x;
_Decimal128 y;

Description

The nextafterd32, nextafterd64, and nextafterd128 subroutines compute the next representable decimal floating-point value following the x value in the direction of the y value. Therefore, if the y value is less than the x value, the nextafter subroutine returns the largest representable decimal floating-point number that is less than x.

If the value of x equals y, the nextafterd32, nextafterd64, and nextafterd128 subroutines return the value of y .

The nexttowardd32, nexttowardd64, and nexttowardd128 subroutines are equivalent to the corresponding nextafter subroutines, except that the second parameter has the _Decimal128 type, and the subroutines return the value of the y parameter that is converted to the type of the subroutine if the value of x equals that of y.

To check error situations, the application must set the errno global variable to zero and call the feclearexcept subroutine (FE_ALL_EXCEPT) before calling these subroutines. On return, if the errno is of the value of nonzero or the fetestexcept subroutine (FE_INVALID| FE_DIVBYZERO| FE_OVERFLOW| FE_UNDERFLOW) is of the value of nonzero, an error has occurred.

Parameters

Item Description
x Specifies the starting values. The next representable decimal floating-point number is found from the x parameter in the direction specified by the y parameter.
y Specifies the direction.

Return Values

Upon successful completion, the nextafterd32, nextafterd64, nextafterd128, nexttowardd32, nexttowardd64, and nexttowardd128 subroutines return the next representable decimal floating-point value following the value of the x parameter in the direction specified by the y parameter.

If x == y, y (of the x type) is returned.

If x is finite and the correct function value overflows, a range error occurs. The ±HUGE_VAL_D32, ±HUGE_VAL_D64, and ±HUGE_VAL_D128 (with the same sign as the x parameter) is returned respectively according to the returned type of the function.

If x or y is NaN, a NaN is returned.

If x != y and the correct subroutine value is subnormal, zero, or underflow, a range error occurs and either the correct function value (if representable) or a value of 0.0 is returned.

Errors

If the value of the x parameter is finite and the correct function value overflows, a range error occurs. The ±HUGE_VAL_D32, ±HUGE_VAL_D64, and ±HUGE_VAL_D128 (with the same sign as the x parameter) is returned respectively according to the returned type of the function.

If the value of the x parameter is not equal to that of the y parameter, and the correct subroutine value is subnormal, zero, or underflow, a range error occurs and either the correct function value (if representable) or a value of 0.0 is returned.