Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
11 KiB

  1. //
  2. // Copyright (c) 2000, Intel Corporation
  3. // All rights reserved.
  4. //
  5. // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
  6. // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
  7. //
  8. // WARRANTY DISCLAIMER
  9. //
  10. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  11. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  12. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  13. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  14. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  15. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18. // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  19. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. //
  22. // Intel Corporation is the author of this code, and requests that all
  23. // problem reports or change requests be submitted to it directly at
  24. // http://developer.intel.com/opensource.
  25. //
  26. // History: 02/02/2000 Initial version
  27. // 2/28/2000 added tags for logb and nextafter
  28. // 3/22/2000 Changes to support _LIB_VERSION variable
  29. // and filled some enum gaps. Added support for C99.
  30. //
  31. #define SIZE_INT_32
  32. #define __MS__
  33. float __libm_frexp_4f( float x, int* exp);
  34. float __libm_frexp_8f( double x, int* exp);
  35. double __libm_frexp_4( double x, int* exp);
  36. double __libm_frexp_8( double x, int* exp);
  37. void __libm_sincos_pi4(double,double*,double*,int);
  38. void __libm_y0y1(double , double *, double *);
  39. void __libm_j0j1(double , double *, double *);
  40. double __libm_lgamma_kernel(double,int*,int,int);
  41. double __libm_j0(double);
  42. double __libm_j1(double);
  43. double __libm_jn(int,double);
  44. double __libm_y0(double);
  45. double __libm_y1(double);
  46. double __libm_yn(int,double);
  47. extern double rint(double);
  48. extern double sqrt(double);
  49. extern double fabs(double);
  50. extern double log(double);
  51. extern double sin(double);
  52. extern double exp(double);
  53. extern double modf(double, double *);
  54. extern double asinh(double);
  55. extern double acosh(double);
  56. extern double atanh(double);
  57. extern double tanh(double);
  58. extern double erf(double);
  59. extern double erfc(double);
  60. extern double j0(double);
  61. extern double j1(double);
  62. extern double jn(int, double);
  63. extern double y0(double);
  64. extern double y1(double);
  65. extern double yn(int, double);
  66. extern float fabsf(float);
  67. extern float asinhf(float);
  68. extern float acoshf(float);
  69. extern float atanhf(float);
  70. extern float tanhf(float);
  71. extern float erff(float);
  72. extern float erfcf(float);
  73. extern float j0f(float);
  74. extern float j1f(float);
  75. extern float jnf(int, float);
  76. extern float y0f(float);
  77. extern float y1f(float);
  78. extern float ynf(int, float);
  79. #if !(defined(SIZE_INT_32) || defined(SIZE_INT_64))
  80. #error integer size not established; define SIZE_INT_32 or SIZE_INT_64
  81. #endif
  82. struct fp64 { /*/ sign:1 exponent:11 significand:52 (implied leading 1)*/
  83. unsigned lo_significand:32;
  84. unsigned hi_significand:20;
  85. unsigned exponent:11;
  86. unsigned sign:1;
  87. };
  88. #define HI_SIGNIFICAND_LESS(X, HI) ((X)->hi_significand < 0x ## HI)
  89. #define f64abs(x) ((x) < 0.0 ? -(x) : (x))
  90. typedef enum
  91. {
  92. logl_zero=0, logl_negative, /* 0, 1 */
  93. log_zero, log_negative, /* 2, 3 */
  94. logf_zero, logf_negative, /* 4, 5 */
  95. log10l_zero, log10l_negative, /* 6, 7 */
  96. log10_zero, log10_negative, /* 8, 9 */
  97. log10f_zero, log10f_negative, /* 10, 11 */
  98. expl_overflow, expl_underflow, /* 12, 13 */
  99. exp_overflow, exp_underflow, /* 14, 15 */
  100. expf_overflow, expf_underflow, /* 16, 17 */
  101. powl_overflow, powl_underflow, /* 18, 19 */
  102. powl_zero_to_zero, /* 20 */
  103. powl_zero_to_negative, /* 21 */
  104. powl_neg_to_non_integer, /* 22 */
  105. powl_nan_to_zero, /* 23 */
  106. pow_overflow, pow_underflow, /* 24, 25 */
  107. pow_zero_to_zero, /* 26 */
  108. pow_zero_to_negative, /* 27 */
  109. pow_neg_to_non_integer, /* 28 */
  110. pow_nan_to_zero, /* 29 */
  111. powf_overflow, powf_underflow, /* 30, 31 */
  112. powf_zero_to_zero, /* 32 */
  113. powf_zero_to_negative, /* 33 */
  114. powf_neg_to_non_integer, /* 34 */
  115. powf_nan_to_zero, /* 35 */
  116. atan2l_zero, /* 36 */
  117. atan2_zero, /* 37 */
  118. atan2f_zero, /* 38 */
  119. expm1l_overflow, /* 39 */
  120. expm1l_underflow, /* 40 */
  121. expm1_overflow, /* 41 */
  122. expm1_underflow, /* 42 */
  123. expm1f_overflow, /* 43 */
  124. expm1f_underflow, /* 44 */
  125. hypotl_overflow, /* 45 */
  126. hypot_overflow, /* 46 */
  127. hypotf_overflow, /* 47 */
  128. sqrtl_negative, /* 48 */
  129. sqrt_negative, /* 49 */
  130. sqrtf_negative, /* 50 */
  131. scalbl_overflow, scalbl_underflow, /* 51,52 */
  132. scalb_overflow, scalb_underflow, /* 53,54 */
  133. scalbf_overflow, scalbf_underflow, /* 55,56 */
  134. acosl_gt_one, acos_gt_one, acosf_gt_one, /* 57, 58, 59 */
  135. asinl_gt_one, asin_gt_one, asinf_gt_one, /* 60, 61, 62 */
  136. coshl_overflow, cosh_overflow, coshf_overflow, /* 63, 64, 65 */
  137. y0l_zero, y0l_negative,y0l_gt_loss, /* 66, 67, 68 */
  138. y0_zero, y0_negative,y0_gt_loss, /* 69, 70, 71 */
  139. y0f_zero, y0f_negative,y0f_gt_loss, /* 72, 73, 74 */
  140. y1l_zero, y1l_negative,y1l_gt_loss, /* 75, 76, 77 */
  141. y1_zero, y1_negative,y1_gt_loss, /* 78, 79, 80 */
  142. y1f_zero, y1f_negative,y1f_gt_loss, /* 81, 82, 83 */
  143. ynl_zero, ynl_negative,ynl_gt_loss, /* 84, 85, 86 */
  144. yn_zero, yn_negative,yn_gt_loss, /* 87, 88, 89 */
  145. ynf_zero, ynf_negative,ynf_gt_loss, /* 90, 91, 92 */
  146. j0l_gt_loss, /* 93 */
  147. j0_gt_loss, /* 94 */
  148. j0f_gt_loss, /* 95 */
  149. j1l_gt_loss, /* 96 */
  150. j1_gt_loss, /* 97 */
  151. j1f_gt_loss, /* 98 */
  152. jnl_gt_loss, /* 99 */
  153. jn_gt_loss, /* 100 */
  154. jnf_gt_loss, /* 101 */
  155. lgammal_overflow, lgammal_negative,lgammal_reserve, /* 102, 103, 104 */
  156. lgamma_overflow, lgamma_negative,lgamma_reserve, /* 105, 106, 107 */
  157. lgammaf_overflow, lgammaf_negative, lgammaf_reserve,/* 108, 109, 110 */
  158. gammal_overflow,gammal_negative, gammal_reserve, /* 111, 112, 113 */
  159. gamma_overflow, gamma_negative, gamma_reserve, /* 114, 115, 116 */
  160. gammaf_overflow,gammaf_negative,gammaf_reserve, /* 117, 118, 119 */
  161. fmodl_by_zero, /* 120 */
  162. fmod_by_zero, /* 121 */
  163. fmodf_by_zero, /* 122 */
  164. remainderl_by_zero, /* 123 */
  165. remainder_by_zero, /* 124 */
  166. remainderf_by_zero, /* 125 */
  167. sinhl_overflow, sinh_overflow, sinhf_overflow, /* 126, 127, 128 */
  168. atanhl_gt_one, atanhl_eq_one, /* 129, 130 */
  169. atanh_gt_one, atanh_eq_one, /* 131, 132 */
  170. atanhf_gt_one, atanhf_eq_one, /* 133, 134 */
  171. acoshl_lt_one, /* 135 */
  172. acosh_lt_one, /* 136 */
  173. acoshf_lt_one, /* 137 */
  174. log1pl_zero, log1pl_negative, /* 138, 139 */
  175. log1p_zero, log1p_negative, /* 140, 141 */
  176. log1pf_zero, log1pf_negative, /* 142, 143 */
  177. ldexpl_overflow, ldexpl_underflow, /* 144, 145 */
  178. ldexp_overflow, ldexp_underflow, /* 146, 147 */
  179. ldexpf_overflow, ldexpf_underflow, /* 148, 149 */
  180. logbl_zero, logb_zero, logbf_zero, /* 150, 151,152 */
  181. nextafterl_overflow, nextafter_overflow, nextafterf_overflow /* 153, 154,155 */
  182. } error_types;
  183. void __libm_error_support(void*,void*,void*,error_types);
  184. #define BIAS_64 1023
  185. #define EXPINF_64 2047
  186. #define DOUBLE_HEX(HI, LO) 0x ## LO, 0x ## HI
  187. static const unsigned INF[] = {
  188. DOUBLE_HEX(7ff00000, 00000000),
  189. DOUBLE_HEX(fff00000, 00000000)
  190. };
  191. static const double _zeroo = 0.0;
  192. static const double _bigg = 1.0e300;
  193. static const double _ponee = 1.0;
  194. static const double _nonee = -1.0;
  195. #define INVALID (_zeroo * *((double*)&INF[0]))
  196. #define PINF *((double*)&INF[0])
  197. #define NINF -PINF
  198. #define PINF_DZ (_ponee/_zeroo)
  199. #define X_TLOSS 1.41484755040568800000e+16
  200. # ifdef __cplusplus
  201. struct __exception
  202. {
  203. int type;
  204. char *name;
  205. double arg1, arg2, retval;
  206. };
  207. # else
  208. struct exception
  209. {
  210. int type;
  211. char *name;
  212. double arg1, arg2, retval;
  213. };
  214. #endif
  215. #ifdef __MS__
  216. #define exceptionf exception
  217. #elif
  218. struct exceptionf
  219. {
  220. int type;
  221. char *name;
  222. float arg1, arg2, retval;
  223. };
  224. struct exceptionl
  225. {
  226. int type;
  227. char *name;
  228. long double arg1, arg2, retval;
  229. };
  230. #endif
  231. #ifdef __MS__
  232. #define _matherrf _matherr
  233. #else
  234. extern int matherrf(struct exceptionf*);
  235. #endif
  236. # ifdef __cplusplus
  237. #ifdef __MS__
  238. extern int _matherr(struct __exception*);
  239. #else
  240. extern int matherr(struct __exception*);
  241. #endif
  242. # else
  243. #ifdef __MS__
  244. extern int _matherr(struct exception*);
  245. # else
  246. extern int matherr(struct exception*);
  247. # endif
  248. # endif
  249. // exception is a reserved name in C++
  250. extern int matherrl(struct exceptionl*);
  251. /* Set these appropriately to make thread Safe */
  252. #define ERRNO_RANGE errno = ERANGE
  253. #define ERRNO_DOMAIN errno = EDOM
  254. // Add code to support _LIB_VERSION
  255. typedef enum
  256. {
  257. _IEEE_ = -1, // IEEE-like behavior
  258. _SVID_, // SysV, Rel. 4 behavior
  259. _XOPEN_, // Unix98
  260. __POSIX__, // Posix
  261. _ISOC_, // ISO C9X
  262. _MS_ // Microsoft version
  263. } _LIB_VERSION_TYPE;
  264. extern _LIB_VERSION_TYPE _LIB_VERSION;
  265. // This is a run-time variable and may effect
  266. // floating point behavior of the libm functions