1 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
24 .\" 2000-08-14 added GNU additions from Andreas Jaeger
25 .\" 2000-12-05 some changes inspired by acahalan's remarks
27 .TH FENV 3 2021-03-22 "Linux" "Linux Programmer's Manual"
29 feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag,
30 fetestexcept, fegetenv, fegetround, feholdexcept, fesetround,
31 fesetenv, feupdateenv, feenableexcept, fedisableexcept,
32 fegetexcept \- floating-point rounding and exception handling
37 .BI "int feclearexcept(int " excepts );
38 .BI "int fegetexceptflag(fexcept_t *" flagp ", int " excepts );
39 .BI "int feraiseexcept(int " excepts );
40 .BI "int fesetexceptflag(const fexcept_t *" flagp ", int " excepts );
41 .BI "int fetestexcept(int " excepts );
43 .B "int fegetround(void);"
44 .BI "int fesetround(int " rounding_mode );
46 .BI "int fegetenv(fenv_t *" envp );
47 .BI "int feholdexcept(fenv_t *" envp );
48 .BI "int fesetenv(const fenv_t *" envp );
49 .BI "int feupdateenv(const fenv_t *" envp );
54 These eleven functions were defined in C99, and describe the handling
55 of floating-point rounding and exceptions (overflow, zero-divide, etc.).
59 exception occurs when an operation on finite numbers
60 produces infinity as exact answer.
64 exception occurs when a result has to be represented as a
65 floating-point number, but has (much) larger absolute value than the
66 largest (finite) floating-point number that is representable.
70 exception occurs when a result has to be represented as a
71 floating-point number, but has smaller absolute value than the smallest
72 positive normalized floating-point number (and would lose much accuracy
73 when represented as a denormalized number).
77 exception occurs when the rounded result of an operation
78 is not equal to the infinite precision result.
87 exception occurs when there is no well-defined result
88 for an operation, as for 0/0 or infinity \- infinity or sqrt(\-1).
89 .SS Exception handling
90 Exceptions are represented in two ways: as a single bit
91 (exception present/absent), and these bits correspond in some
92 implementation-defined way with bit positions in an integer,
93 and also as an opaque structure that may contain more information
94 about the exception (perhaps the code address where it occurred).
102 is defined when the implementation supports handling
103 of the corresponding exception, and if so then
104 defines the corresponding bit(s), so that one can call
105 exception handling functions, for example, using the integer argument
106 .BR FE_OVERFLOW | FE_UNDERFLOW .
107 Other exceptions may be supported.
110 is the bitwise OR of all bits corresponding to supported exceptions.
114 function clears the supported exceptions represented by the bits
118 .BR fegetexceptflag ()
119 function stores a representation of the state of the exception flags
120 represented by the argument
127 function raises the supported exceptions represented by the bits in
131 .BR fesetexceptflag ()
132 function sets the complete status for the exceptions represented by
136 This value must have been obtained by an earlier call of
137 .BR fegetexceptflag ()
138 with a last argument that contained all bits in
143 function returns a word in which the bits are set that were
146 and for which the corresponding exception is currently set.
148 The rounding mode determines how the result of floating-point operations
149 is treated when the result cannot be exactly represented in the significand.
150 Various rounding modes may be provided:
151 round to nearest (the default),
152 round up (toward positive infinity),
153 round down (toward negative infinity), and
162 is defined when the implementation supports getting and setting
163 the corresponding rounding direction.
167 function returns the macro corresponding to the current
172 function sets the rounding mode as specified by its argument
173 and returns zero when it was successful.
175 C99 and POSIX.1-2008 specify an identifier,
179 which indicates the implementation-defined rounding
180 behavior for floating-point addition.
181 This identifier has one of the following values:
183 The rounding mode is not determinable.
185 Rounding is toward 0.
187 Rounding is toward nearest number.
189 Rounding is toward positive infinity.
191 Rounding is toward negative infinity.
193 Other values represent machine-dependent, nonstandard rounding modes.
197 should reflect the current rounding mode as set by
200 .SS Floating-point environment
201 The entire floating-point environment, including
202 control modes and status flags, can be handled
203 as one opaque object, of type
205 The default environment is denoted by
208 .IR "const fenv_t\ *" ).
209 This is the environment setup at program start and it is defined by
210 ISO C to have round to nearest, all exceptions cleared and a nonstop
211 (continue on exceptions) mode.
215 function saves the current floating-point environment in the object
220 function does the same, then clears all exception flags,
221 and sets a nonstop (continue on exceptions) mode,
223 It returns zero when successful.
227 function restores the floating-point environment from
230 This object must be known to be valid, for example, the result of a call to
236 This call does not raise exceptions.
240 function installs the floating-point environment represented by
243 except that currently raised exceptions are not cleared.
244 After calling this function, the raised exceptions will be a bitwise OR
245 of those previously set with those in
247 As before, the object
249 must be known to be valid.
251 These functions return zero on success and nonzero if an error occurred.
252 .\" Earlier seven of these functions were listed as returning void.
253 .\" This was corrected in Corrigendum 1 (ISO/IEC 9899:1999/Cor.1:2001(E))
254 .\" of the C99 Standard.
256 These functions first appeared in glibc in version 2.1.
258 For an explanation of the terms used in this section, see
267 Interface Attribute Value
269 .BR feclearexcept (),
270 .BR fegetexceptflag (),
271 .BR feraiseexcept (),
272 .BR fesetexceptflag (),
280 .BR feenableexcept (),
281 .BR fedisableexcept (),
292 IEC 60559 (IEC 559:1989), ANSI/IEEE 854, C99, POSIX.1-2001.
295 If possible, the GNU C Library defines a macro
297 which represents an environment where every exception raised causes a
299 You can test for this macro using
301 It is defined only if
304 The C99 standard does not define a way to set individual bits in the
305 floating-point mask, for example, to trap on specific flags.
306 Since version 2.2, glibc supports the functions
307 .BR feenableexcept ()
309 .BR fedisableexcept ()
310 to set individual floating-point traps, and
315 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
316 .B "#include <fenv.h>"
318 .BI "int feenableexcept(int " excepts );
319 .BI "int fedisableexcept(int " excepts );
320 .B "int fegetexcept(void);"
324 .BR feenableexcept ()
326 .BR fedisableexcept ()
327 functions enable (disable) traps for each of the exceptions represented by
329 and return the previous set of enabled exceptions when successful,
333 function returns the set of all currently enabled exceptions.
335 C99 specifies that the value of
337 should reflect changes to the current rounding mode, as set by
340 .\" Aug 08, glibc 2.8
343 always has the value 1.
344 .\" See http://gcc.gnu.org/ml/gcc/2002-02/msg01535.html