📅 2018-Sep-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cfenv, cpp11, floating point, rounding mode ⬩ 📚 Archive
The standard C library has 4 floating point rounding modes available through cfenv.h
. These are now available in C++11 through the header file cfenv
.
FE_TONEAREST
FE_DOWNWARD
FE_UPWARD
FE_TOWARDZERO
FE_TONEAREST
rounds to the nearest integer. If the floating point value is exactly midway between two integers, then it does round half to even. This rounding mode is also called round-to-nearest-even (RNE). The rest of the rounding modes are self explanatory.round
method does.#define FE_TONEAREST 0x000
#define FE_DOWNWARD 0x400
#define FE_UPWARD 0x800
#define FE_TOWARDZERO 0xC00
FE_TONEAREST
was the default rounding mode when I used methods like rint
and nearbyint
to perform rounding.