rintd32(), rintd64(), rintd128() — Round to nearest integral 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 rintd32(_Decimal32 x);
_Decimal64 rintd64(_Decimal64 x);
_Decimal128 rintd128(_Decimal128 x);
_Decimal32 rint(_Decimal32 x); /* C++ only */
_Decimal64 rint(_Decimal64 x); /* C++ only */
_Decimal128 rint(_Decimal128 x); /* C++ only */
General description
These functions return the integral value (represented in a decimal floating-point mode) nearest x according to the rounding mode and might raise the "inexact" decimal floating-point exception if the result differs in value from the argument.
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
These functions are always successful.
Example
/* CELEBR21
This example illustrates the rintd32() function.
*/
#pragma strings(readonly)
#define __STDC_WANT_DEC_FP__
#include <fenv.h>
#include <math.h>
#include <stdio.h>
static void try_rm(int);
/* pass back printable rounding mode */
static
char *rm_str(int rm)
{
char *s = "undetermined";
switch (rm)
{
case FE_DEC_TONEAREST :
s = "FE_DEC_TONEAREST" ; break;
case FE_DEC_TOWARDZERO :
s = "FE_DEC_TOWARDZERO" ; break;
case FE_DEC_UPWARD :
s = "FE_DEC_UPWARD" ; break;
case FE_DEC_DOWNWARD :
s = "FE_DEC_DOWNWARD" ; break;
case FE_DEC_TONEARESTFROMZERO :
s = "FE_DEC_TONEARESTFROMZERO" ; break;
case _FE_DEC_TONEARESTTOWARDZERO :
s = "_FE_DEC_TONEARESTTOWARDZERO" ; break;
case _FE_DEC_AWAYFROMZERO :
s = "_FE_DEC_AWAYFROMZERO" ; break;
case _FE_DEC_PREPAREFORSHORTER :
s = "_FE_DEC_PREPAREFORSHORTER" ; break;
}
return s;
}
/* Try out one passed-in number with rounding mode */
static void try_rm(int rm)
{
_Decimal32 r32;
_Decimal32 d32 = 500.99DF;
(void)fe_dec_setround(rm);
r32 = rintd32(d32);
printf("rintd32(%.2HF) = %HG - rounding mode = %s\n",
d32, r32, rm_str(rm)
);
return;
}
int main()
{
try_rm( FE_DEC_TONEAREST );
try_rm( FE_DEC_TOWARDZERO );
try_rm( FE_DEC_UPWARD );
try_rm( FE_DEC_DOWNWARD );
try_rm( FE_DEC_TONEARESTFROMZERO );
try_rm(_FE_DEC_TONEARESTTOWARDZERO);
try_rm(_FE_DEC_AWAYFROMZERO );
try_rm(_FE_DEC_PREPAREFORSHORTER );
return 0;
}