Penguin
Blame: fetestexcept(3)
EditPageHistoryDiffInfoLikePages
Annotated edit history of fetestexcept(3) version 2, including all changes. View license author blame.
Rev Author # Line
1 perry 1 FENV
2 !!!FENV
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 GNU DETAILS
7 CONFORMING TO
8 ----
9 !!NAME
10
11
12 feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag, fetestexcept, fegetenv, fegetround, feholdexcept, fesetround, fesetenv, feupdateenv - C99 floating point rounding and exception handling
13 !!SYNOPSIS
14
15
16 __#include
17 __ ''excepts''__);
18 void fegetexceptflag(fexcept_t *__''flagp''__, int__ ''excepts''__);
19 void feraiseexcept(int__ ''excepts''__);
20 void fesetexceptflag(const fexcept_t *__''flagp''__, int__ ''excepts''__);
21 int fetestexcept(int__ ''excepts''__);
22 int fegetround(void);
23 int fesetround(int__ ''rounding_mode''__);
24 void fegetenv(fenv_t *__''envp''__);
25 int feholdexcept(fenv_t *__''envp''__);
26 void fesetenv(const fenv_t *__''envp''__);
27 void feupdateenv(const fenv_t *__''envp''__);
28 __
29 !!DESCRIPTION
30
31
32 These eleven functions were defined in C99, and describe the
33 handling of floating point rounding and exceptions
34 (overflow, zero-divide etc.).
35
36
37 __Exceptions__
38
39
2 perry 40 The !DivideByZero exception occurs when an operation on
1 perry 41 finite numbers produces infinity as exact
42 answer.
43
44
45 The Overflow exception occurs when a result has to be
46 represented as a floating point number, but has (much)
47 larger absolute value than the largest (finite) floating
48 point number that is representable.
49
50
51 The Underflow exception occurs when a result has to be
52 represented as a floating point number, but has smaller
53 absolute value than the smallest positive normalized
54 floating point number (and would lose much accuracy when
55 represented as a denormalized number).
56
57
58 The Inexact exception occurs when the rounded result of an
59 operation is not equal to the infinite precision result. It
60 may occur whenever Overflow or Underflow
61 occurs.
62
63
64 The Invalid exception occurs when there is no well-defined
65 result for an operation, as for 0/0 or infinity - infinity
66 or sqrt(-1).
67
68
69 __Exception handling__
70
71
72 Exceptions are represented in two ways: as a single bit
73 (exception present/absent), and these bits correspond in
74 some implementation-defined way with bit positions in an
75 integer, and also as an opaque structure that may contain
76 more information about the exception (perhaps the code
77 address where it occurred).
78
79
80 Each of the macros __FE_DIVBYZERO__, __FE_INEXACT__,
81 __FE_INVALID__, __FE_OVERFLOW__, __FE_UNDERFLOW__
82 is defined when the implementation supports handling of the
83 corresponding exception, and if so then defines the
84 corresponding bit(s), so that one can call exception
85 handling functions e.g. using the integer argument
86 __FE_OVERFLOW__|__FE_UNDERFLOW__. Other exceptions may
87 be supported. The macro __FE_ALL_EXCEPT__ is the bitwise
88 OR of all bits corresponding to supported
89 exceptions.
90
91
92 The __feclearexcept__ function clears the supported
93 exceptions represented by the bits in its
94 argument.
95
96
97 The __fegetexceptflag__ function stores a representation
98 of the state of the exception flags represented by the
99 argument ''excepts'' in the opaque object
100 *''flagp''.
101
102
103 The __feraiseexcept__ function raises the supported
104 exceptions represented by the bits in
105 ''excepts''.
106
107
108 The __fesetexceptflag__ function sets the complete status
109 for the exceptions represented by ''excepts'' to the
110 value *''flagp''. This value must have been obtained by
111 an earlier call of __fegetexceptflag__ with a last
112 argument that contained all bits in
113 ''excepts''.
114
115
116 The __fetestexcept__ function returns a word in which the
117 bits are set that were set in the argument ''excepts''
118 and for which the corresponding exception is currently
119 set.
120
121
122 __Rounding__
123
124
125 Each of the macros __FE_DOWNWARD__, __FE_TONEAREST__,
126 __FE_TOWARDZERO__, __FE_UPWARD__ is defined when the
127 implementation supports getting and setting the
128 corresponding rounding direction.
129
130
131 The __fegetround__ function returns the macro
132 corresponding to the current rounding mode.
133
134
135 The __fesetround__ function sets the rounding mode as
136 specified by its argument and returns zero when it was
137 successful.
138
139
140 __Floating point environment__
141
142
143 The entire floating point environment, including control
144 modes and status flags, can be handled as one opaque object,
145 of type ''fenv_t''. The default environment is denoted by
146 __FE_DFL_ENV__ (of type ''const fenv_t *''). This is
147 the environment setup at program start and it is defined by
148 ISO C to have round to nearest, all exceptions cleared and a
149 non-stop (continue on exceptions) mode.
150
151
152 The __fegetenv__ function saves the current floating
153 point environment in the object *''envp''.
154
155
156 The __feholdexcept__ function does the same, then clears
157 all exception flags, and sets a non-stop (continue on
158 exceptions) mode, if available. It returns zero when
159 successful.
160
161
162 The __fesetenv__ function restores the floating point
163 environment from the object *''envp''. This object must
164 be known to be valid, e.g., the result of a call to
165 __fegetenv__ or __feholdexcept__ or equal to
166 __FE_DFL_ENV__. This call does not raise
167 exceptions.
168
169
170 The __feupdateenv__ function installs the floating-point
171 environment represented by the object *''envp'', except
172 that currently raised exceptions are not cleared. After
173 calling this function, the raised exceptions will be a
174 bitwise OR of those previously set with those in
175 *''envp''. As before, the object *''envp'' must be
176 known to be valid.
177 !!GNU DETAILS
178
179
180 If possible, the GNU C Library defines a macro
181 __FE_NOMASK_ENV__ which represents an environment where
182 every exception raised causes a trap to occur. You can test
183 for this macro using __#ifdef__. It is only defined if
184 ___GNU_SOURCE__ is defined. The C99 standard does not
185 define a way to set individual bits in the floating point
186 mask, e.g. to trap on specific flags. glibc 2.2 will support
187 the functions ''feenableexcept'' and
188 ''fedisableexcept'' to set individual floating point
189 traps, and ''fegetexcept'' to query the
190 state.
191
192
193 __int feenableexcept (int__ ''excepts''__);
194 int fedisableexcept (int__ ''excepts''__);
195 int fegetexcept (void);
196 __The __feenableexcept__ and __fedisableexcept__ functions enable (disable) traps for each of the exceptions represented by ''excepts'' and return the previous set of enabled exceptions when successful, and -1 otherwise. The __fegetexcept__ function returns the set of all currently enabled exceptions.
197 !!CONFORMING TO
198
199
200 IEC 60559 (IEC 559:1989), ANSI/IEEE 854, ISO C99 (ISO/IEC
201 9899:1999).
202 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.