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