xref: /reactos/sdk/include/crt/fenv.h (revision 34593d93)
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the w64 mingw-runtime package.
4  * No warranty is given; refer to the file DISCLAIMER within this package.
5  */
6 #ifndef _FENV_H_
7 #define _FENV_H_
8 
9 /* FPU status word exception flags */
10 #define FE_INVALID	0x01
11 #define FE_DENORMAL	0x02
12 #define FE_DIVBYZERO	0x04
13 #define FE_OVERFLOW	0x08
14 #define FE_UNDERFLOW	0x10
15 #define FE_INEXACT	0x20
16 #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO \
17 		       | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
18 
19 /* FPU control word rounding flags */
20 #define FE_TONEAREST	0x0000
21 #define FE_DOWNWARD	0x0400
22 #define FE_UPWARD	0x0800
23 #define FE_TOWARDZERO	0x0c00
24 
25 /* The MXCSR exception flags are the same as the
26    FE flags. */
27 #define __MXCSR_EXCEPT_FLAG_SHIFT 0
28 
29 /* How much to shift FE status word exception flags
30    to get MXCSR rounding flags,  */
31 #define __MXCSR_ROUND_FLAG_SHIFT 3
32 
33 #ifndef RC_INVOKED
34 /*
35   For now, support only for the basic abstraction of flags that are
36   either set or clear. fexcept_t could be  structure that holds more
37   info about the fp environment.
38 */
39 typedef unsigned short fexcept_t;
40 
41 /* This 32-byte struct represents the entire floating point
42    environment as stored by fnstenv or fstenv, augmented by
43    the  contents of the MXCSR register, as stored by stmxcsr
44    (if CPU supports it). */
45 typedef struct
46 {
47   unsigned short __control_word;
48   unsigned short __unused0;
49   unsigned short __status_word;
50   unsigned short __unused1;
51   unsigned short __tag_word;
52   unsigned short __unused2;
53   unsigned int	 __ip_offset;    /* instruction pointer offset */
54   unsigned short __ip_selector;
55   unsigned short __opcode;
56   unsigned int	 __data_offset;
57   unsigned short __data_selector;
58   unsigned short __unused3;
59   unsigned int   __mxcsr; /* contents of the MXCSR register  */
60 } fenv_t;
61 
62 
63 /*The C99 standard (7.6.9) allows us to define implementation-specific macros for
64   different fp environments */
65 
66 /* The default Intel x87 floating point environment (64-bit mantissa) */
67 #define FE_PC64_ENV ((const fenv_t *)-1)
68 
69 /* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */
70 #define FE_PC53_ENV ((const fenv_t *)-2)
71 
72 /* The FE_DFL_ENV macro is required by standard.
73   fesetenv will use the environment set at app startup.*/
74 #define FE_DFL_ENV ((const fenv_t *) 0)
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
80 /*TODO: Some of these could be inlined */
81 /* 7.6.2 Exception */
82 
83 extern int __cdecl feclearexcept (int);
84 extern int __cdecl fegetexceptflag (fexcept_t * flagp, int excepts);
85 extern int __cdecl feraiseexcept (int excepts );
86 extern int __cdecl fesetexceptflag (const fexcept_t *, int);
87 extern int __cdecl fetestexcept (int excepts);
88 
89 /* 7.6.3 Rounding */
90 
91 extern int __cdecl fegetround (void);
92 extern int __cdecl fesetround (int mode);
93 
94 /* 7.6.4 Environment */
95 
96 extern int __cdecl fegetenv(fenv_t * envp);
97 extern int __cdecl fesetenv(const fenv_t * );
98 extern int __cdecl feupdateenv(const fenv_t *);
99 extern int __cdecl feholdexcept(fenv_t *);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 #endif	/* Not RC_INVOKED */
105 
106 #endif /* ndef _FENV_H */
107