fe_dec_getround and fe_dec_setround Subroutines

Purpose

Reads and sets the IEEE decimal floating-point rounding mode.

Library

Standard C Library (libc.a)

Syntax

#include <fenv.h>
int fe_dec_getround ();
int fe_dec_setround (RoundMode);
int RoundMode

Description

The fe_dec_getround subroutine returns the current rounding mode. The fe_dec_setround subroutine changes the rounding mode to the RoundMode parameter and returns the value of zero if it successfully completes.

Decimal floating-point rounding occurs when the infinitely precise result of a decimal floating-point operation cannot be represented exactly in the destination decimal floating-point format. The IEEE Standard for decimal floating-point arithmetic defines five modes that round the floating-point numbers: round toward zero, round to nearest, round toward +INF, round toward -INF, and round to nearest ties away from zero. Once a rounding mode is selected, it affects all subsequent decimal floating-point operations until another rounding mode is selected.

Tip: The default decimal floating-point rounding mode is the round to nearest mode. All C main programs begin with the rounding mode that is set to round to nearest.
The encodings of the rounding modes are defined in the ANSI C Standard. The fenv.h file contains definitions for the rounding modes. The following table shows the fenv.h definition, the ANSI C Standard value, and a description of each rounding mode.
fenv.h definition ANSI value Description
FE_DEC_TONEAREST 0 Round to nearest
FE_DEC_TOWARDZERO 1 Round toward zero
FE_DEC_UPWARD 2 Round toward +INF
FE_DEC_DOWNWARD 3 Round toward -INF
FE_DEC_TONEARESTFROMZERO 4 Round to nearest ties away from zero

Parameters

Item Description
RoundMode Specifies one of the following modes: FE_DEC_TOWARDZERO, FE_DEC_TONEAREST, FE_DEC_UPWARD, FE_DEC_DOWNWARD, FE_DEC_TONEARESTFROMZERO.

Return Values

On successful completion, the fe_dec_getround subroutine returns the current rounding mode. Otherwise , it returns -1.

On successful completion, the fe_dec_setround subroutine returns the value of zero. Otherwise, it returns -1.