fe_dec_getround() — Get the current rounding mode
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C/C++ DFP | both | z/OS® V1.8 |
Format
#define __STDC_WANT_DEC_FP__
#include <fenv.h>
int fe_dec_getround(void);
General description
The fe_dec_getround function gets the current rounding mode for decimal floating-point operations.
The following rounding modes are defined for decimal floating-point, and are located in fenv.h:
- FE_DEC_DOWNWARD
- rounds towards minus infinity
- FE_DEC_TONEAREST
- rounds to nearest
- FE_DEC_TOWARDZERO
- rounds toward zero
- FE_DEC_UPWARD
- rounds toward plus infinity
- FE_DEC_TONEARESTFROMZERO
- rounds to nearest, ties away from zero
- _FE_DEC_AWAYFROMZERO
- rounds away from zero
- _FE_DEC_TONEARESTTOWARDZERO
- rounds to nearest, ties toward zero
- _FE_DEC_PREPAREFORSHORTER
- rounds to prepare for shorter precision
Notes:
- To use IEEE decimal floating-point, the hardware must have the Decimal Floating-Point Facility installed.
- This function works in IEEE decimal floating-point format. See "IEEE Decimal Floating-Point" for more information.
Returned value
If successful, returns the value of the current rounding mode for decimal floating-point operations.
If there is no such rounding mode or the current rounding mode can't be determined returns -1.
Example
/* CELEBF77
sample program that issues fe_dec_getround()/setround()
This program calls fe_dec_getround() to get the DFP rounding mode.
Then it will compare the returned value with FE_DEC_TONEAREST
rounding mode. If not the same, it will call fe_dec_setround() to
set the rounding mode to the desired value FE_DEC_TONEAREST.
*/
#define __STDC_WANT_DEC_FP__
#include <fenv.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]){
int r;
if ((r = fe_dec_getround()) == -1){
perror("fe_dec_getround");
exit (-1);
}
printf("The Decimal floating point rounding mode is %d\n", r);
if (r != FE_DEC_TONEAREST){
printf("The DFP rounding mode is not FE_DEC_TONEAREST.\n");
if (fe_dec_setround(FE_DEC_TONEAREST) == -1){
perror("fe_dec_setround");
exit (-1);
}
}
printf("The DFP rounding mode has been set to FE_DEC_TONEAREST.\n");
return 0;
}