26 Numerics library [numerics]

26.3 The floating-point environment [cfenv]

26.3.1 Header <cfenv> synopsis [cfenv.syn]

namespace std {
  // types
  typedef object type  fenv_t;
  typedef integer type fexcept_t;

  // functions
  int feclearexcept(int except);
  int fegetexceptflag(fexcept_t* pflag, int except);
  int feraiseexcept(int except);
  int fesetexceptflag(const fexcept_t* pflag, int except);
  int fetestexcept(int except);

  int fegetround(void);
  int fesetround(int mode);

  int fegetenv(fenv_t* penv);
  int feholdexcept(fenv_t* penv);
  int fesetenv(const fenv_t* penv);
  int feupdateenv(const fenv_t* penv);
}

The header also defines the macros:

  FE_ALL_EXCEPT
  FE_DIVBYZERO
  FE_INEXACT
  FE_INVALID
  FE_OVERFLOW
  FE_UNDERFLOW

  FE_DOWNWARD
  FE_TONEAREST
  FE_TOWARDZERO
  FE_UPWARD

  FE_DFL_ENV

The header defines all functions, types, and macros the same as Clause 7.6 of the C standard.

The floating-point environment has thread storage duration ([basic.stc.thread]). The initial state for a thread's floating-point environment is the state of the floating-point environment of the thread that constructs the corresponding std::thread object ([thread.thread.class]) at the time it constructed the object. [ Note: That is, the child thread gets the floating-point state of the parent thread at the time of the child's creation.  — end note ]

A separate floating-point environment shall be maintained for each thread. Each function accesses the environment corresponding to its calling thread.