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 nexttowardd32(_Decimal32 x, _Decimal128 y);
_Decimal64 nexttowardd64(_Decimal64 x, _Decimal128 y);
_Decimal128 nexttowardd128(_Decimal128 x, _Decimal128 y);
_Decimal32 nexttoward(_Decimal32 x, _Decimal128 y); /*C++ only*/
_Decimal64 nexttoward(_Decimal64 x, _Decimal128 y); /*C++ only*/
_Decimal128 nexttoward(_Decimal128 x, _Decimal128 y);/*C++ only*/
General description
The nexttoward() family
of functions compute the next representable decimal floating-point
value following
x in the direction of
y.
Notes: - To use IEEE decimal floating-point, the hardware must have the
Decimal Floating-Point Facility installed.
- These functions work in IEEE decimal floating-point format. See
"IEEE Decimal Floating-Point" for more information.
Returned value
If successful, they return
the next representable value in the specified format after x in the
direction of y.
If... |
Then... |
x equals y |
y (of type x)
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 is finite and the
correct function value would overflow |
a range error occurs and ±HUGE_VAL_D32, ±HUGE_VAL_D64,
or ±HUGE_VAL_D128 (with the same sign as x)
is returned by nexttowardd32(), nexttowardd64() or nexttowardd128(),
respectively. |
x does not equal y and
the correct subroutine value is subnormal, 0, or underflows |
a range error occurs and either the correct
function value (if representable) or 0.0 is returned. |
x or y is
a NaN |
a NaN is returned. |
Example
⁄* CELEBN08
This example illustrates the nexttowardd32() function.
*⁄
#define __STDC_WANT_DEC_FP__
#include <math.h>
#include <stdio.h>
static void try_nt(_Decimal32 x, _Decimal128 y)
{
_Decimal32 r = nexttowardd32(x, y);
printf("nexttowardd32(%12.12HG, %12.12DDG) = % 12.12HG\n", x, y, r);
return;
}
int main(void)
{
try_nt( 2.000000DF , 2.00000001DL );
try_nt(-2.000000DF , -2.00000001DL );
try_nt( 2.000000DF , 2.00000000DL );
try_nt( 2.000000DF , 1.99999999DL );
try_nt(-2.000000DF , -1.99999999DL );
try_nt( 9.999999E+96DF, 9.99999999E+96DL);
try_nt( 1.000000E-95DF, 0.99999999E-95DL);
return 0;
}