float.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * float.h
  3. *
  4. * Constants related to floating point arithmetic.
  5. *
  6. * Also included here are some non-ANSI bits for accessing the floating
  7. * point controller.
  8. *
  9. * NOTE: GCC provides float.h, and it is probably more accurate than this,
  10. * but it doesn't include the non-standard stuff for accessing the
  11. * fp controller. (TODO: Move those bits elsewhere?) Thus it is
  12. * probably not a good idea to use the GCC supplied version instead
  13. * of this header.
  14. *
  15. * This file is part of the Mingw32 package.
  16. *
  17. * Contributors:
  18. * Created by Colin Peters <[email protected]>
  19. *
  20. * THIS SOFTWARE IS NOT COPYRIGHTED
  21. *
  22. * This source code is offered for use in the public domain. You may
  23. * use, modify or distribute it freely.
  24. *
  25. * This code is distributed in the hope that it will be useful but
  26. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  27. * DISCLAIMED. This includes but is not limited to warranties of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  29. *
  30. * $Revision: 1.2 $
  31. * $Author: bellard $
  32. * $Date: 2005/04/17 13:14:29 $
  33. *
  34. */
  35. #ifndef _FLOAT_H_
  36. #define _FLOAT_H_
  37. /* All the headers include this file. */
  38. #include <_mingw.h>
  39. #define FLT_ROUNDS 1
  40. #define FLT_GUARD 1
  41. #define FLT_NORMALIZE 1
  42. /*
  43. * The characteristics of float.
  44. */
  45. /* The radix for floating point representation. */
  46. #define FLT_RADIX 2
  47. /* Decimal digits of precision. */
  48. #define FLT_DIG 6
  49. /* Smallest number such that 1+x != 1 */
  50. #define FLT_EPSILON 1.19209290e-07F
  51. /* The number of base FLT_RADIX digits in the mantissa. */
  52. #define FLT_MANT_DIG 24
  53. /* The maximum floating point number. */
  54. #define FLT_MAX 3.40282347e+38F
  55. /* Maximum n such that FLT_RADIX^n - 1 is representable. */
  56. #define FLT_MAX_EXP 128
  57. /* Maximum n such that 10^n is representable. */
  58. #define FLT_MAX_10_EXP 38
  59. /* Minimum normalized floating-point number. */
  60. #define FLT_MIN 1.17549435e-38F
  61. /* Minimum n such that FLT_RADIX^n is a normalized number. */
  62. #define FLT_MIN_EXP (-125)
  63. /* Minimum n such that 10^n is a normalized number. */
  64. #define FLT_MIN_10_EXP (-37)
  65. /*
  66. * The characteristics of double.
  67. */
  68. #define DBL_DIG 15
  69. #define DBL_EPSILON 1.1102230246251568e-16
  70. #define DBL_MANT_DIG 53
  71. #define DBL_MAX 1.7976931348623157e+308
  72. #define DBL_MAX_EXP 1024
  73. #define DBL_MAX_10_EXP 308
  74. #define DBL_MIN 2.2250738585072014e-308
  75. #define DBL_MIN_EXP (-1021)
  76. #define DBL_MIN_10_EXP (-307)
  77. /*
  78. * The characteristics of long double.
  79. * NOTE: long double is the same as double.
  80. */
  81. #define LDBL_DIG 15
  82. #define LDBL_EPSILON 1.1102230246251568e-16L
  83. #define LDBL_MANT_DIG 53
  84. #define LDBL_MAX 1.7976931348623157e+308L
  85. #define LDBL_MAX_EXP 1024
  86. #define LDBL_MAX_10_EXP 308
  87. #define LDBL_MIN 2.2250738585072014e-308L
  88. #define LDBL_MIN_EXP (-1021)
  89. #define LDBL_MIN_10_EXP (-307)
  90. /*
  91. * Functions and definitions for controlling the FPU.
  92. */
  93. #ifndef __STRICT_ANSI__
  94. /* TODO: These constants are only valid for x86 machines */
  95. /* Control word masks for unMask */
  96. #define _MCW_EM 0x0008001F /* Error masks */
  97. #define _MCW_IC 0x00040000 /* Infinity */
  98. #define _MCW_RC 0x00000300 /* Rounding */
  99. #define _MCW_PC 0x00030000 /* Precision */
  100. /* Control word values for unNew (use with related unMask above) */
  101. #define _EM_INVALID 0x00000010
  102. #define _EM_DENORMAL 0x00080000
  103. #define _EM_ZERODIVIDE 0x00000008
  104. #define _EM_OVERFLOW 0x00000004
  105. #define _EM_UNDERFLOW 0x00000002
  106. #define _EM_INEXACT 0x00000001
  107. #define _IC_AFFINE 0x00040000
  108. #define _IC_PROJECTIVE 0x00000000
  109. #define _RC_CHOP 0x00000300
  110. #define _RC_UP 0x00000200
  111. #define _RC_DOWN 0x00000100
  112. #define _RC_NEAR 0x00000000
  113. #define _PC_24 0x00020000
  114. #define _PC_53 0x00010000
  115. #define _PC_64 0x00000000
  116. /* These are also defined in Mingw math.h, needed to work around
  117. GCC build issues. */
  118. /* Return values for fpclass. */
  119. #ifndef __MINGW_FPCLASS_DEFINED
  120. #define __MINGW_FPCLASS_DEFINED 1
  121. #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
  122. #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
  123. #define _FPCLASS_NINF 0x0004 /* Negative Infinity */
  124. #define _FPCLASS_NN 0x0008 /* Negative Normal */
  125. #define _FPCLASS_ND 0x0010 /* Negative Denormal */
  126. #define _FPCLASS_NZ 0x0020 /* Negative Zero */
  127. #define _FPCLASS_PZ 0x0040 /* Positive Zero */
  128. #define _FPCLASS_PD 0x0080 /* Positive Denormal */
  129. #define _FPCLASS_PN 0x0100 /* Positive Normal */
  130. #define _FPCLASS_PINF 0x0200 /* Positive Infinity */
  131. #endif /* __MINGW_FPCLASS_DEFINED */
  132. /* invalid subconditions (_SW_INVALID also set) */
  133. #define _SW_UNEMULATED 0x0040 /* unemulated instruction */
  134. #define _SW_SQRTNEG 0x0080 /* square root of a neg number */
  135. #define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */
  136. #define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */
  137. /* Floating point error signals and return codes */
  138. #define _FPE_INVALID 0x81
  139. #define _FPE_DENORMAL 0x82
  140. #define _FPE_ZERODIVIDE 0x83
  141. #define _FPE_OVERFLOW 0x84
  142. #define _FPE_UNDERFLOW 0x85
  143. #define _FPE_INEXACT 0x86
  144. #define _FPE_UNEMULATED 0x87
  145. #define _FPE_SQRTNEG 0x88
  146. #define _FPE_STACKOVERFLOW 0x8a
  147. #define _FPE_STACKUNDERFLOW 0x8b
  148. #define _FPE_EXPLICITGEN 0x8c /* raise( SIGFPE ); */
  149. #ifndef RC_INVOKED
  150. #ifdef __cplusplus
  151. extern "C" {
  152. #endif
  153. /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
  154. * i.e. change the bits in unMask to have the values they have in unNew,
  155. * leaving other bits unchanged. */
  156. unsigned int _controlfp (unsigned int unNew, unsigned int unMask);
  157. unsigned int _control87 (unsigned int unNew, unsigned int unMask);
  158. unsigned int _clearfp (void); /* Clear the FPU status word */
  159. unsigned int _statusfp (void); /* Report the FPU status word */
  160. #define _clear87 _clearfp
  161. #define _status87 _statusfp
  162. void _fpreset (void); /* Reset the FPU */
  163. void fpreset (void);
  164. /* Global 'variable' for the current floating point error code. */
  165. int * __fpecode(void);
  166. #define _fpecode (*(__fpecode()))
  167. /*
  168. * IEEE recommended functions
  169. */
  170. double _chgsign (double);
  171. double _copysign (double, double);
  172. double _logb (double);
  173. double _nextafter (double, double);
  174. double _scalb (double, long);
  175. int _finite (double);
  176. int _fpclass (double);
  177. int _isnan (double);
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* Not RC_INVOKED */
  182. #endif /* Not __STRICT_ANSI__ */
  183. #endif /* _FLOAT_H_ */