cfenv
#include <cfenv>
#include <cstdio>
int main() {
std::printf("Current floating-point environment:\n");
// Get control word
const int cw = _control87(0, 0);
std::printf("Control word: %x\n", cw);
// Get rounding mode
const int rm = (cw >> 10) & 0x3;
switch (rm) {
case 0: std::printf("Rounding mode: Round to nearest\n"); break;
case 1: std::printf("Rounding mode: Round towards zero\n"); break;
case 2: std::printf("Rounding mode: Round towards positive infinity\n"); break;
case 3: std::printf("Rounding mode: Round towards negative infinity\n"); break;
}
// Get exception flags
const int ef = (cw >> 13) & 0xf;
if (ef & _EM_INVALID) std::printf("Invalid operation exception flag is set\n");
if (ef & _EM_DENORMAL) std::printf("Denormalized number exception flag is set\n");
if (ef & _EM_ZERODIVIDE) std::printf("Zero divide exception flag is set\n");
if (ef & _EM_OVERFLOW) std::printf("Overflow exception flag is set\n");
if (ef & _EM_UNDERFLOW) std::printf("Underflow exception flag is set\n");
if (ef & _EM_INEXACT) std::printf("Inexact result exception flag is set\n");
return 0;
}