This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
fegetround,fesetroundGets or sets the current floating-point rounding mode.
int fegetround(void);int fesetround(int round_mode);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.
On success,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.
On success,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>:
| Macro | Description |
|---|---|
FE_DOWNWARD | Round towards negative infinity. |
FE_TONEAREST | Round towards the nearest. |
FE_TOWARDZERO | Round towards zero. |
FE_UPWARD | Round towards positive infinity. |
The default behavior ofFE_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:
rint andnearbyint.The current rounding mode doesn't affect these operations:
trunc,ceil,floor, andlround library functions.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, seefenv_access.
Important
Prior to Windows 10 version 14393,fenv.h definedFE_UPWARD = 0x0100 andFE_DOWNWARD = 0x0200. In Windows version 14393, this header was updated to address a bug in which some APIs would interpretFE_UPWARD asFE_DOWNWARD, and vice-versa. Starting in Windows version 14393,FE_UPWARD = 0x0200 andFE_DOWNWARD = 0x0100, reversing their previous values.If you compiled your app against an old Windows SDK version (this issue depends on SDK version, not OS version or VS version) you might encounter this issue. Update your app to target the latest Windows SDK so that the definitions ofFE_UPWARD andFE_DOWNWARD are consistent with the Windows implementation. If you can't update your app to target a later Windows SDK, you can defineFE_UPWARD as0x0100 andFE_DOWNWARD as0x0200 in your code.
| Function | C header | C++ header |
|---|---|---|
fegetround,fesetround | <fenv.h> | <cfenv> |
For more information, seeCompatibility.
Alphabetical function referencenearbyint,nearbyintf,nearbyintlrint,rintf,rintllrint,lrintf,lrintl,llrint,llrintf,llrintl
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?