[cfenv]

# 29 Numerics library [[numerics]](./#numerics)

## 29.3 The floating-point environment [cfenv]

### [29.3.1](#syn) Header <cfenv> synopsis [[cfenv.syn]](cfenv.syn)

[ð](#header:%3ccfenv%3e)

#define FE_ALL_EXCEPT *see below*#define FE_DIVBYZERO *see below* // optional#define FE_INEXACT *see below* // optional#define FE_INVALID *see below* // optional#define FE_OVERFLOW *see below* // optional#define FE_UNDERFLOW *see below* // optional#define FE_DOWNWARD *see below* // optional#define FE_TONEAREST *see below* // optional#define FE_TOWARDZERO *see below* // optional#define FE_UPWARD *see below* // optional#define FE_DFL_ENV *see below*namespace std {// typesusing fenv_t = *object type*; using fexcept_t = *object type*; // functionsint 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(); 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);}

[1](#syn-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L138)

The contents and meaning of the header [<cfenv>](#header:%3ccfenv%3e "29.3.1 Header <cfenv> synopsis [cfenv.syn]") are a subset of the C standard library header [<fenv.h>](support.c.headers.general#header:%3cfenv.h%3e "17.15.1 General [support.c.headers.general]") and
only the declarations shown in the synopsis above are present[.](#syn-1.sentence-1)

[*Note [1](#syn-note-1)*:

This document does not require an implementation to support theFENV_ACCESS pragma;
it is implementation-defined ([[cpp.pragma]](cpp.pragma "15.10 Pragma directive"))
whether the pragma is supported[.](#syn-1.sentence-2)

As a consequence,
it is implementation-defined
whether these functions can be used to test floating-point status flags,
set floating-point control modes, or run under non-default mode settings[.](#syn-1.sentence-3)

If the pragma is used to enable control over the floating-point environment,
this document does not specify the effect on
floating-point evaluation in constant expressions[.](#syn-1.sentence-4)

â *end note*]

See also: ISO/IEC 9899:2024, 7.6

### [29.3.2](#thread) Threads [[cfenv.thread]](cfenv.thread)

[1](#thread-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L159)

The floating-point environment has [thread storage duration](basic.stc.thread#def:storage_duration,thread "6.8.6.3 Thread storage duration [basic.stc.thread]")[.](#thread-1.sentence-1)

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 thread object ([[thread.thread.class]](thread.thread.class "32.4.3 Class thread"))
or jthread object ([[thread.jthread.class]](thread.jthread.class "32.4.4 Class jthread"))
at the time it
constructed the object[.](#thread-1.sentence-2)

[*Note [1](#thread-note-1)*:

That is, the child thread gets the floating-point
state of the parent thread at the time of the child's creation[.](#thread-1.sentence-3)

â *end note*]

[2](#thread-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L172)

A separate floating-point environment is maintained for each thread[.](#thread-2.sentence-1)

Each function
accesses the environment corresponding to its calling thread[.](#thread-2.sentence-2)
