1fenv.h(0P)                 POSIX Programmer's Manual                fenv.h(0P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fenv.h — floating-point environment
14

SYNOPSIS

16       #include <fenv.h>
17

DESCRIPTION

19       The functionality described on this reference page is aligned with  the
20       ISO C  standard.  Any  conflict between the requirements described here
21       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
22       defers to the ISO C standard.
23
24       The <fenv.h> header shall define the following data types through type‐
25       def:
26
27       fenv_t    Represents the entire floating-point environment. The  float‐
28                 ing-point  environment  refers  collectively to any floating-
29                 point status flags and control modes supported by the  imple‐
30                 mentation.
31
32       fexcept_t Represents  the  floating-point  status  flags  collectively,
33                 including any status the implementation associates  with  the
34                 flags.  A  floating-point  status  flag  is a system variable
35                 whose value is set (but never cleared) when a  floating-point
36                 exception  is raised, which occurs as a side-effect of excep‐
37                 tional floating-point arithmetic to provide auxiliary  infor‐
38                 mation.  A  floating-point  control mode is a system variable
39                 whose value may be set by the user to affect  the  subsequent
40                 behavior of floating-point arithmetic.
41
42       The  <fenv.h>  header  shall define each of the following macros if and
43       only if the implementation supports  the  floating-point  exception  by
44       means  of  the  floating-point  functions feclearexcept(), fegetexcept‐
45       flag(), feraiseexcept(), fesetexceptflag(),  and  fetestexcept().   The
46       defined macros shall expand to integer constant expressions with values
47       that are bitwise-distinct.
48
49              FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW
50
51       If the implementation supports the IEC 60559 Floating-Point option, all
52       five macros shall be defined.  Additional implementation-defined float‐
53       ing-point exceptions with macros beginning with FE_  and  an  uppercase
54       letter may also be specified by the implementation.
55
56       The  <fenv.h>  header  shall define the macro FE_ALL_EXCEPT as the bit‐
57       wise-inclusive OR of all floating-point exception macros defined by the
58       implementation,  if  any. If no such macros are defined, then the macro
59       FE_ALL_EXCEPT shall be defined as zero.
60
61       The <fenv.h> header shall define each of the following  macros  if  and
62       only if the implementation supports getting and setting the represented
63       rounding direction by means of the fegetround() and fesetround()  func‐
64       tions.  The defined macros shall expand to integer constant expressions
65       whose values are distinct non-negative values.
66
67              FE_DOWNWARD FE_TONEAREST FE_TOWARDZERO FE_UPWARD
68
69       If the implementation supports the IEC 60559 Floating-Point option, all
70       four macros shall be defined.  Additional implementation-defined round‐
71       ing directions with macros beginning with FE_ and an  uppercase  letter
72       may also be specified by the implementation.
73
74       The  <fenv.h> header shall define the following macro, which represents
75       the default floating-point environment (that is, the one  installed  at
76       program  startup)  and  has type pointer to const-qualified fenv_t.  It
77       can be used as an argument to the functions within the <fenv.h>  header
78       that manage the floating-point environment.
79
80              FE_DFL_ENV
81
82       The following shall be declared as functions and may also be defined as
83       macros. Function prototypes shall be provided.
84
85           int  feclearexcept(int);
86           int  fegetenv(fenv_t *);
87           int  fegetexceptflag(fexcept_t *, int);
88           int  fegetround(void);
89           int  feholdexcept(fenv_t *);
90           int  feraiseexcept(int);
91           int  fesetenv(const fenv_t *);
92           int  fesetexceptflag(const fexcept_t *, int);
93           int  fesetround(int);
94           int  fetestexcept(int);
95           int  feupdateenv(const fenv_t *);
96
97       The FENV_ACCESS pragma provides a means to  inform  the  implementation
98       when an application might access the floating-point environment to test
99       floating-point status flags or  run  under  non-default  floating-point
100       control  modes. The pragma shall occur either outside external declara‐
101       tions or preceding all explicit declarations and  statements  inside  a
102       compound  statement.  When  outside  external  declarations, the pragma
103       takes effect from its occurrence until another  FENV_ACCESS  pragma  is
104       encountered,  or  until  the end of the translation unit. When inside a
105       compound statement, the pragma takes effect from its  occurrence  until
106       another  FENV_ACCESS  pragma  is encountered (including within a nested
107       compound statement), or until the end of the compound statement; at the
108       end of a compound statement the state for the pragma is restored to its
109       condition just before the compound statement. If this pragma is used in
110       any other context, the behavior is undefined. If part of an application
111       tests floating-point status flags, sets floating-point  control  modes,
112       or  runs  under  non-default mode settings, but was translated with the
113       state for the FENV_ACCESS pragma off, the behavior  is  undefined.  The
114       default  state  (on  or  off) for the pragma is implementation-defined.
115       (When execution passes from a part of the application  translated  with
116       FENV_ACCESS  off to a part translated with FENV_ACCESS on, the state of
117       the floating-point status flags is unspecified and  the  floating-point
118       control modes have their default settings.)
119
120       The following sections are informative.
121

