C++ <cfenv> - FE_TOWARDZERO
The FE_TOWARDZERO macro expands to a value of type int, which can be used with fesetround and fegetround functions to indicate toward-zero rounding direction. Rounding x toward-zero gives the largest possible value that is not larger in magnitude than x.
Definition in the <cfenv> header file is:
#define FE_TOWARDZERO /* implementation defined */
All possible rounding direction modes are given below:
Macros | Description |
---|---|
FE_DOWNWARD | Rounding towards negative infinity. |
FE_TONEAREST | Rounding towards nearest representable value. |
FE_TOWARDZERO | Rounding towards zero. |
FE_UPWARD | Rounding towards positive infinity. |
Certain library implementations may define additional floating-point rounding direction macro constants (with their corresponding macros also beginning with FE_).
Example:
The example below shows the usage of FE_TOWARDZERO macro.
#include <iostream> #include <cfenv> #include <cmath> #pragma STDC FENV_ACCESS ON using namespace std; int main (){ //toward-zero rounding direction mode fesetround(FE_TOWARDZERO); cout<<"rint(10.2) = "<<rint(10.2)<<"\n"; cout<<"rint(10.8) = "<<rint(10.8)<<"\n"; cout<<"rint(-5.2) = "<<rint(-5.2)<<"\n"; cout<<"rint(-5.8) = "<<rint(-5.8)<<"\n"; return 0; }
The output of the above code will be:
rint(10.2) = 10 rint(10.8) = 10 rint(-5.2) = -5 rint(-5.8) = -5
❮ C++ <cfenv> Library