Gets or sets the current floating-point rounding mode.
int fegetround(void); int fesetround( int round_mode );
The rounding mode to set, as one of the floating-point rounding macros. If the value isn't equal to one of the floating-point rounding macros, the rounding mode isn't changed.
fegetround returns the rounding mode as one of the floating point rounding macro values. It returns a negative value if the current rounding mode can't be determined.
fesetround returns 0. Otherwise, a non-zero value is returned.
Floating-point operations can use one of several rounding modes. These modes control which direction the results of floating-point operations are rounded toward when the results are stored. Here are the names and behaviors of the floating-point rounding macros defined in <fenv.h>:
||Round towards negative infinity.|
||Round towards the nearest.|
||Round towards zero.|
||Round towards positive infinity.|
The default behavior of
FE_TONEAREST is to round results midway between representable values toward the nearest value with an even (0) least significant bit.
The current rounding mode affects these operations:
The results of floating-point arithmetic operators outside of constant expressions.
The library rounding functions, such as
Return values from standard library mathematical functions.
The current rounding mode doesn't affect these operations:
Floating-point to integer implicit casts and conversions, which always round towards zero.
The results of floating-point arithmetic operators in constant expressions, which always round to the nearest value.
To use these functions, you must turn off floating-point optimizations that could prevent access by using the
#pragma fenv_access(on) directive prior to the call. For more information, see
|Function||C header||C++ header|
For more compatibility information, see Compatibility.
Submit and view feedback for