Guest User

Untitled

a guest
Mar 27th, 2018
262
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * float.h
  3. *
  4. * Constants related to floating point arithmetic. Also included here are
  5. * some non-ANSI mechanisms for accessing the floating point controller.
  6. *
  7. * $Id: float.h,v af569eb5aad7 2017/02/27 17:46:27 keithmarshall $
  8. *
  9. * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  10. * Copyright (C) 1997, 1999-2005, 2007, 2010, 2011, 2017, MinGW.org Project
  11. *
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice, this permission notice, and the following
  21. * disclaimer shall be included in all copies or substantial portions of
  22. * the Software.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  27. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  29. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
  30. * DEALINGS IN THE SOFTWARE.
  31. *
  32. */
  33. #ifndef _MINGW_FLOAT_H
  34. #pragma GCC system_header
  35. #define _MINGW_FLOAT_H
  36. /*
  37. * NOTE:
  38. *
  39. * GCC provides float.h, but it doesn't include the non-standard stuff for
  40. * accessing the fp controller. We parse the GCC-supplied header, for its
  41. * standard content, and then define the MS-specific extensions here.
  42. *
  43. * In a MinGW standard Win32 hosted environment, this should be the float.h
  44. * found by a system include path search, but this can't be guaranteed; for
  45. * a cross-compiler setup, the GCC-supplied header, which is guarded by the
  46. * _FLOAT_H___ macro, may be found first, thus, except when compiling any
  47. * __LIBIMPL__ stub...
  48. *
  49. */
  50. #if !defined(_FLOAT_H___) && !defined(__FLOAT_H)
  51. /* ...when we didn't find the GCC-supplied header first, we want to pull
  52. * it in now; include_next should achieve this, (and we must rely on the
  53. * GCC header maintainers to extend us the same courtesy, to get this one
  54. * pulled in, when the GCC-supplied header is found first).
  55. */
  56. # define _MINGW_FLOAT_H_ 1 /* GCC's <float.h> needs to see this */
  57. # include_next <float.h> /* !__CRT_ALIAS __LIBIMPL__( FUNCTION = fpreset ) */
  58. #endif
  59.  
  60. /* All MinGW headers are required to include <_mingw.h>
  61. */
  62. #include <_mingw.h>
  63.  
  64. /* Functions and definitions for controlling the FPU.
  65. */
  66. #ifndef __STRICT_ANSI__
  67.  
  68. /* TODO: These constants are only valid for x86 machines */
  69.  
  70. /* Control word masks for unMask
  71. */
  72. #define _MCW_EM 0x0008001F /* Error masks */
  73. #define _MCW_IC 0x00040000 /* Infinity */
  74. #define _MCW_RC 0x00000300 /* Rounding */
  75. #define _MCW_PC 0x00030000 /* Precision */
  76.  
  77. /* Control word values for unNew (use with related unMask above)
  78. */
  79. #define _EM_INVALID 0x00000010
  80. #define _EM_DENORMAL 0x00080000
  81. #define _EM_ZERODIVIDE 0x00000008
  82. #define _EM_OVERFLOW 0x00000004
  83. #define _EM_UNDERFLOW 0x00000002
  84. #define _EM_INEXACT 0x00000001
  85. #define _IC_AFFINE 0x00040000
  86. #define _IC_PROJECTIVE 0x00000000
  87. #define _RC_CHOP 0x00000300
  88. #define _RC_UP 0x00000200
  89. #define _RC_DOWN 0x00000100
  90. #define _RC_NEAR 0x00000000
  91. #define _PC_24 0x00020000
  92. #define _PC_53 0x00010000
  93. #define _PC_64 0x00000000
  94.  
  95. #ifndef __MINGW_FPCLASS_DEFINED
  96. #define __MINGW_FPCLASS_DEFINED 1
  97. /* These are also defined in MinGW <math.h>; these duplicates are
  98. * needed here, to work around GCC build issues. FIXME: we should
  99. * be able to factor this, at least to avoid any potential for the
  100. * introduction of inconsistent definitions.
  101. *
  102. *
  103. * Return values for fpclass.
  104. */
  105. #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
  106. #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
  107. #define _FPCLASS_NINF 0x0004 /* Negative Infinity */
  108. #define _FPCLASS_NN 0x0008 /* Negative Normal */
  109. #define _FPCLASS_ND 0x0010 /* Negative Denormal */
  110. #define _FPCLASS_NZ 0x0020 /* Negative Zero */
  111. #define _FPCLASS_PZ 0x0040 /* Positive Zero */
  112. #define _FPCLASS_PD 0x0080 /* Positive Denormal */
  113. #define _FPCLASS_PN 0x0100 /* Positive Normal */
  114. #define _FPCLASS_PINF 0x0200 /* Positive Infinity */
  115.  
  116. #endif /* __MINGW_FPCLASS_DEFINED */
  117.  
  118. /* Invalid subconditions (_SW_INVALID also set)
  119. */
  120. #define _SW_UNEMULATED 0x0040 /* unemulated instruction */
  121. #define _SW_SQRTNEG 0x0080 /* square root of a neg number */
  122. #define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */
  123. #define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */
  124.  
  125. /* Floating point error signals and return codes
  126. */
  127. #define _FPE_INVALID 0x81
  128. #define _FPE_DENORMAL 0x82
  129. #define _FPE_ZERODIVIDE 0x83
  130. #define _FPE_OVERFLOW 0x84
  131. #define _FPE_UNDERFLOW 0x85
  132. #define _FPE_INEXACT 0x86
  133. #define _FPE_UNEMULATED 0x87
  134. #define _FPE_SQRTNEG 0x88
  135. #define _FPE_STACKOVERFLOW 0x8A
  136. #define _FPE_STACKUNDERFLOW 0x8B
  137. #define _FPE_EXPLICITGEN 0x8C /* raise SIGFPE */
  138.  
  139. #ifndef RC_INVOKED
  140.  
  141. _BEGIN_C_DECLS
  142.  
  143. /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
  144. * i.e. change the bits in unMask to have the values they have in unNew,
  145. * leaving other bits unchanged.
  146. */
  147. _CRTIMP __cdecl __MINGW_NOTHROW unsigned int _controlfp (unsigned int unNew, unsigned int unMask);
  148. _CRTIMP __cdecl __MINGW_NOTHROW unsigned int _control87 (unsigned int unNew, unsigned int unMask);
  149.  
  150. #define _clear87 _clearfp
  151. #define _status87 _statusfp
  152.  
  153. _CRTIMP __cdecl __MINGW_NOTHROW unsigned int _clearfp (void); /* Clear the FPU status word */
  154. _CRTIMP __cdecl __MINGW_NOTHROW unsigned int _statusfp (void); /* Report the FPU status word */
  155.  
  156.  
  157. /* MSVCRT.DLL provides _fpreset() to initialize the FPU; it initializes
  158. * the control register to 0x27F, (thus selecting 53-bit precision), the
  159. * status register to zero and the tag word to 0FFFFh. This differs from
  160. * Intel's default configuration, (as established by the asm instructions
  161. * "finit" and "fninit"), which set the control word to 0x37F, (yielding
  162. * 64-bit precison rather than 53-bit).
  163. *
  164. * Nominally, MinGW prefers to configure the FPU for 64-bit precision, as
  165. * that is a better fit for support of GCC's 10-byte long doubles. This
  166. * was formerly achieved by provision of an alternative implementation of
  167. * _fpreset(), intended to be statically linked into MinGW applications,
  168. * (with variants enabling 64-bit precision by default, or alternatively,
  169. * when the application is explicitly linked with CRT_fp8.o, providing
  170. * 53-bit precision instead). Unfortunately, this linking strategy may
  171. * lead to non-deterministic ambiguity over which _fpreset() variant is
  172. * called, in the event of the call originating in any user implemented,
  173. * or third party DLL. Consequently, support for this strategy has been
  174. * withdrawn. _fpreset() now ALWAYS refers to the MSVCRT.DLL function,
  175. * (and thus ALWAYS selects 53-bit precision); MinGW applications should
  176. * now use the ISO-C99 standard fesetenv() function to configure the FPU,
  177. * (as the start-up code now does, to enable 64-bit precision by default,
  178. * but continuing to support linking with CRT_fp8.o, to initialize the
  179. * configuration to 53-bit precision).
  180. */
  181. _CRTIMP __cdecl __MINGW_NOTHROW void _fpreset (void);
  182.  
  183. /* Former MinGW releases also provided fpreset(), implemented as an alias
  184. * for _fpreset(), (in whichever guise it was deployed); deprecate this,
  185. * but retain the association for backward compatibility, (noting that it
  186. * will now redirect the call to fesetenv(), as recommended above, with
  187. * the configuration selection set to FE_DFL_ENV).
  188. */
  189. __cdecl __MINGW_NOTHROW void fpreset (void) __MINGW_ATTRIB_DEPRECATED;
  190.  
  191. #ifndef __NO_INLINE__
  192. /* Provide the implementation of fpreset() as an inline stub; for this,
  193. * we need to expose a minimal opaque subset of <fenv.h>, and we assume
  194. * that FE_DFL_ENV is equivalent to (const fenv_t *)(0), (as it is, in
  195. * the MinGW implementation of <fenv.h>).
  196. */
  197. typedef struct __fenv_t fenv_t;
  198. __cdecl __MINGW_NOTHROW int fesetenv (const fenv_t *);
  199.  
  200. __CRT_ALIAS __LIBIMPL__( FUNCTION = fpreset )
  201. void fpreset (void){ fesetenv ((const fenv_t *)(0)); }
  202. #endif
  203.  
  204. /* Global 'variable' for the current floating point error code.
  205. */
  206. #define _fpecode (*(__fpecode()))
  207. _CRTIMP __cdecl __MINGW_NOTHROW int *__fpecode (void);
  208.  
  209. /* IEEE recommended functions. Microsoft puts them in <float.h>,
  210. * but they really belong in math.h.
  211. */
  212. _CRTIMP __cdecl __MINGW_NOTHROW double _chgsign (double);
  213. _CRTIMP __cdecl __MINGW_NOTHROW double _copysign (double, double);
  214. _CRTIMP __cdecl __MINGW_NOTHROW double _logb (double);
  215. _CRTIMP __cdecl __MINGW_NOTHROW double _nextafter (double, double);
  216. _CRTIMP __cdecl __MINGW_NOTHROW double _scalb (double, long);
  217.  
  218. _CRTIMP __cdecl __MINGW_NOTHROW int _finite (double);
  219. _CRTIMP __cdecl __MINGW_NOTHROW int _fpclass (double);
  220. _CRTIMP __cdecl __MINGW_NOTHROW int _isnan (double);
  221.  
  222. _END_C_DECLS
  223.  
  224. #endif /* ! RC_INVOKED */
  225. #endif /* !__STRICT_ANSI__ */
  226.  
  227. #endif /* _MINGW_FLOAT_H: $RCSfile: float.h,v $: end of file */
RAW Paste Data