cfenv


1. Get Environment Variables

#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;
}

2. Set Control Word

3. Get Exception Status

4. Clear Exception Flags

5. Raise Invalid Operation Exception

6. Handle Invalid Operation Exception

7. Get Floating-Point Precision

8. Get Floating-Point Class

9. Test Floating-Point Predicate

10. Convert Floating-Point Value to Integer

11. Convert Integer to Floating-Point Value

12. Set Default Floating-Point Environment

13. Get Floating-Point Status Word

14. Set Floating-Point Status Word

15. Get Floating-Point Control Word

16. Set Floating-Point Control Word

17. Get Floating-Point Tag Word