xref: /openbsd-src/sys/arch/alpha/include/fenv.h (revision c968322491f5e86f378eca5c4a4d58810e068baa)
1 /*	$OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $	*/
2 
3 /*
4  * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef	_ALPHA_FENV_H_
20 #define	_ALPHA_FENV_H_
21 
22 /*
23  * Each symbol representing a floating point exception expands to an integer
24  * constant expression with values, such that bitwise-inclusive ORs of _all
25  * combinations_ of the constants result in distinct values.
26  *
27  * We use such values that allow direct bitwise operations on FPU registers.
28  */
29 #define	FE_INVALID		0x01
30 #define	FE_DIVBYZERO		0x02
31 #define	FE_OVERFLOW		0x04
32 #define	FE_UNDERFLOW		0x08
33 #define	FE_INEXACT		0x10
34 
35 /*
36  * The following symbol is simply the bitwise-inclusive OR of all floating-point
37  * exception constants defined above.
38  */
39 #define	FE_ALL_EXCEPT		(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | \
40 				 FE_UNDERFLOW)
41 
42 /*
43  * Each symbol representing the rounding direction, expands to an integer
44  * constant expression whose value is distinct non-negative value.
45  *
46  * We use such values that allow direct bitwise operations on FPU registers.
47  */
48 #define	FE_TOWARDZERO		0x0
49 #define	FE_DOWNWARD		0x1
50 #define	FE_TONEAREST		0x2
51 #define	FE_UPWARD		0x3
52 
53 /*
54  * The following symbol is simply the bitwise-inclusive OR of all floating-point
55  * rounding direction constants defined above.
56  */
57 #define	_ROUND_MASK		(FE_TOWARDZERO | FE_DOWNWARD | FE_TONEAREST | \
58 				 FE_UPWARD)
59 #define	_ROUND_SHIFT		58
60 
61 /*
62  * fenv_t represents the entire floating-point environment.
63  */
64 typedef	struct {
65 	unsigned int __sticky;
66 	unsigned int __mask;
67 	unsigned int __round;
68 } fenv_t;
69 
70 /*
71  * The following constant represents the default floating-point environment
72  * (that is, the one installed at program startup) and has type pointer to
73  * const-qualified fenv_t.
74  *
75  * It can be used as an argument to the functions within the <fenv.h> header
76  * that manage the floating-point environment, namely fesetenv() and
77  * feupdateenv().
78  */
79 __BEGIN_DECLS
80 extern	fenv_t			__fe_dfl_env;
81 __END_DECLS
82 #define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
83 
84 /*
85  * fexcept_t represents the floating-point status flags collectively, including
86  * any status the implementation associates with the flags.
87  *
88  * A floating-point status flag is a system variable whose value is set (but
89  * never cleared) when a floating-point exception is raised, which occurs as a
90  * side effect of exceptional floating-point arithmetic to provide auxiliary
91  * information.
92  *
93  * A floating-point control mode is a system variable whose value may be set by
94  * the user to affect the subsequent behavior of floating-point arithmetic.
95  */
96 typedef	unsigned int		fexcept_t;
97 
98 #endif	/* !_ALPHA_FENV_H_ */
99