float.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * float.h
  3. * This file has no copyright assigned and is placed in the Public Domain.
  4. * This file is part of the mingw-runtime package.
  5. * No warranty is given; refer to the file DISCLAIMER.PD within the package.
  6. *
  7. * Constants related to floating point arithmetic.
  8. *
  9. * Also included here are some non-ANSI bits for accessing the floating
  10. * point controller.
  11. *
  12. */
  13. #if defined(__LIBMSVCRT__)
  14. /* When building mingw-w64, this should be blank. */
  15. #define _SECIMP
  16. #else
  17. #ifndef _SECIMP
  18. #define _SECIMP __declspec(dllimport)
  19. #endif /* _SECIMP */
  20. #endif /* defined(__LIBMSVCRT__) */
  21. #if (defined (__GNUC__) && defined (__GNUC_MINOR__)) \
  22. || (defined(__clang__) && defined(__clang_major__))
  23. #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) \
  24. || (__clang_major__ >=3)
  25. #if !defined(_FLOAT_H___) && !defined(__FLOAT_H) && !defined(__CLANG_FLOAT_H)
  26. #include_next <float.h>
  27. #endif
  28. #elif !defined (_FLOAT_H___)
  29. #if (__GNUC__ < 4)
  30. #error Corrupt install of gcc-s internal headers, or search order was changed.
  31. #else
  32. /* #include_next <float_ginclude.h> */
  33. /* Number of decimal digits, q, such that any floating-point number with q
  34. decimal digits can be rounded into a floating-point number with p radix b
  35. digits and back again without change to the q decimal digits,
  36. p * log10(b) if b is a power of 10
  37. floor((p - 1) * log10(b)) otherwise
  38. */
  39. #undef FLT_DIG
  40. #undef DBL_DIG
  41. #undef LDBL_DIG
  42. #define FLT_DIG __FLT_DIG__
  43. #define DBL_DIG __DBL_DIG__
  44. #define LDBL_DIG __LDBL_DIG__
  45. /* Maximum representable finite floating-point number,
  46. (1 - b**-p) * b**emax
  47. */
  48. #undef FLT_MAX
  49. #undef DBL_MAX
  50. #undef LDBL_MAX
  51. #define FLT_MAX __FLT_MAX__
  52. #define DBL_MAX __DBL_MAX__
  53. #define LDBL_MAX __LDBL_MAX__
  54. /* Minimum normalized positive floating-point number, b**(emin - 1). */
  55. #undef FLT_MIN
  56. #undef DBL_MIN
  57. #undef LDBL_MIN
  58. #define FLT_MIN __FLT_MIN__
  59. #define DBL_MIN __DBL_MIN__
  60. #define LDBL_MIN __LDBL_MIN__
  61. /* Needed for libjava building - Victor K. */
  62. /* Radix of exponent representation, b. */
  63. #undef FLT_RADIX
  64. #define FLT_RADIX __FLT_RADIX__
  65. /* Minimum int x such that FLT_RADIX**(x-1) is a normalized float, emin */
  66. #undef FLT_MIN_EXP
  67. #undef DBL_MIN_EXP
  68. #undef LDBL_MIN_EXP
  69. #define FLT_MIN_EXP __FLT_MIN_EXP__
  70. #define DBL_MIN_EXP __DBL_MIN_EXP__
  71. #define LDBL_MIN_EXP __LDBL_MIN_EXP__
  72. /* Minimum negative integer such that 10 raised to that power is in the
  73. range of normalized floating-point numbers,
  74. ceil(log10(b) * (emin - 1))
  75. */
  76. #undef FLT_MIN_10_EXP
  77. #undef DBL_MIN_10_EXP
  78. #undef LDBL_MIN_10_EXP
  79. #define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
  80. #define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
  81. #define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
  82. /* Maximum int x such that FLT_RADIX**(x-1) is a representable float, emax. */
  83. #undef FLT_MAX_EXP
  84. #undef DBL_MAX_EXP
  85. #undef LDBL_MAX_EXP
  86. #define FLT_MAX_EXP __FLT_MAX_EXP__
  87. #define DBL_MAX_EXP __DBL_MAX_EXP__
  88. #define LDBL_MAX_EXP __LDBL_MAX_EXP__
  89. /* Maximum integer such that 10 raised to that power is in the range of
  90. representable finite floating-point numbers,
  91. floor(log10((1 - b**-p) * b**emax))
  92. */
  93. #undef FLT_MAX_10_EXP
  94. #undef DBL_MAX_10_EXP
  95. #undef LDBL_MAX_10_EXP
  96. #define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
  97. #define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
  98. #define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
  99. /* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown. */
  100. /* ??? This is supposed to change with calls to fesetround in <fenv.h>. */
  101. #undef FLT_ROUNDS
  102. #define FLT_ROUNDS 1
  103. #undef FLT_EPSILON
  104. #undef DBL_EPSILON
  105. #undef LDBL_EPSILON
  106. #define FLT_EPSILON __FLT_EPSILON__
  107. #define DBL_EPSILON __DBL_EPSILON__
  108. #define LDBL_EPSILON __LDBL_EPSILON__
  109. #define _FLOAT_H___
  110. #endif
  111. #endif
  112. #endif
  113. #ifndef _MINGW_FLOAT_H_
  114. #define _MINGW_FLOAT_H_
  115. /* All the headers include this file. */
  116. #include <crtdefs.h>
  117. /*
  118. * Functions and definitions for controlling the FPU.
  119. */
  120. /* TODO: These constants are only valid for x86 machines */
  121. /* Control word masks for unMask */
  122. #define _MCW_DN 0x03000000 /* Denormal control */
  123. #define _MCW_EM 0x0008001F /* Error masks */
  124. #define _MCW_IC 0x00040000 /* Infinity */
  125. #define _MCW_RC 0x00000300 /* Rounding */
  126. #define _MCW_PC 0x00030000 /* Precision */
  127. /* Number of base-FLT_RADIX digits in the significand, p. */
  128. #undef FLT_MANT_DIG
  129. #undef DBL_MANT_DIG
  130. #undef LDBL_MANT_DIG
  131. #define FLT_MANT_DIG __FLT_MANT_DIG__
  132. #define DBL_MANT_DIG __DBL_MANT_DIG__
  133. #define LDBL_MANT_DIG __LDBL_MANT_DIG__
  134. #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  135. /* The floating-point expression evaluation method.
  136. -1 indeterminate
  137. 0 evaluate all operations and constants just to the range and
  138. precision of the type
  139. 1 evaluate operations and constants of type float and double
  140. to the range and precision of the double type, evaluate
  141. long double operations and constants to the range and
  142. precision of the long double type
  143. 2 evaluate all operations and constants to the range and
  144. precision of the long double type
  145. ??? This ought to change with the setting of the fp control word;
  146. the value provided by the compiler assumes the widest setting. */
  147. #undef FLT_EVAL_METHOD
  148. #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
  149. #endif /* C99 */
  150. /* Control word values for unNew (use with related unMask above) */
  151. #define _DN_SAVE 0x00000000
  152. #define _DN_FLUSH 0x01000000
  153. #define _EM_INVALID 0x00000010
  154. #define _EM_DENORMAL 0x00080000
  155. #define _EM_ZERODIVIDE 0x00000008
  156. #define _EM_OVERFLOW 0x00000004
  157. #define _EM_UNDERFLOW 0x00000002
  158. #define _EM_INEXACT 0x00000001
  159. #define _IC_AFFINE 0x00040000
  160. #define _IC_PROJECTIVE 0x00000000
  161. #define _RC_CHOP 0x00000300
  162. #define _RC_UP 0x00000200
  163. #define _RC_DOWN 0x00000100
  164. #define _RC_NEAR 0x00000000
  165. #define _PC_24 0x00020000
  166. #define _PC_53 0x00010000
  167. #define _PC_64 0x00000000
  168. /* These are also defined in Mingw math.h, needed to work around
  169. GCC build issues. */
  170. /* Return values for fpclass. */
  171. #ifndef __MINGW_FPCLASS_DEFINED
  172. #define __MINGW_FPCLASS_DEFINED 1
  173. #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
  174. #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
  175. #define _FPCLASS_NINF 0x0004 /* Negative Infinity */
  176. #define _FPCLASS_NN 0x0008 /* Negative Normal */
  177. #define _FPCLASS_ND 0x0010 /* Negative Denormal */
  178. #define _FPCLASS_NZ 0x0020 /* Negative Zero */
  179. #define _FPCLASS_PZ 0x0040 /* Positive Zero */
  180. #define _FPCLASS_PD 0x0080 /* Positive Denormal */
  181. #define _FPCLASS_PN 0x0100 /* Positive Normal */
  182. #define _FPCLASS_PINF 0x0200 /* Positive Infinity */
  183. #endif /* __MINGW_FPCLASS_DEFINED */
  184. /* invalid subconditions (_SW_INVALID also set) */
  185. #define _SW_UNEMULATED 0x0040 /* unemulated instruction */
  186. #define _SW_SQRTNEG 0x0080 /* square root of a neg number */
  187. #define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */
  188. #define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */
  189. /* Floating point error signals and return codes */
  190. #define _FPE_INVALID 0x81
  191. #define _FPE_DENORMAL 0x82
  192. #define _FPE_ZERODIVIDE 0x83
  193. #define _FPE_OVERFLOW 0x84
  194. #define _FPE_UNDERFLOW 0x85
  195. #define _FPE_INEXACT 0x86
  196. #define _FPE_UNEMULATED 0x87
  197. #define _FPE_SQRTNEG 0x88
  198. #define _FPE_STACKOVERFLOW 0x8a
  199. #define _FPE_STACKUNDERFLOW 0x8b
  200. #define _FPE_EXPLICITGEN 0x8c /* raise( SIGFPE ); */
  201. #ifndef __STRICT_ANSI__
  202. #define CW_DEFAULT _CW_DEFAULT
  203. #define MCW_PC _MCW_PC
  204. #define PC_24 _PC_24
  205. #define PC_53 _PC_53
  206. #define PC_64 _PC_64
  207. #endif /* Not __STRICT_ANSI__ */
  208. #if defined(__i386__)
  209. #define _CW_DEFAULT (_RC_NEAR+_PC_53+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
  210. #elif defined(__ia64__)
  211. #define _CW_DEFAULT (_RC_NEAR+_PC_64+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
  212. #elif defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
  213. #define _CW_DEFAULT (_RC_NEAR+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
  214. #endif
  215. #ifndef RC_INVOKED
  216. #ifdef __cplusplus
  217. extern "C" {
  218. #endif
  219. /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
  220. * i.e. change the bits in unMask to have the values they have in unNew,
  221. * leaving other bits unchanged. */
  222. _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int _NewValue, unsigned int _Mask) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
  223. _SECIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask);
  224. _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int _NewValue, unsigned int _Mask);
  225. _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void); /* Clear the FPU status word */
  226. _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void); /* Report the FPU status word */
  227. #define _clear87 _clearfp
  228. #define _status87 _statusfp
  229. /*
  230. MSVCRT.dll _fpreset initializes the control register to 0x27f,
  231. the status register to zero and the tag word to 0FFFFh.
  232. This differs from asm instruction finit/fninit which set control
  233. word to 0x37f (64 bit mantissa precison rather than 53 bit).
  234. By default, the mingw version of _fpreset sets fp control as
  235. per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
  236. building your application.
  237. */
  238. void __cdecl __MINGW_NOTHROW _fpreset (void);
  239. #ifndef __STRICT_ANSI__
  240. void __cdecl __MINGW_NOTHROW fpreset (void);
  241. #endif /* Not __STRICT_ANSI__ */
  242. /* Global 'variable' for the current floating point error code. */
  243. _CRTIMP int * __cdecl __MINGW_NOTHROW __fpecode(void);
  244. #define _fpecode (*(__fpecode()))
  245. /*
  246. * IEEE recommended functions. MS puts them in float.h
  247. * but they really belong in math.h.
  248. */
  249. #ifndef _SIGN_DEFINED
  250. #define _SIGN_DEFINED
  251. _CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double _X);
  252. _CRTIMP double __cdecl __MINGW_NOTHROW _copysign (double _Number,double _Sign);
  253. _CRTIMP double __cdecl __MINGW_NOTHROW _logb (double);
  254. _CRTIMP double __cdecl __MINGW_NOTHROW _nextafter (double, double);
  255. _CRTIMP double __cdecl __MINGW_NOTHROW _scalb (double, long);
  256. _CRTIMP int __cdecl __MINGW_NOTHROW _finite (double);
  257. _CRTIMP int __cdecl __MINGW_NOTHROW _fpclass (double);
  258. _CRTIMP int __cdecl __MINGW_NOTHROW _isnan (double);
  259. #define _copysignl copysignl
  260. extern long double __cdecl _chgsignl (long double);
  261. #endif /* _SIGN_DEFINED */
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265. #endif /* Not RC_INVOKED */
  266. #endif /* _MINGW_FLOAT_H_ */