2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2010-2019 Red Hat, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
41 The Open Group Base Specifications Issue 6:
42 http://www.opengroup.org/onlinepubs/000095399/basedefs/fenv.h.html
44 C99 Language spec (draft n1256):
47 Intel(R) 64 and IA-32 Architectures Software Developer's Manuals:
48 http://www.intel.com/products/processor/manuals/
50 GNU C library manual pages:
51 http://www.gnu.org/software/libc/manual/html_node/Control-Functions.html
52 http://www.gnu.org/software/libc/manual/html_node/Rounding.html
53 http://www.gnu.org/software/libc/manual/html_node/FP-Exceptions.html
54 http://www.gnu.org/software/libc/manual/html_node/Status-bit-operations.html
56 Linux online man page(s):
57 http://linux.die.net/man/3/fegetexcept
59 The documentation quotes these sources for reference. All definitions and
60 code have been developed solely based on the information from these specs.
64 /* Represents the entire floating-point environment. The floating-point
65 environment refers collectively to any floating-point status flags and
66 control modes supported by the implementation.
67 In this implementation, the struct contains the state information from
68 the fstenv/fnstenv instructions and a copy of the SSE MXCSR, since GCC
69 uses SSE for a lot of floating-point operations. (Cygwin assumes i686
70 or above these days, as does the compiler.) */
72 typedef struct _fenv_t
74 struct _fpu_env_info
{
75 unsigned int _fpu_cw
; /* low 16 bits only. */
76 unsigned int _fpu_sw
; /* low 16 bits only. */
77 unsigned int _fpu_tagw
; /* low 16 bits only. */
78 unsigned int _fpu_ipoff
;
79 unsigned int _fpu_ipsel
;
80 unsigned int _fpu_opoff
;
81 unsigned int _fpu_opsel
; /* low 16 bits only. */
83 unsigned int _sse_mxcsr
;
86 /* Represents the floating-point status flags collectively, including
87 any status the implementation associates with the flags. A floating-point
88 status flag is a system variable whose value is set (but never cleared)
89 when a floating-point exception is raised, which occurs as a side effect
90 of exceptional floating-point arithmetic to provide auxiliary information.
91 A floating-point control mode is a system variable whose value may be
92 set by the user to affect the subsequent behavior of floating-point
95 typedef __uint32_t fexcept_t
;
97 /* The <fenv.h> header shall define the following constants if and only
98 if the implementation supports the floating-point exception by means
99 of the floating-point functions feclearexcept(), fegetexceptflag(),
100 feraiseexcept(), fesetexceptflag(), and fetestexcept(). Each expands to
101 an integer constant expression with values such that bitwise-inclusive
102 ORs of all combinations of the constants result in distinct values. */
104 #define FE_DIVBYZERO (1 << 2)
105 #define FE_INEXACT (1 << 5)
106 #define FE_INVALID (1 << 0)
107 #define FE_OVERFLOW (1 << 3)
108 #define FE_UNDERFLOW (1 << 4)
110 /* The <fenv.h> header shall define the following constant, which is
111 simply the bitwise-inclusive OR of all floating-point exception
112 constants defined above: */
114 /* in agreement w/ Linux the subnormal exception will always be masked */
115 #define FE_ALL_EXCEPT \
116 (FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | FE_DIVBYZERO | FE_INVALID)
118 /* The <fenv.h> header shall define the following constants if and only
119 if the implementation supports getting and setting the represented
120 rounding direction by means of the fegetround() and fesetround()
121 functions. Each expands to an integer constant expression whose values
122 are distinct non-negative vales. */
124 #define FE_DOWNWARD (1)
125 #define FE_TONEAREST (0)
126 #define FE_TOWARDZERO (3)
127 #define FE_UPWARD (2)
129 /* Only Solaris and QNX implement fegetprec/fesetprec. As Solaris, use the
130 values defined by http://www.open-std.org/jtc1/sc22//WG14/www/docs/n752.htm
131 QNX defines different values. */
133 #define FE_FLTPREC (0)
134 #define FE_DBLPREC (2)
135 #define FE_LDBLPREC (3)
138 /* The <fenv.h> header shall define the following constant, which
139 represents the default floating-point environment (that is, the one
140 installed at program startup) and has type pointer to const-qualified
141 fenv_t. It can be used as an argument to the functions within the
142 <fenv.h> header that manage the floating-point environment. */
144 extern const fenv_t
*_fe_dfl_env
;
145 #define FE_DFL_ENV (_fe_dfl_env)
147 /* Additional implementation-defined environments, with macro
148 definitions beginning with FE_ and an uppercase letter,and having
149 type "pointer to const-qualified fenv_t",may also be specified by
150 the implementation. */
153 /* If possible, the GNU C Library defines a macro FE_NOMASK_ENV which
154 represents an environment where every exception raised causes a trap
155 to occur. You can test for this macro using #ifdef. It is only defined
156 if _GNU_SOURCE is defined. */
157 extern const fenv_t
*_fe_nomask_env
;
158 #define FE_NOMASK_ENV (_fe_nomask_env)
160 /* These are GNU extensions defined in glibc. */
161 int feenableexcept (int __excepts
);
162 int fedisableexcept (int __excepts
);
163 int fegetexcept (void);
164 #endif /* __GNU_VISIBLE */
169 int fegetprec (void);
170 int fesetprec (int __prec
);
173 #endif /* __CYGWIN__ */