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.

309 lines
9.0 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, James
  6. // Edwards, 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
  27. //==============================================================
  28. // 2/02/00: Initial version.
  29. // 2/12/01: Updated to be NT double precision specific.
  30. #include <errno.h>
  31. #include <stdio.h>
  32. #include "libm_support.h"
  33. /************************************************************/
  34. /* matherrX function pointers and setusermatherrX functions */
  35. /************************************************************/
  36. int (*_pmatherr)(struct EXC_DECL_D*) = MATHERR_D;
  37. /***********************************************/
  38. /* error-handling function, libm_error_support */
  39. /***********************************************/
  40. void __libm_error_support(void *arg1,void *arg2,void *retval,error_types input_tag)
  41. {
  42. struct _exception exc;
  43. const char double_inf[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x7F};
  44. const char double_huge[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0x7F};
  45. const char double_zero[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  46. const char double_neg_inf[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFF};
  47. const char double_neg_huge[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xFF};
  48. const char double_neg_zero[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80};
  49. #define RETVAL_HUGE_VALD *(double *)retval = *(double *) double_inf
  50. #define RETVAL_NEG_HUGE_VALD *(double *)retval = *(double *) double_neg_inf
  51. #define RETVAL_HUGED *(double *)retval = (double) *(float *)float_huge
  52. #define RETVAL_NEG_HUGED *(double *)retval = (double) *(float *) float_neg_huge
  53. #define RETVAL_ZEROD *(double *)retval = *(double *)double_zero
  54. #define RETVAL_NEG_ZEROD *(double *)retval = *(double *)double_neg_zero
  55. #define RETVAL_ONED *(double *)retval = 1.0
  56. #define NOT_MATHERRD exc.arg1=*(double *)arg1;exc.arg2=*(double *)arg2;exc.retval=*(double *)retval;if(!_pmatherr(&exc))
  57. #define NAMED exc.name
  58. //
  59. // These should work OK for MS because they are ints -
  60. // leading underbars are not necessary.
  61. //
  62. #define DOMAIN 1
  63. #define SING 2
  64. #define OVERFLOW 3
  65. #define UNDERFLOW 4
  66. #define TLOSS 5
  67. #define PLOSS 6
  68. #define SINGD exc.type = SING
  69. #define DOMAIND exc.type = DOMAIN
  70. #define OVERFLOWD exc.type = OVERFLOW
  71. #define UNDERFLOWD exc.type = UNDERFLOW
  72. #define TLOSSD exc.type = TLOSS
  73. #define INPUT_XD (exc.arg1=*(double*)arg1)
  74. #define INPUT_YD (exc.arg1=*(double*)arg2)
  75. #define INPUT_RESD (*(double *)retval)
  76. #define WRITED_LOG_ZERO fputs("log: SING error\n",stderr)
  77. #define WRITED_LOG_NEGATIVE fputs("log: DOMAIN error\n",stderr)
  78. #define WRITED_LOG10_ZERO fputs("log10: SING error\n",stderr)
  79. #define WRITED_LOG10_NEGATIVE fputs("log10: DOMAIN error\n",stderr)
  80. #define WRITED_POW_ZERO_TO_ZERO fputs("pow(0,0): DOMAIN error\n",stderr)
  81. #define WRITED_POW_ZERO_TO_NEGATIVE fputs("pow(0,negative): DOMAIN error\n",stderr)
  82. #define WRITED_POW_NEG_TO_NON_INTEGER fputs("pow(negative,non-integer): DOMAIN error\n",stderr)
  83. switch(input_tag)
  84. {
  85. case log_zero:
  86. /* log(0) */
  87. {
  88. SINGD; NAMED="log";
  89. NOT_MATHERRD {ERRNO_RANGE;}
  90. *(double *)retval = exc.retval;
  91. break;
  92. }
  93. case log_negative:
  94. /* log(x < 0) */
  95. {
  96. DOMAIND; NAMED="log";
  97. NOT_MATHERRD {ERRNO_DOMAIN;}
  98. *(double *)retval = exc.retval;
  99. break;
  100. }
  101. case log10_zero:
  102. /* log10(0) */
  103. {
  104. SINGD; NAMED="log10";
  105. NOT_MATHERRD {ERRNO_RANGE;}
  106. *(double *)retval = exc.retval;
  107. break;
  108. }
  109. case log10_negative:
  110. /* log10(x < 0) */
  111. {
  112. DOMAIND; NAMED="log10";
  113. NOT_MATHERRD {ERRNO_DOMAIN;}
  114. *(double *)retval = exc.retval;
  115. break;
  116. }
  117. case exp_overflow:
  118. /* exp overflow */
  119. {
  120. OVERFLOWD; NAMED="exp";
  121. NOT_MATHERRD {ERRNO_RANGE;}
  122. *(double *)retval = exc.retval;
  123. break;
  124. }
  125. case exp_underflow:
  126. /* exp underflow */
  127. {
  128. UNDERFLOWD; NAMED="exp";
  129. NOT_MATHERRD {}
  130. *(double *)retval = exc.retval;
  131. break;
  132. }
  133. case pow_zero_to_zero:
  134. /* pow 0**0 */
  135. {
  136. DOMAIND; NAMED="pow";
  137. RETVAL_ONED;
  138. break;
  139. }
  140. case pow_overflow:
  141. /* pow(x,y) overflow */
  142. {
  143. OVERFLOWD; NAMED = "pow";
  144. NOT_MATHERRD {ERRNO_RANGE;}
  145. *(double *)retval = exc.retval;
  146. break;
  147. }
  148. case pow_underflow:
  149. /* pow(x,y) underflow */
  150. {
  151. UNDERFLOWD; NAMED = "pow";
  152. NOT_MATHERRD {}
  153. *(double *)retval = exc.retval;
  154. break;
  155. }
  156. case pow_zero_to_negative:
  157. /* 0**neg */
  158. {
  159. SINGD; NAMED = "pow";
  160. NOT_MATHERRD {ERRNO_RANGE;}
  161. *(double *)retval = exc.retval;
  162. break;
  163. }
  164. case pow_neg_to_non_integer:
  165. /* neg**non_integral */
  166. {
  167. DOMAIND; NAMED = "pow";
  168. NOT_MATHERRD {ERRNO_DOMAIN;}
  169. *(double *)retval = exc.retval;
  170. break;
  171. }
  172. case pow_nan_to_zero:
  173. /* pow(NaN,0.0) */
  174. /* Special Error */
  175. {
  176. DOMAIND; NAMED = "pow"; INPUT_XD; INPUT_YD;
  177. *(double *)retval = *(double *)arg1 * 1.0;
  178. NOT_MATHERRD {ERRNO_DOMAIN;}
  179. *(double *)retval = exc.retval;
  180. break;
  181. }
  182. case log2_zero:
  183. /* log2(0) */
  184. {
  185. SINGD; NAMED="log2";
  186. NOT_MATHERRD {ERRNO_RANGE;}
  187. *(double *)retval = exc.retval;
  188. break;
  189. }
  190. case log2_negative:
  191. /* log2(negative) */
  192. {
  193. DOMAIND; NAMED="log2";
  194. NOT_MATHERRD {ERRNO_DOMAIN;}
  195. *(double *)retval = exc.retval;
  196. break;
  197. }
  198. case exp2_underflow:
  199. /* exp2 underflow */
  200. {
  201. UNDERFLOWD; NAMED="exp2";
  202. NOT_MATHERRD {ERRNO_RANGE;}
  203. *(double *)retval = exc.retval;
  204. break;
  205. }
  206. case exp2_overflow:
  207. /* exp2 overflow */
  208. {
  209. OVERFLOWD; NAMED="exp2";
  210. NOT_MATHERRD {ERRNO_RANGE;}
  211. *(double *)retval = exc.retval;
  212. break;
  213. }
  214. case exp10_overflow:
  215. /* exp10 overflow */
  216. {
  217. OVERFLOWD; NAMED="exp10";
  218. NOT_MATHERRD {ERRNO_RANGE;}
  219. *(double *)retval = exc.retval;
  220. break;
  221. }
  222. case log_nan:
  223. /* log(NaN) */
  224. {
  225. DOMAIND; NAMED="log";
  226. *(double *)retval = *(double *)arg1 * 1.0;
  227. NOT_MATHERRD {ERRNO_DOMAIN;}
  228. *(double *)retval = exc.retval;
  229. break;
  230. }
  231. case log10_nan:
  232. /* log10(NaN) */
  233. {
  234. DOMAIND; NAMED="log10";
  235. *(double *)retval = *(double *)arg1 * 1.0;
  236. NOT_MATHERRD {ERRNO_DOMAIN;}
  237. *(double *)retval = exc.retval;
  238. break;
  239. }
  240. case exp_nan:
  241. /* exp(NaN) */
  242. {
  243. DOMAIND; NAMED="exp";
  244. *(double *)retval = *(double *)arg1 * 1.0;
  245. NOT_MATHERRD {ERRNO_DOMAIN;}
  246. *(double *)retval = exc.retval;
  247. break;
  248. }
  249. case atan_nan:
  250. /* atan(NaN) */
  251. {
  252. DOMAIND; NAMED="atan";
  253. *(double *)retval = *(double *)arg1 * 1.0;
  254. NOT_MATHERRD {ERRNO_DOMAIN;}
  255. *(double *)retval = exc.retval;
  256. break;
  257. }
  258. case ceil_nan:
  259. /* ceil(NaN) */
  260. {
  261. DOMAIND; NAMED="ceil";
  262. *(double *)retval = *(double *)arg1 * 1.0;
  263. NOT_MATHERRD {ERRNO_DOMAIN;}
  264. *(double *)retval = exc.retval;
  265. break;
  266. }
  267. case floor_nan:
  268. /* floor(NaN) */
  269. {
  270. DOMAIND; NAMED="floor";
  271. *(double *)retval = *(double *)arg1 * 1.0;
  272. NOT_MATHERRD {ERRNO_DOMAIN;}
  273. *(double *)retval = exc.retval;
  274. break;
  275. }
  276. case pow_nan:
  277. /* pow(NaN,*) or pow(*,NaN) */
  278. {
  279. DOMAIND; NAMED="pow";
  280. NOT_MATHERRD {ERRNO_DOMAIN;}
  281. *(double *)retval = exc.retval;
  282. break;
  283. }
  284. case modf_nan:
  285. /* modf(NaN) */
  286. {
  287. DOMAIND; NAMED="modf";
  288. *(double *)retval = *(double *)arg1 * 1.0;
  289. NOT_MATHERRD {ERRNO_DOMAIN;}
  290. *(double *)retval = exc.retval;
  291. break;
  292. }
  293. }
  294. return;
  295. }