APPLICATION USAGE

123       This  header is designed to support the floating-point exception status
124       flags   and   directed-rounding   control   modes   required   by   the
125       IEC 60559:1989  standard, and other similar floating-point state infor‐
126       mation. Also it is designed to facilitate code  portability  among  all
127       systems.
128
129       Certain  application programming conventions support the intended model
130       of use for the floating-point environment:
131
132        *  A function call does not alter its caller's floating-point  control
133           modes,  clear  its caller's floating-point status flags, nor depend
134           on the state of its caller's floating-point status flags unless the
135           function is so documented.
136
137        *  A  function  call is assumed to require default floating-point con‐
138           trol modes, unless its documentation promises otherwise.
139
140        *  A function call is assumed to have the potential for raising float‐
141           ing-point exceptions, unless its documentation promises otherwise.
142
143       With these conventions, an application can safely assume default float‐
144       ing-point control modes (or be unaware of them).  The  responsibilities
145       associated  with  accessing  the floating-point environment fall on the
146       application that does so explicitly.
147
148       Even though the rounding direction macros may expand to constants  cor‐
149       responding to the values of FLT_ROUNDS, they are not required to do so.
150
151       For example:
152
153           #include <fenv.h>
154           void f(double x)
155           {
156               #pragma STDC FENV_ACCESS ON
157               void g(double);
158               void h(double);
159               /* ... */
160               g(x + 1);
161               h(x + 1);
162               /* ... */
163           }
164
165       If  the  function g() might depend on status flags set as a side-effect
166       of the first x+1, or if the second x+1 might depend  on  control  modes
167       set  as a side-effect of the call to function g(), then the application
168       shall contain an appropriately placed invocation as follows:
169
170           #pragma STDC FENV_ACCESS ON
171

RATIONALE

173   The fexcept_t Type
174       fexcept_t does not have to be an  integer  type.  Its  values  must  be
175       obtained by a call to fegetexceptflag(), and cannot be created by logi‐
176       cal operations from the exception macros.  An implementation might sim‐
177       ply implement fexcept_t as an int and use the representations reflected
178       by the exception macros, but is not required to; other  representations
179       might  contain extra information about the exceptions.  fexcept_t might
180       be a struct with a member for  each  exception  (that  might  hold  the
181       address  of  the  first  or last floating-point instruction that caused
182       that exception).  The ISO/IEC 9899:1999 standard makes no claims  about
183       the internals of an fexcept_t, and so the user cannot inspect it.
184
185   Exception and Rounding Macros
186       Macros  corresponding  to unsupported modes and rounding directions are
187       not defined by the implementation and must not be defined by the appli‐
188       cation. An application might use #ifdef to test for this.
189

FUTURE DIRECTIONS

191       None.
192

SEE ALSO

194       The   System   Interfaces   volume  of  POSIX.1‐2008,  feclearexcept(),
195       fegetenv(), fegetexceptflag(), fegetround(), feholdexcept(), feraiseex‐
196       cept(), fetestexcept(), feupdateenv()
197
199       Portions  of  this text are reprinted and reproduced in electronic form
200       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
201       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
202       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
203       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
204       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
205       event of any discrepancy between this version and the original IEEE and
206       The Open Group Standard, the original IEEE and The Open Group  Standard
207       is  the  referee document. The original Standard can be obtained online
208       at http://www.unix.org/online.html .
209
210       Any typographical or formatting errors that appear  in  this  page  are
211       most likely to have been introduced during the conversion of the source
212       files to man page format. To report such errors,  see  https://www.ker
213       nel.org/doc/man-pages/reporting_bugs.html .
214
215
216
217IEEE/The Open Group                  2013                           fenv.h(0P)
Impressum