Merge branch 'master' of ../null
[unleashed.git] / include / fenv.h
blob66a2163b6dfb8dae4578b6a4b3eff0ed06acbd5e
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #ifndef _FENV_H
30 #define _FENV_H
32 #include <sys/feature_tests.h>
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 #ifndef __P
39 #ifdef __STDC__
40 #define __P(p) p
41 #else
42 #define __P(p) ()
43 #endif
44 #endif /* !defined(__P) */
47 * Rounding modes
49 #if defined(__sparc)
51 #define FE_TONEAREST 0
52 #define FE_TOWARDZERO 1
53 #define FE_UPWARD 2
54 #define FE_DOWNWARD 3
56 #elif defined(__i386) || defined(__amd64)
58 #define FE_TONEAREST 0
59 #define FE_DOWNWARD 1
60 #define FE_UPWARD 2
61 #define FE_TOWARDZERO 3
63 #endif
65 extern int fegetround __P((void));
66 extern int fesetround __P((int));
68 #if (defined(__i386) || defined(__amd64)) && \
69 (!defined(_STRICT_STDC) || defined(__EXTENSIONS__))
71 #define FE_FLTPREC 0
72 #define FE_DBLPREC 2
73 #define FE_LDBLPREC 3
75 extern int fegetprec __P((void));
76 extern int fesetprec __P((int));
78 #endif
81 * Exception flags
83 #if defined(__sparc)
85 #define FE_INEXACT 0x01
86 #define FE_DIVBYZERO 0x02
87 #define FE_UNDERFLOW 0x04
88 #define FE_OVERFLOW 0x08
89 #define FE_INVALID 0x10
90 #define FE_ALL_EXCEPT 0x1f
92 #elif defined(__i386) || defined(__amd64)
94 #define FE_INVALID 0x01
95 #define FE_DIVBYZERO 0x04
96 #define FE_OVERFLOW 0x08
97 #define FE_UNDERFLOW 0x10
98 #define FE_INEXACT 0x20
99 #define FE_ALL_EXCEPT 0x3d
101 #endif
103 typedef int fexcept_t;
105 extern int feclearexcept __P((int));
106 extern int feraiseexcept __P((int));
107 extern int fetestexcept __P((int));
108 extern int fegetexceptflag __P((fexcept_t *, int));
109 extern int fesetexceptflag __P((const fexcept_t *, int));
111 #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
114 * Exception handling extensions
116 #define FEX_NOHANDLER -1
117 #define FEX_NONSTOP 0
118 #define FEX_ABORT 1
119 #define FEX_SIGNAL 2
120 #define FEX_CUSTOM 3
122 #define FEX_INEXACT 0x001
123 #define FEX_DIVBYZERO 0x002
124 #define FEX_UNDERFLOW 0x004
125 #define FEX_OVERFLOW 0x008
126 #define FEX_INV_ZDZ 0x010
127 #define FEX_INV_IDI 0x020
128 #define FEX_INV_ISI 0x040
129 #define FEX_INV_ZMI 0x080
130 #define FEX_INV_SQRT 0x100
131 #define FEX_INV_SNAN 0x200
132 #define FEX_INV_INT 0x400
133 #define FEX_INV_CMP 0x800
134 #define FEX_INVALID 0xff0
135 #define FEX_COMMON (FEX_INVALID | FEX_DIVBYZERO | FEX_OVERFLOW)
136 #define FEX_ALL (FEX_COMMON | FEX_UNDERFLOW | FEX_INEXACT)
137 #define FEX_NONE 0
139 #define FEX_NUM_EXC 12
141 /* structure to hold a numeric value in any format used by the FPU */
142 typedef struct {
143 enum fex_nt {
144 fex_nodata = 0,
145 fex_int = 1,
146 fex_llong = 2,
147 fex_float = 3,
148 fex_double = 4,
149 fex_ldouble = 5
150 } type;
151 union {
152 int i;
153 #if !defined(_STRICT_STDC) && !defined(_NO_LONGLONG) || defined(_STDC_C99) || \
154 defined(__C99FEATURES__)
155 long long l;
156 #else
157 struct {
158 int l[2];
159 } l;
160 #endif
161 float f;
162 double d;
163 long double q;
164 } val;
165 } fex_numeric_t;
167 /* structure to supply information about an exception to a custom handler */
168 typedef struct {
169 enum fex_op {
170 fex_add = 0,
171 fex_sub = 1,
172 fex_mul = 2,
173 fex_div = 3,
174 fex_sqrt = 4,
175 fex_cnvt = 5,
176 fex_cmp = 6,
177 fex_other = 7
178 } op; /* operation that caused the exception */
179 int flags; /* flags to be set */
180 fex_numeric_t op1, op2, res; /* operands and result */
181 } fex_info_t;
183 typedef struct fex_handler_data {
184 int __mode;
185 void (*__handler)();
186 } fex_handler_t[FEX_NUM_EXC];
188 extern int fex_get_handling __P((int));
189 extern int fex_set_handling __P((int, int, void (*)()));
191 extern void fex_getexcepthandler __P((fex_handler_t *, int));
192 extern void fex_setexcepthandler __P((const fex_handler_t *, int));
194 #ifdef __STDC__
195 #include <stdio_tag.h>
196 #ifndef _FILEDEFED
197 #define _FILEDEFED
198 typedef __FILE FILE;
199 #endif
200 #endif
201 extern FILE *fex_get_log __P((void));
202 extern int fex_set_log __P((FILE *));
203 extern int fex_get_log_depth __P((void));
204 extern int fex_set_log_depth __P((int));
205 extern void fex_log_entry __P((const char *));
207 #define __fex_handler_t fex_handler_t
209 #else
211 typedef struct {
212 int __mode;
213 void (*__handler)();
214 } __fex_handler_t[12];
216 #endif /* !defined(_STRICT_STDC) || defined(__EXTENSIONS__) */
219 * Environment as a whole
221 typedef struct {
222 __fex_handler_t __handlers;
223 unsigned long __fsr;
224 } fenv_t;
226 #ifdef __STDC__
227 extern const fenv_t __fenv_dfl_env;
228 #else
229 extern fenv_t __fenv_dfl_env;
230 #endif
232 #define FE_DFL_ENV (&__fenv_dfl_env)
234 extern int fegetenv __P((fenv_t *));
235 extern int fesetenv __P((const fenv_t *));
236 extern int feholdexcept __P((fenv_t *));
237 extern int feupdateenv __P((const fenv_t *));
239 #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
240 extern void fex_merge_flags __P((const fenv_t *));
241 #endif
243 #ifdef __cplusplus
245 #endif
247 #endif /* _FENV_H */