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.

2694 lines
89 KiB

  1. /*++
  2. Copyright (c) 1990-1991 Microsoft Corporation
  3. Module Name:
  4. htmath.c
  5. Abstract:
  6. This module contains the basic math. functions for the halftone
  7. process.
  8. Author:
  9. 16-Jan-1991 Wed 10:51:27 created -by- Daniel Chou (danielc)
  10. [Environment:]
  11. GDI Device Driver - Halftone.
  12. [Notes:]
  13. Revision History:
  14. 02-Feb-1994 Wed 18:08:13 updated -by- Daniel Chou (danielc)
  15. Remove unary unsigned wranings.
  16. --*/
  17. #define DBGP_VARNAME dbgpHTMath
  18. #define HAS_80x86_EQUIVALENT_CODES
  19. #include "htp.h"
  20. #include "htmath.h"
  21. #define DBGP_MAPPING 0x0001
  22. #define DBGP_CONCAT_M 0x0002
  23. DEF_DBGPVAR(BIT_IF(DBGP_CONCAT_M, 0) |
  24. BIT_IF(DBGP_MAPPING, 0))
  25. #if DBG
  26. LPBYTE pDbgRegMode[] = { "LINEAR", "LOG", "EXP", "POWER" };
  27. #endif
  28. //
  29. // Local definitions only used in this file
  30. //
  31. #define ABSFD6(a) (FD6)(((a) < 0L) ? -(a) : (a))
  32. #define SWAPFD6(a, b, t) (t)=(a); (a)=(b); (b)=(t)
  33. #define U16_H_U32(a) (WORD)((DWORD)(a) >> 16)
  34. #define U16_L_U32(a) (WORD)((DWORD)(a) & 0xffffL)
  35. #define FD6_LOG_MIN -FD6_6
  36. #define FD6_LOG_MAX (FD6)3331930L
  37. #define FD6ToL(n) (LONG)(n)
  38. #define FD6FromL(n) (FD6)(n)
  39. #define NEGDW(x) (DWORD)(-(LONG)(x))
  40. #define MIN_FD6 (FD6)-(LONG)2147483648
  41. #define MAX_FD6 (FD6)(LONG)2147483647
  42. //
  43. // MANTISSATABLE
  44. //
  45. // This is the look up table for the mantissa portion of the log number, the
  46. // table range from 1.00 to 10.00 at increment of 0.01 for the look up
  47. // numbers. If the requested number has lies between two look up numbers
  48. // then an interpolation is done using those two look up numbers.
  49. //
  50. #define MANTISSATABLE_SIZE 901
  51. FD6 MantissaTable[MANTISSATABLE_SIZE] = {
  52. (FD6)0, (FD6)4321, // 1.00 - 1.01
  53. (FD6)8600, (FD6)12837, // 1.02 - 1.03
  54. (FD6)17033, (FD6)21189, // 1.04 - 1.05
  55. (FD6)25306, (FD6)29384, // 1.06 - 1.07
  56. (FD6)33424, (FD6)37426, // 1.08 - 1.09
  57. (FD6)41393, (FD6)45323, // 1.10 - 1.11
  58. (FD6)49218, (FD6)53078, // 1.12 - 1.13
  59. (FD6)56905, (FD6)60698, // 1.14 - 1.15
  60. (FD6)64458, (FD6)68186, // 1.16 - 1.17
  61. (FD6)71882, (FD6)75547, // 1.18 - 1.19
  62. (FD6)79181, (FD6)82785, // 1.20 - 1.21
  63. (FD6)86360, (FD6)89905, // 1.22 - 1.23
  64. (FD6)93422, (FD6)96910, // 1.24 - 1.25
  65. (FD6)100371, (FD6)103804, // 1.26 - 1.27
  66. (FD6)107210, (FD6)110590, // 1.28 - 1.29
  67. (FD6)113943, (FD6)117271, // 1.30 - 1.31
  68. (FD6)120574, (FD6)123852, // 1.32 - 1.33
  69. (FD6)127105, (FD6)130334, // 1.34 - 1.35
  70. (FD6)133539, (FD6)136721, // 1.36 - 1.37
  71. (FD6)139879, (FD6)143015, // 1.38 - 1.39
  72. (FD6)146128, (FD6)149219, // 1.40 - 1.41
  73. (FD6)152288, (FD6)155336, // 1.42 - 1.43
  74. (FD6)158362, (FD6)161368, // 1.44 - 1.45
  75. (FD6)164353, (FD6)167317, // 1.46 - 1.47
  76. (FD6)170262, (FD6)173186, // 1.48 - 1.49
  77. (FD6)176091, (FD6)178977, // 1.50 - 1.51
  78. (FD6)181844, (FD6)184691, // 1.52 - 1.53
  79. (FD6)187521, (FD6)190332, // 1.54 - 1.55
  80. (FD6)193125, (FD6)195900, // 1.56 - 1.57
  81. (FD6)198657, (FD6)201397, // 1.58 - 1.59
  82. (FD6)204120, (FD6)206826, // 1.60 - 1.61
  83. (FD6)209515, (FD6)212188, // 1.62 - 1.63
  84. (FD6)214844, (FD6)217484, // 1.64 - 1.65
  85. (FD6)220108, (FD6)222716, // 1.66 - 1.67
  86. (FD6)225309, (FD6)227887, // 1.68 - 1.69
  87. (FD6)230449, (FD6)232996, // 1.70 - 1.71
  88. (FD6)235528, (FD6)238046, // 1.72 - 1.73
  89. (FD6)240549, (FD6)243038, // 1.74 - 1.75
  90. (FD6)245513, (FD6)247973, // 1.76 - 1.77
  91. (FD6)250420, (FD6)252853, // 1.78 - 1.79
  92. (FD6)255273, (FD6)257679, // 1.80 - 1.81
  93. (FD6)260071, (FD6)262451, // 1.82 - 1.83
  94. (FD6)264818, (FD6)267172, // 1.84 - 1.85
  95. (FD6)269513, (FD6)271842, // 1.86 - 1.87
  96. (FD6)274158, (FD6)276462, // 1.88 - 1.89
  97. (FD6)278754, (FD6)281033, // 1.90 - 1.91
  98. (FD6)283301, (FD6)285557, // 1.92 - 1.93
  99. (FD6)287802, (FD6)290035, // 1.94 - 1.95
  100. (FD6)292256, (FD6)294466, // 1.96 - 1.97
  101. (FD6)296665, (FD6)298853, // 1.98 - 1.99
  102. (FD6)301030, (FD6)303196, // 2.00 - 2.01
  103. (FD6)305351, (FD6)307496, // 2.02 - 2.03
  104. (FD6)309630, (FD6)311754, // 2.04 - 2.05
  105. (FD6)313867, (FD6)315970, // 2.06 - 2.07
  106. (FD6)318063, (FD6)320146, // 2.08 - 2.09
  107. (FD6)322219, (FD6)324282, // 2.10 - 2.11
  108. (FD6)326336, (FD6)328380, // 2.12 - 2.13
  109. (FD6)330414, (FD6)332438, // 2.14 - 2.15
  110. (FD6)334454, (FD6)336460, // 2.16 - 2.17
  111. (FD6)338456, (FD6)340444, // 2.18 - 2.19
  112. (FD6)342423, (FD6)344392, // 2.20 - 2.21
  113. (FD6)346353, (FD6)348305, // 2.22 - 2.23
  114. (FD6)350248, (FD6)352183, // 2.24 - 2.25
  115. (FD6)354108, (FD6)356026, // 2.26 - 2.27
  116. (FD6)357935, (FD6)359835, // 2.28 - 2.29
  117. (FD6)361728, (FD6)363612, // 2.30 - 2.31
  118. (FD6)365488, (FD6)367356, // 2.32 - 2.33
  119. (FD6)369216, (FD6)371068, // 2.34 - 2.35
  120. (FD6)372912, (FD6)374748, // 2.36 - 2.37
  121. (FD6)376577, (FD6)378398, // 2.38 - 2.39
  122. (FD6)380211, (FD6)382017, // 2.40 - 2.41
  123. (FD6)383815, (FD6)385606, // 2.42 - 2.43
  124. (FD6)387390, (FD6)389166, // 2.44 - 2.45
  125. (FD6)390935, (FD6)392697, // 2.46 - 2.47
  126. (FD6)394452, (FD6)396199, // 2.48 - 2.49
  127. (FD6)397940, (FD6)399674, // 2.50 - 2.51
  128. (FD6)401401, (FD6)403121, // 2.52 - 2.53
  129. (FD6)404834, (FD6)406540, // 2.54 - 2.55
  130. (FD6)408240, (FD6)409933, // 2.56 - 2.57
  131. (FD6)411620, (FD6)413300, // 2.58 - 2.59
  132. (FD6)414973, (FD6)416641, // 2.60 - 2.61
  133. (FD6)418301, (FD6)419956, // 2.62 - 2.63
  134. (FD6)421604, (FD6)423246, // 2.64 - 2.65
  135. (FD6)424882, (FD6)426511, // 2.66 - 2.67
  136. (FD6)428135, (FD6)429752, // 2.68 - 2.69
  137. (FD6)431364, (FD6)432969, // 2.70 - 2.71
  138. (FD6)434569, (FD6)436163, // 2.72 - 2.73
  139. (FD6)437751, (FD6)439333, // 2.74 - 2.75
  140. (FD6)440909, (FD6)442480, // 2.76 - 2.77
  141. (FD6)444045, (FD6)445604, // 2.78 - 2.79
  142. (FD6)447158, (FD6)448706, // 2.80 - 2.81
  143. (FD6)450249, (FD6)451786, // 2.82 - 2.83
  144. (FD6)453318, (FD6)454845, // 2.84 - 2.85
  145. (FD6)456366, (FD6)457882, // 2.86 - 2.87
  146. (FD6)459392, (FD6)460898, // 2.88 - 2.89
  147. (FD6)462398, (FD6)463893, // 2.90 - 2.91
  148. (FD6)465383, (FD6)466868, // 2.92 - 2.93
  149. (FD6)468347, (FD6)469822, // 2.94 - 2.95
  150. (FD6)471292, (FD6)472756, // 2.96 - 2.97
  151. (FD6)474216, (FD6)475671, // 2.98 - 2.99
  152. (FD6)477121, (FD6)478566, // 3.00 - 3.01
  153. (FD6)480007, (FD6)481443, // 3.02 - 3.03
  154. (FD6)482874, (FD6)484300, // 3.04 - 3.05
  155. (FD6)485721, (FD6)487138, // 3.06 - 3.07
  156. (FD6)488551, (FD6)489958, // 3.08 - 3.09
  157. (FD6)491362, (FD6)492760, // 3.10 - 3.11
  158. (FD6)494155, (FD6)495544, // 3.12 - 3.13
  159. (FD6)496930, (FD6)498311, // 3.14 - 3.15
  160. (FD6)499687, (FD6)501059, // 3.16 - 3.17
  161. (FD6)502427, (FD6)503791, // 3.18 - 3.19
  162. (FD6)505150, (FD6)506505, // 3.20 - 3.21
  163. (FD6)507856, (FD6)509203, // 3.22 - 3.23
  164. (FD6)510545, (FD6)511883, // 3.24 - 3.25
  165. (FD6)513218, (FD6)514548, // 3.26 - 3.27
  166. (FD6)515874, (FD6)517196, // 3.28 - 3.29
  167. (FD6)518514, (FD6)519828, // 3.30 - 3.31
  168. (FD6)521138, (FD6)522444, // 3.32 - 3.33
  169. (FD6)523746, (FD6)525045, // 3.34 - 3.35
  170. (FD6)526339, (FD6)527630, // 3.36 - 3.37
  171. (FD6)528917, (FD6)530200, // 3.38 - 3.39
  172. (FD6)531479, (FD6)532754, // 3.40 - 3.41
  173. (FD6)534026, (FD6)535294, // 3.42 - 3.43
  174. (FD6)536558, (FD6)537819, // 3.44 - 3.45
  175. (FD6)539076, (FD6)540329, // 3.46 - 3.47
  176. (FD6)541579, (FD6)542825, // 3.48 - 3.49
  177. (FD6)544068, (FD6)545307, // 3.50 - 3.51
  178. (FD6)546543, (FD6)547775, // 3.52 - 3.53
  179. (FD6)549003, (FD6)550228, // 3.54 - 3.55
  180. (FD6)551450, (FD6)552668, // 3.56 - 3.57
  181. (FD6)553883, (FD6)555094, // 3.58 - 3.59
  182. (FD6)556303, (FD6)557507, // 3.60 - 3.61
  183. (FD6)558709, (FD6)559907, // 3.62 - 3.63
  184. (FD6)561101, (FD6)562293, // 3.64 - 3.65
  185. (FD6)563481, (FD6)564666, // 3.66 - 3.67
  186. (FD6)565848, (FD6)567026, // 3.68 - 3.69
  187. (FD6)568202, (FD6)569374, // 3.70 - 3.71
  188. (FD6)570543, (FD6)571709, // 3.72 - 3.73
  189. (FD6)572872, (FD6)574031, // 3.74 - 3.75
  190. (FD6)575188, (FD6)576341, // 3.76 - 3.77
  191. (FD6)577492, (FD6)578639, // 3.78 - 3.79
  192. (FD6)579784, (FD6)580925, // 3.80 - 3.81
  193. (FD6)582063, (FD6)583199, // 3.82 - 3.83
  194. (FD6)584331, (FD6)585461, // 3.84 - 3.85
  195. (FD6)586587, (FD6)587711, // 3.86 - 3.87
  196. (FD6)588832, (FD6)589950, // 3.88 - 3.89
  197. (FD6)591065, (FD6)592177, // 3.90 - 3.91
  198. (FD6)593286, (FD6)594393, // 3.92 - 3.93
  199. (FD6)595496, (FD6)596597, // 3.94 - 3.95
  200. (FD6)597695, (FD6)598791, // 3.96 - 3.97
  201. (FD6)599883, (FD6)600973, // 3.98 - 3.99
  202. (FD6)602060, (FD6)603144, // 4.00 - 4.01
  203. (FD6)604226, (FD6)605305, // 4.02 - 4.03
  204. (FD6)606381, (FD6)607455, // 4.04 - 4.05
  205. (FD6)608526, (FD6)609594, // 4.06 - 4.07
  206. (FD6)610660, (FD6)611723, // 4.08 - 4.09
  207. (FD6)612784, (FD6)613842, // 4.10 - 4.11
  208. (FD6)614897, (FD6)615950, // 4.12 - 4.13
  209. (FD6)617000, (FD6)618048, // 4.14 - 4.15
  210. (FD6)619093, (FD6)620136, // 4.16 - 4.17
  211. (FD6)621176, (FD6)622214, // 4.18 - 4.19
  212. (FD6)623249, (FD6)624282, // 4.20 - 4.21
  213. (FD6)625312, (FD6)626340, // 4.22 - 4.23
  214. (FD6)627366, (FD6)628389, // 4.24 - 4.25
  215. (FD6)629410, (FD6)630428, // 4.26 - 4.27
  216. (FD6)631444, (FD6)632457, // 4.28 - 4.29
  217. (FD6)633468, (FD6)634477, // 4.30 - 4.31
  218. (FD6)635484, (FD6)636488, // 4.32 - 4.33
  219. (FD6)637490, (FD6)638489, // 4.34 - 4.35
  220. (FD6)639486, (FD6)640481, // 4.36 - 4.37
  221. (FD6)641474, (FD6)642465, // 4.38 - 4.39
  222. (FD6)643453, (FD6)644439, // 4.40 - 4.41
  223. (FD6)645422, (FD6)646404, // 4.42 - 4.43
  224. (FD6)647383, (FD6)648360, // 4.44 - 4.45
  225. (FD6)649335, (FD6)650308, // 4.46 - 4.47
  226. (FD6)651278, (FD6)652246, // 4.48 - 4.49
  227. (FD6)653213, (FD6)654177, // 4.50 - 4.51
  228. (FD6)655138, (FD6)656098, // 4.52 - 4.53
  229. (FD6)657056, (FD6)658011, // 4.54 - 4.55
  230. (FD6)658965, (FD6)659916, // 4.56 - 4.57
  231. (FD6)660865, (FD6)661813, // 4.58 - 4.59
  232. (FD6)662758, (FD6)663701, // 4.60 - 4.61
  233. (FD6)664642, (FD6)665581, // 4.62 - 4.63
  234. (FD6)666518, (FD6)667453, // 4.64 - 4.65
  235. (FD6)668386, (FD6)669317, // 4.66 - 4.67
  236. (FD6)670246, (FD6)671173, // 4.68 - 4.69
  237. (FD6)672098, (FD6)673021, // 4.70 - 4.71
  238. (FD6)673942, (FD6)674861, // 4.72 - 4.73
  239. (FD6)675778, (FD6)676694, // 4.74 - 4.75
  240. (FD6)677607, (FD6)678518, // 4.76 - 4.77
  241. (FD6)679428, (FD6)680336, // 4.78 - 4.79
  242. (FD6)681241, (FD6)682145, // 4.80 - 4.81
  243. (FD6)683047, (FD6)683947, // 4.82 - 4.83
  244. (FD6)684845, (FD6)685742, // 4.84 - 4.85
  245. (FD6)686636, (FD6)687529, // 4.86 - 4.87
  246. (FD6)688420, (FD6)689309, // 4.88 - 4.89
  247. (FD6)690196, (FD6)691081, // 4.90 - 4.91
  248. (FD6)691965, (FD6)692847, // 4.92 - 4.93
  249. (FD6)693727, (FD6)694605, // 4.94 - 4.95
  250. (FD6)695482, (FD6)696356, // 4.96 - 4.97
  251. (FD6)697229, (FD6)698101, // 4.98 - 4.99
  252. (FD6)698970, (FD6)699838, // 5.00 - 5.01
  253. (FD6)700704, (FD6)701568, // 5.02 - 5.03
  254. (FD6)702431, (FD6)703291, // 5.04 - 5.05
  255. (FD6)704151, (FD6)705008, // 5.06 - 5.07
  256. (FD6)705864, (FD6)706718, // 5.08 - 5.09
  257. (FD6)707570, (FD6)708421, // 5.10 - 5.11
  258. (FD6)709270, (FD6)710117, // 5.12 - 5.13
  259. (FD6)710963, (FD6)711807, // 5.14 - 5.15
  260. (FD6)712650, (FD6)713491, // 5.16 - 5.17
  261. (FD6)714330, (FD6)715167, // 5.18 - 5.19
  262. (FD6)716003, (FD6)716838, // 5.20 - 5.21
  263. (FD6)717671, (FD6)718502, // 5.22 - 5.23
  264. (FD6)719331, (FD6)720159, // 5.24 - 5.25
  265. (FD6)720986, (FD6)721811, // 5.26 - 5.27
  266. (FD6)722634, (FD6)723456, // 5.28 - 5.29
  267. (FD6)724276, (FD6)725095, // 5.30 - 5.31
  268. (FD6)725912, (FD6)726727, // 5.32 - 5.33
  269. (FD6)727541, (FD6)728354, // 5.34 - 5.35
  270. (FD6)729165, (FD6)729974, // 5.36 - 5.37
  271. (FD6)730782, (FD6)731589, // 5.38 - 5.39
  272. (FD6)732394, (FD6)733197, // 5.40 - 5.41
  273. (FD6)733999, (FD6)734800, // 5.42 - 5.43
  274. (FD6)735599, (FD6)736397, // 5.44 - 5.45
  275. (FD6)737193, (FD6)737987, // 5.46 - 5.47
  276. (FD6)738781, (FD6)739572, // 5.48 - 5.49
  277. (FD6)740363, (FD6)741152, // 5.50 - 5.51
  278. (FD6)741939, (FD6)742725, // 5.52 - 5.53
  279. (FD6)743510, (FD6)744293, // 5.54 - 5.55
  280. (FD6)745075, (FD6)745855, // 5.56 - 5.57
  281. (FD6)746634, (FD6)747412, // 5.58 - 5.59
  282. (FD6)748188, (FD6)748963, // 5.60 - 5.61
  283. (FD6)749736, (FD6)750508, // 5.62 - 5.63
  284. (FD6)751279, (FD6)752048, // 5.64 - 5.65
  285. (FD6)752816, (FD6)753583, // 5.66 - 5.67
  286. (FD6)754348, (FD6)755112, // 5.68 - 5.69
  287. (FD6)755875, (FD6)756636, // 5.70 - 5.71
  288. (FD6)757396, (FD6)758155, // 5.72 - 5.73
  289. (FD6)758912, (FD6)759668, // 5.74 - 5.75
  290. (FD6)760422, (FD6)761176, // 5.76 - 5.77
  291. (FD6)761928, (FD6)762679, // 5.78 - 5.79
  292. (FD6)763428, (FD6)764176, // 5.80 - 5.81
  293. (FD6)764923, (FD6)765669, // 5.82 - 5.83
  294. (FD6)766413, (FD6)767156, // 5.84 - 5.85
  295. (FD6)767898, (FD6)768638, // 5.86 - 5.87
  296. (FD6)769377, (FD6)770115, // 5.88 - 5.89
  297. (FD6)770852, (FD6)771587, // 5.90 - 5.91
  298. (FD6)772322, (FD6)773055, // 5.92 - 5.93
  299. (FD6)773786, (FD6)774517, // 5.94 - 5.95
  300. (FD6)775246, (FD6)775974, // 5.96 - 5.97
  301. (FD6)776701, (FD6)777427, // 5.98 - 5.99
  302. (FD6)778151, (FD6)778874, // 6.00 - 6.01
  303. (FD6)779596, (FD6)780317, // 6.02 - 6.03
  304. (FD6)781037, (FD6)781755, // 6.04 - 6.05
  305. (FD6)782473, (FD6)783189, // 6.06 - 6.07
  306. (FD6)783904, (FD6)784617, // 6.08 - 6.09
  307. (FD6)785330, (FD6)786041, // 6.10 - 6.11
  308. (FD6)786751, (FD6)787460, // 6.12 - 6.13
  309. (FD6)788168, (FD6)788875, // 6.14 - 6.15
  310. (FD6)789581, (FD6)790285, // 6.16 - 6.17
  311. (FD6)790988, (FD6)791691, // 6.18 - 6.19
  312. (FD6)792392, (FD6)793092, // 6.20 - 6.21
  313. (FD6)793790, (FD6)794488, // 6.22 - 6.23
  314. (FD6)795185, (FD6)795880, // 6.24 - 6.25
  315. (FD6)796574, (FD6)797268, // 6.26 - 6.27
  316. (FD6)797960, (FD6)798651, // 6.28 - 6.29
  317. (FD6)799341, (FD6)800029, // 6.30 - 6.31
  318. (FD6)800717, (FD6)801404, // 6.32 - 6.33
  319. (FD6)802089, (FD6)802774, // 6.34 - 6.35
  320. (FD6)803457, (FD6)804139, // 6.36 - 6.37
  321. (FD6)804821, (FD6)805501, // 6.38 - 6.39
  322. (FD6)806180, (FD6)806858, // 6.40 - 6.41
  323. (FD6)807535, (FD6)808211, // 6.42 - 6.43
  324. (FD6)808886, (FD6)809560, // 6.44 - 6.45
  325. (FD6)810233, (FD6)810904, // 6.46 - 6.47
  326. (FD6)811575, (FD6)812245, // 6.48 - 6.49
  327. (FD6)812913, (FD6)813581, // 6.50 - 6.51
  328. (FD6)814248, (FD6)814913, // 6.52 - 6.53
  329. (FD6)815578, (FD6)816241, // 6.54 - 6.55
  330. (FD6)816904, (FD6)817565, // 6.56 - 6.57
  331. (FD6)818226, (FD6)818885, // 6.58 - 6.59
  332. (FD6)819544, (FD6)820201, // 6.60 - 6.61
  333. (FD6)820858, (FD6)821514, // 6.62 - 6.63
  334. (FD6)822168, (FD6)822822, // 6.64 - 6.65
  335. (FD6)823474, (FD6)824126, // 6.66 - 6.67
  336. (FD6)824776, (FD6)825426, // 6.68 - 6.69
  337. (FD6)826075, (FD6)826723, // 6.70 - 6.71
  338. (FD6)827369, (FD6)828015, // 6.72 - 6.73
  339. (FD6)828660, (FD6)829304, // 6.74 - 6.75
  340. (FD6)829947, (FD6)830589, // 6.76 - 6.77
  341. (FD6)831230, (FD6)831870, // 6.78 - 6.79
  342. (FD6)832509, (FD6)833147, // 6.80 - 6.81
  343. (FD6)833784, (FD6)834421, // 6.82 - 6.83
  344. (FD6)835056, (FD6)835691, // 6.84 - 6.85
  345. (FD6)836324, (FD6)836957, // 6.86 - 6.87
  346. (FD6)837588, (FD6)838219, // 6.88 - 6.89
  347. (FD6)838849, (FD6)839478, // 6.90 - 6.91
  348. (FD6)840106, (FD6)840733, // 6.92 - 6.93
  349. (FD6)841359, (FD6)841985, // 6.94 - 6.95
  350. (FD6)842609, (FD6)843233, // 6.96 - 6.97
  351. (FD6)843855, (FD6)844477, // 6.98 - 6.99
  352. (FD6)845098, (FD6)845718, // 7.00 - 7.01
  353. (FD6)846337, (FD6)846955, // 7.02 - 7.03
  354. (FD6)847573, (FD6)848189, // 7.04 - 7.05
  355. (FD6)848805, (FD6)849419, // 7.06 - 7.07
  356. (FD6)850033, (FD6)850646, // 7.08 - 7.09
  357. (FD6)851258, (FD6)851870, // 7.10 - 7.11
  358. (FD6)852480, (FD6)853090, // 7.12 - 7.13
  359. (FD6)853698, (FD6)854306, // 7.14 - 7.15
  360. (FD6)854913, (FD6)855519, // 7.16 - 7.17
  361. (FD6)856124, (FD6)856729, // 7.18 - 7.19
  362. (FD6)857332, (FD6)857935, // 7.20 - 7.21
  363. (FD6)858537, (FD6)859138, // 7.22 - 7.23
  364. (FD6)859739, (FD6)860338, // 7.24 - 7.25
  365. (FD6)860937, (FD6)861534, // 7.26 - 7.27
  366. (FD6)862131, (FD6)862728, // 7.28 - 7.29
  367. (FD6)863323, (FD6)863917, // 7.30 - 7.31
  368. (FD6)864511, (FD6)865104, // 7.32 - 7.33
  369. (FD6)865696, (FD6)866287, // 7.34 - 7.35
  370. (FD6)866878, (FD6)867467, // 7.36 - 7.37
  371. (FD6)868056, (FD6)868644, // 7.38 - 7.39
  372. (FD6)869232, (FD6)869818, // 7.40 - 7.41
  373. (FD6)870404, (FD6)870989, // 7.42 - 7.43
  374. (FD6)871573, (FD6)872156, // 7.44 - 7.45
  375. (FD6)872739, (FD6)873321, // 7.46 - 7.47
  376. (FD6)873902, (FD6)874482, // 7.48 - 7.49
  377. (FD6)875061, (FD6)875640, // 7.50 - 7.51
  378. (FD6)876218, (FD6)876795, // 7.52 - 7.53
  379. (FD6)877371, (FD6)877947, // 7.54 - 7.55
  380. (FD6)878522, (FD6)879096, // 7.56 - 7.57
  381. (FD6)879669, (FD6)880242, // 7.58 - 7.59
  382. (FD6)880814, (FD6)881385, // 7.60 - 7.61
  383. (FD6)881955, (FD6)882525, // 7.62 - 7.63
  384. (FD6)883093, (FD6)883661, // 7.64 - 7.65
  385. (FD6)884229, (FD6)884795, // 7.66 - 7.67
  386. (FD6)885361, (FD6)885926, // 7.68 - 7.69
  387. (FD6)886491, (FD6)887054, // 7.70 - 7.71
  388. (FD6)887617, (FD6)888179, // 7.72 - 7.73
  389. (FD6)888741, (FD6)889302, // 7.74 - 7.75
  390. (FD6)889862, (FD6)890421, // 7.76 - 7.77
  391. (FD6)890980, (FD6)891537, // 7.78 - 7.79
  392. (FD6)892095, (FD6)892651, // 7.80 - 7.81
  393. (FD6)893207, (FD6)893762, // 7.82 - 7.83
  394. (FD6)894316, (FD6)894870, // 7.84 - 7.85
  395. (FD6)895423, (FD6)895975, // 7.86 - 7.87
  396. (FD6)896526, (FD6)897077, // 7.88 - 7.89
  397. (FD6)897627, (FD6)898176, // 7.90 - 7.91
  398. (FD6)898725, (FD6)899273, // 7.92 - 7.93
  399. (FD6)899821, (FD6)900367, // 7.94 - 7.95
  400. (FD6)900913, (FD6)901458, // 7.96 - 7.97
  401. (FD6)902003, (FD6)902547, // 7.98 - 7.99
  402. (FD6)903090, (FD6)903633, // 8.00 - 8.01
  403. (FD6)904174, (FD6)904716, // 8.02 - 8.03
  404. (FD6)905256, (FD6)905796, // 8.04 - 8.05
  405. (FD6)906335, (FD6)906874, // 8.06 - 8.07
  406. (FD6)907411, (FD6)907949, // 8.08 - 8.09
  407. (FD6)908485, (FD6)909021, // 8.10 - 8.11
  408. (FD6)909556, (FD6)910091, // 8.12 - 8.13
  409. (FD6)910624, (FD6)911158, // 8.14 - 8.15
  410. (FD6)911690, (FD6)912222, // 8.16 - 8.17
  411. (FD6)912753, (FD6)913284, // 8.18 - 8.19
  412. (FD6)913814, (FD6)914343, // 8.20 - 8.21
  413. (FD6)914872, (FD6)915400, // 8.22 - 8.23
  414. (FD6)915927, (FD6)916454, // 8.24 - 8.25
  415. (FD6)916980, (FD6)917506, // 8.26 - 8.27
  416. (FD6)918030, (FD6)918555, // 8.28 - 8.29
  417. (FD6)919078, (FD6)919601, // 8.30 - 8.31
  418. (FD6)920123, (FD6)920645, // 8.32 - 8.33
  419. (FD6)921166, (FD6)921686, // 8.34 - 8.35
  420. (FD6)922206, (FD6)922725, // 8.36 - 8.37
  421. (FD6)923244, (FD6)923762, // 8.38 - 8.39
  422. (FD6)924279, (FD6)924796, // 8.40 - 8.41
  423. (FD6)925312, (FD6)925828, // 8.42 - 8.43
  424. (FD6)926342, (FD6)926857, // 8.44 - 8.45
  425. (FD6)927370, (FD6)927883, // 8.46 - 8.47
  426. (FD6)928396, (FD6)928908, // 8.48 - 8.49
  427. (FD6)929419, (FD6)929930, // 8.50 - 8.51
  428. (FD6)930440, (FD6)930949, // 8.52 - 8.53
  429. (FD6)931458, (FD6)931966, // 8.54 - 8.55
  430. (FD6)932474, (FD6)932981, // 8.56 - 8.57
  431. (FD6)933487, (FD6)933993, // 8.58 - 8.59
  432. (FD6)934498, (FD6)935003, // 8.60 - 8.61
  433. (FD6)935507, (FD6)936011, // 8.62 - 8.63
  434. (FD6)936514, (FD6)937016, // 8.64 - 8.65
  435. (FD6)937518, (FD6)938019, // 8.66 - 8.67
  436. (FD6)938520, (FD6)939020, // 8.68 - 8.69
  437. (FD6)939519, (FD6)940018, // 8.70 - 8.71
  438. (FD6)940516, (FD6)941014, // 8.72 - 8.73
  439. (FD6)941511, (FD6)942008, // 8.74 - 8.75
  440. (FD6)942504, (FD6)943000, // 8.76 - 8.77
  441. (FD6)943495, (FD6)943989, // 8.78 - 8.79
  442. (FD6)944483, (FD6)944976, // 8.80 - 8.81
  443. (FD6)945469, (FD6)945961, // 8.82 - 8.83
  444. (FD6)946452, (FD6)946943, // 8.84 - 8.85
  445. (FD6)947434, (FD6)947924, // 8.86 - 8.87
  446. (FD6)948413, (FD6)948902, // 8.88 - 8.89
  447. (FD6)949390, (FD6)949878, // 8.90 - 8.91
  448. (FD6)950365, (FD6)950851, // 8.92 - 8.93
  449. (FD6)951338, (FD6)951823, // 8.94 - 8.95
  450. (FD6)952308, (FD6)952792, // 8.96 - 8.97
  451. (FD6)953276, (FD6)953760, // 8.98 - 8.99
  452. (FD6)954243, (FD6)954725, // 9.00 - 9.01
  453. (FD6)955207, (FD6)955688, // 9.02 - 9.03
  454. (FD6)956168, (FD6)956649, // 9.04 - 9.05
  455. (FD6)957128, (FD6)957607, // 9.06 - 9.07
  456. (FD6)958086, (FD6)958564, // 9.08 - 9.09
  457. (FD6)959041, (FD6)959518, // 9.10 - 9.11
  458. (FD6)959995, (FD6)960471, // 9.12 - 9.13
  459. (FD6)960946, (FD6)961421, // 9.14 - 9.15
  460. (FD6)961895, (FD6)962369, // 9.16 - 9.17
  461. (FD6)962843, (FD6)963316, // 9.18 - 9.19
  462. (FD6)963788, (FD6)964260, // 9.20 - 9.21
  463. (FD6)964731, (FD6)965202, // 9.22 - 9.23
  464. (FD6)965672, (FD6)966142, // 9.24 - 9.25
  465. (FD6)966611, (FD6)967080, // 9.26 - 9.27
  466. (FD6)967548, (FD6)968016, // 9.28 - 9.29
  467. (FD6)968483, (FD6)968950, // 9.30 - 9.31
  468. (FD6)969416, (FD6)969882, // 9.32 - 9.33
  469. (FD6)970347, (FD6)970812, // 9.34 - 9.35
  470. (FD6)971276, (FD6)971740, // 9.36 - 9.37
  471. (FD6)972203, (FD6)972666, // 9.38 - 9.39
  472. (FD6)973128, (FD6)973590, // 9.40 - 9.41
  473. (FD6)974051, (FD6)974512, // 9.42 - 9.43
  474. (FD6)974972, (FD6)975432, // 9.44 - 9.45
  475. (FD6)975891, (FD6)976350, // 9.46 - 9.47
  476. (FD6)976808, (FD6)977266, // 9.48 - 9.49
  477. (FD6)977724, (FD6)978181, // 9.50 - 9.51
  478. (FD6)978637, (FD6)979093, // 9.52 - 9.53
  479. (FD6)979548, (FD6)980003, // 9.54 - 9.55
  480. (FD6)980458, (FD6)980912, // 9.56 - 9.57
  481. (FD6)981366, (FD6)981819, // 9.58 - 9.59
  482. (FD6)982271, (FD6)982723, // 9.60 - 9.61
  483. (FD6)983175, (FD6)983626, // 9.62 - 9.63
  484. (FD6)984077, (FD6)984527, // 9.64 - 9.65
  485. (FD6)984977, (FD6)985426, // 9.66 - 9.67
  486. (FD6)985875, (FD6)986324, // 9.68 - 9.69
  487. (FD6)986772, (FD6)987219, // 9.70 - 9.71
  488. (FD6)987666, (FD6)988113, // 9.72 - 9.73
  489. (FD6)988559, (FD6)989005, // 9.74 - 9.75
  490. (FD6)989450, (FD6)989895, // 9.76 - 9.77
  491. (FD6)990339, (FD6)990783, // 9.78 - 9.79
  492. (FD6)991226, (FD6)991669, // 9.80 - 9.81
  493. (FD6)992111, (FD6)992554, // 9.82 - 9.83
  494. (FD6)992995, (FD6)993436, // 9.84 - 9.85
  495. (FD6)993877, (FD6)994317, // 9.86 - 9.87
  496. (FD6)994757, (FD6)995196, // 9.88 - 9.89
  497. (FD6)995635, (FD6)996074, // 9.90 - 9.91
  498. (FD6)996512, (FD6)996949, // 9.92 - 9.93
  499. (FD6)997386, (FD6)997823, // 9.94 - 9.95
  500. (FD6)998259, (FD6)998695, // 9.96 - 9.97
  501. (FD6)999131, (FD6)999565, // 9.98 - 9.99
  502. FD6_1 // 10.00
  503. };
  504. WORD MantSearchTable[101] = {
  505. 0, // 0: 0.000000 - 0.012837, EndIndex = 3 ( 4)
  506. 2, // 1: 0.008600 - 0.021189, EndIndex = 5 ( 4)
  507. 4, // 2: 0.017033 - 0.033424, EndIndex = 8 ( 5)
  508. 7, // 3: 0.029384 - 0.041393, EndIndex = 10 ( 4)
  509. 9, // 4: 0.037426 - 0.053078, EndIndex = 13 ( 5)
  510. 12, // 5: 0.049218 - 0.060698, EndIndex = 15 ( 4)
  511. 14, // 6: 0.056905 - 0.071882, EndIndex = 18 ( 5)
  512. 17, // 7: 0.068186 - 0.082785, EndIndex = 21 ( 5)
  513. 20, // 8: 0.079181 - 0.093422, EndIndex = 24 ( 5)
  514. 23, // 9: 0.089905 - 0.100371, EndIndex = 26 ( 4)
  515. 25, // 10: 0.096910 - 0.110590, EndIndex = 29 ( 5)
  516. 28, // 11: 0.107210 - 0.120574, EndIndex = 32 ( 5)
  517. 31, // 12: 0.117271 - 0.130334, EndIndex = 35 ( 5)
  518. 34, // 13: 0.127105 - 0.143015, EndIndex = 39 ( 6)
  519. 38, // 14: 0.139879 - 0.152288, EndIndex = 42 ( 5)
  520. 41, // 15: 0.149219 - 0.161368, EndIndex = 45 ( 5)
  521. 44, // 16: 0.158362 - 0.170262, EndIndex = 48 ( 5)
  522. 47, // 17: 0.167317 - 0.181844, EndIndex = 52 ( 6)
  523. 51, // 18: 0.178977 - 0.190332, EndIndex = 55 ( 5)
  524. 54, // 19: 0.187521 - 0.201397, EndIndex = 59 ( 6)
  525. 58, // 20: 0.198657 - 0.212188, EndIndex = 63 ( 6)
  526. 62, // 21: 0.209515 - 0.220108, EndIndex = 66 ( 5)
  527. 65, // 22: 0.217484 - 0.230449, EndIndex = 70 ( 6)
  528. 69, // 23: 0.227887 - 0.240549, EndIndex = 74 ( 6)
  529. 73, // 24: 0.238046 - 0.250420, EndIndex = 78 ( 6)
  530. 77, // 25: 0.247973 - 0.260071, EndIndex = 82 ( 6)
  531. 81, // 26: 0.257679 - 0.271842, EndIndex = 87 ( 7)
  532. 86, // 27: 0.269513 - 0.281033, EndIndex = 91 ( 6)
  533. 90, // 28: 0.278754 - 0.290035, EndIndex = 95 ( 6)
  534. 94, // 29: 0.287802 - 0.301030, EndIndex = 100 ( 7)
  535. 99, // 30: 0.298853 - 0.311754, EndIndex = 105 ( 7)
  536. 104, // 31: 0.309630 - 0.320146, EndIndex = 109 ( 6)
  537. 108, // 32: 0.318063 - 0.330414, EndIndex = 114 ( 7)
  538. 113, // 33: 0.328380 - 0.340444, EndIndex = 119 ( 7)
  539. 118, // 34: 0.338456 - 0.350248, EndIndex = 124 ( 7)
  540. 123, // 35: 0.348305 - 0.361728, EndIndex = 130 ( 8)
  541. 129, // 36: 0.359835 - 0.371068, EndIndex = 135 ( 7)
  542. 134, // 37: 0.369216 - 0.380211, EndIndex = 140 ( 7)
  543. 139, // 38: 0.378398 - 0.390935, EndIndex = 146 ( 8)
  544. 145, // 39: 0.389166 - 0.401401, EndIndex = 152 ( 8)
  545. 151, // 40: 0.399674 - 0.411620, EndIndex = 158 ( 8)
  546. 157, // 41: 0.409933 - 0.421604, EndIndex = 164 ( 8)
  547. 163, // 42: 0.419956 - 0.431364, EndIndex = 170 ( 8)
  548. 169, // 43: 0.429752 - 0.440909, EndIndex = 176 ( 8)
  549. 175, // 44: 0.439333 - 0.450249, EndIndex = 182 ( 8)
  550. 181, // 45: 0.448706 - 0.460898, EndIndex = 189 ( 9)
  551. 188, // 46: 0.459392 - 0.471292, EndIndex = 196 ( 9)
  552. 195, // 47: 0.469822 - 0.480007, EndIndex = 202 ( 8)
  553. 201, // 48: 0.478566 - 0.491362, EndIndex = 210 (10)
  554. 209, // 49: 0.489958 - 0.501059, EndIndex = 217 ( 9)
  555. 216, // 50: 0.499687 - 0.510545, EndIndex = 224 ( 9)
  556. 223, // 51: 0.509203 - 0.521138, EndIndex = 232 (10)
  557. 231, // 52: 0.519828 - 0.530200, EndIndex = 239 ( 9)
  558. 238, // 53: 0.528917 - 0.540329, EndIndex = 247 (10)
  559. 246, // 54: 0.539076 - 0.550228, EndIndex = 255 (10)
  560. 254, // 55: 0.549003 - 0.561101, EndIndex = 264 (11)
  561. 263, // 56: 0.559907 - 0.570543, EndIndex = 272 (10)
  562. 271, // 57: 0.569374 - 0.580925, EndIndex = 281 (11)
  563. 280, // 58: 0.579784 - 0.591065, EndIndex = 290 (11)
  564. 289, // 59: 0.589950 - 0.600973, EndIndex = 299 (11)
  565. 298, // 60: 0.599883 - 0.610660, EndIndex = 308 (11)
  566. 307, // 61: 0.609594 - 0.620136, EndIndex = 317 (11)
  567. 316, // 62: 0.619093 - 0.630428, EndIndex = 327 (12)
  568. 326, // 63: 0.629410 - 0.640481, EndIndex = 337 (12)
  569. 336, // 64: 0.639486 - 0.650308, EndIndex = 347 (12)
  570. 346, // 65: 0.649335 - 0.660865, EndIndex = 358 (13)
  571. 357, // 66: 0.659916 - 0.670246, EndIndex = 368 (12)
  572. 367, // 67: 0.669317 - 0.680336, EndIndex = 379 (13)
  573. 378, // 68: 0.679428 - 0.690196, EndIndex = 390 (13)
  574. 389, // 69: 0.689309 - 0.700704, EndIndex = 402 (14)
  575. 401, // 70: 0.699838 - 0.710117, EndIndex = 413 (13)
  576. 412, // 71: 0.709270 - 0.720159, EndIndex = 425 (14)
  577. 424, // 72: 0.719331 - 0.730782, EndIndex = 438 (15)
  578. 437, // 73: 0.729974 - 0.740363, EndIndex = 450 (14)
  579. 449, // 74: 0.739572 - 0.750508, EndIndex = 463 (15)
  580. 462, // 75: 0.749736 - 0.760422, EndIndex = 476 (15)
  581. 475, // 76: 0.759668 - 0.770115, EndIndex = 489 (15)
  582. 488, // 77: 0.769377 - 0.780317, EndIndex = 503 (16)
  583. 502, // 78: 0.779596 - 0.790285, EndIndex = 517 (16)
  584. 516, // 79: 0.789581 - 0.800029, EndIndex = 531 (16)
  585. 530, // 80: 0.799341 - 0.810233, EndIndex = 546 (17)
  586. 545, // 81: 0.809560 - 0.820201, EndIndex = 561 (17)
  587. 560, // 82: 0.819544 - 0.830589, EndIndex = 577 (18)
  588. 576, // 83: 0.829947 - 0.840106, EndIndex = 592 (17)
  589. 591, // 84: 0.839478 - 0.850033, EndIndex = 608 (18)
  590. 607, // 85: 0.849419 - 0.860338, EndIndex = 625 (19)
  591. 624, // 86: 0.859739 - 0.870404, EndIndex = 642 (19)
  592. 641, // 87: 0.869818 - 0.880242, EndIndex = 659 (19)
  593. 658, // 88: 0.879669 - 0.890421, EndIndex = 677 (20)
  594. 676, // 89: 0.889862 - 0.900367, EndIndex = 695 (20)
  595. 694, // 90: 0.899821 - 0.910091, EndIndex = 713 (20)
  596. 712, // 91: 0.909556 - 0.920123, EndIndex = 732 (21)
  597. 731, // 92: 0.919601 - 0.930440, EndIndex = 752 (22)
  598. 751, // 93: 0.929930 - 0.940018, EndIndex = 771 (21)
  599. 770, // 94: 0.939519 - 0.950365, EndIndex = 792 (23)
  600. 791, // 95: 0.949878 - 0.960471, EndIndex = 813 (23)
  601. 812, // 96: 0.959995 - 0.970347, EndIndex = 834 (23)
  602. 833, // 97: 0.969882 - 0.980003, EndIndex = 855 (23)
  603. 854, // 98: 0.979548 - 0.990339, EndIndex = 878 (25)
  604. 877, // 99: 0.989895 - 1.000000, EndIndex = 900 (24)
  605. 899 // Last MantissaTable[] Index Number - 1
  606. };
  607. //
  608. // Mantissa Correction Data Bits Usage:
  609. //
  610. //
  611. // <---High Word---> <----Low Word--->
  612. // Bit# 3 2 1 0
  613. // 10987654 32109876 54321098 76543210
  614. // | | | | | | | || | |
  615. // | | | | | | | || | +-- x.000 Minimum Difference
  616. // | | | | | | | || +----- x.001-x.002 (0-7) Correct 1
  617. // | | | | | | | |+-------- x.000-x.001 (0-7) Correct 2
  618. // | | | | | | | +--------- x.009-y.000 (0-1) Correct 10
  619. // | | | | | | +------------- x.009-y.000 (0-7) Correct 3
  620. // | | | | | +---------------- x.008-x.009 (0-7) Correct 4
  621. // | | | | +------------------ x.007-x.008 (0-3) Correct 5
  622. // | | | +--------------------- x.006-x.007 (0-3) Correct 6
  623. // | | +----------------------- x.005-x.006 (0-3) Correct 7
  624. // | +------------------------- x.004-x.005 (0-3) Correct 8
  625. // +--------------------------- x.003-x.004 (0-3) Correct 9
  626. //
  627. DWORD MantissaCorrectData[MANTISSATABLE_SIZE] = {
  628. 0x269b49ae, 0x169a49aa, 0x159339a6, 0x9ba34ba1, 0x0692399e, // 1.00-1.04
  629. 0x165a399a, 0x559a4796, 0x1a93c792, 0x5adb398e, 0x4692398b, // 1.05-1.09
  630. 0x5a934787, 0x15923784, 0x59d33980, 0x5593297d, 0x1252277a, // 1.10-1.14
  631. 0x269bb776, 0x56933773, 0x55923770, 0x4653276d, 0x1592276a, // 1.15-1.19
  632. 0x158b2767, 0x46523764, 0x49922761, 0x1992b75e, 0x2692b75b, // 1.20-1.24
  633. 0x11522559, 0x45922556, 0x56922753, 0x054a2551, 0x158a354e, // 1.25-1.29
  634. 0x599a374b, 0x458a2749, 0x014a1547, 0x55522544, 0x05492542, // 1.30-1.34
  635. 0x1652b53f, 0x058aa53d, 0x044a233b, 0x00491539, 0x55522536, // 1.35-1.39
  636. 0x154a2534, 0x05492532, 0x01492530, 0x5992272d, 0x1992a72b, // 1.40-1.44
  637. 0x198ab529, 0x55922527, 0x00411526, 0x56522523, 0x56522721, // 1.45-1.49
  638. 0x01091520, 0x0449231e, 0x0149231c, 0x4549251a, 0x154a9518, // 1.50-1.54
  639. 0x4651a516, 0x01091315, 0x04492313, 0x454a1511, 0x158aa50f, // 1.55-1.59
  640. 0x0141230e, 0x1451150c, 0x464aa50a, 0x04491309, 0x454a1507, // 1.60-1.64
  641. 0x1952a505, 0x05491504, 0x558a2502, 0x41491501, 0x158a94ff, // 1.65-1.69
  642. 0x050922fe, 0x555124fc, 0x114914fb, 0x564a24f9, 0x454914f8, // 1.70-1.74
  643. 0x010912f7, 0x455122f5, 0x110914f4, 0x1951a4f2, 0x154994f1, // 1.75-1.79
  644. 0x410912f0, 0x558a22ee, 0x454a14ed, 0x114912ec, 0x010812eb, // 1.80-1.84
  645. 0x1551a2e9, 0x1149a2e8, 0x110912e7, 0x010812e6, 0x000102e5, // 1.85-1.89
  646. 0x454922e3, 0x114914e2, 0x044912e1, 0x044112e0, 0x004102df, // 1.90-1.94
  647. 0x1551a2dd, 0x518914dc, 0x454914db, 0x444922da, 0x414912d9, // 1.95-1.99
  648. 0x110912d8, 0x014112d7, 0x040912d6, 0x010812d5, 0x010812d4, // 2.00-2.04
  649. 0x004102d3, 0x2551a4d1, 0x2551a4d0, 0x000812d0, 0x000812cf, // 2.05-2.09
  650. 0x595124cd, 0x010812cd, 0x100902cc, 0x044110cb, 0x010902ca, // 2.10-2.14
  651. 0x410912c9, 0x444112c8, 0x110912c7, 0x450914c6, 0x1449a2c5, // 2.15-2.19
  652. 0x515112c4, 0x155194c3, 0x000802c3, 0x004102c2, 0x010892c1, // 2.20-2.24
  653. 0x044910c0, 0x054194bf, 0x154992be, 0x554922bd, 0x004012bd, // 2.25-2.29
  654. 0x044102bc, 0x414112bb, 0x114992ba, 0x1549a2b9, 0x000810b9, // 2.30-2.34
  655. 0x044102b8, 0x114112b7, 0x144994b6, 0x000010b6, 0x004102b5, // 2.35-2.39
  656. 0x414112b4, 0x454912b3, 0x555114b2, 0x040812b2, 0x444812b1, // 2.40-2.44
  657. 0x550a12b0, 0x000802b0, 0x410902af, 0x450912ae, 0x458994ad, // 2.45-2.49
  658. 0x104102ad, 0x114892ac, 0x000000ac, 0x100810ab, 0x444812aa, // 2.50-2.54
  659. 0x1549a2a9, 0x010102a9, 0x110992a8, 0x515192a7, 0x010110a7, // 2.55-2.59
  660. 0x144992a6, 0x155192a5, 0x410812a5, 0x144992a4, 0x004010a4, // 2.60-2.64
  661. 0x044892a3, 0x554912a2, 0x104102a2, 0x450912a1, 0x000802a1, // 2.65-2.69
  662. 0x110902a0, 0x4549949f, 0x4041029f, 0x4509929e, 0x0101009e, // 2.70-2.74
  663. 0x4449029d, 0x0000109d, 0x4441029c, 0x5549129b, 0x1041029b, // 2.75-2.79
  664. 0x5149129a, 0x0101029a, 0x45091299, 0x00010299, 0x11099298, // 2.80-2.84
  665. 0x00001098, 0x44481297, 0x554a1296, 0x44411296, 0x51519295, // 2.85-2.89
  666. 0x41090295, 0x51519294, 0x04418294, 0x55491293, 0x41081293, // 2.90-2.94
  667. 0x00000093, 0x04411092, 0x55491491, 0x11081291, 0x1549a290, // 2.95-2.99
  668. 0x11081290, 0x00000290, 0x1109828f, 0x0008008f, 0x1109908e, // 3.00-3.04
  669. 0x0000108e, 0x4509128d, 0x1001028d, 0x4541128c, 0x4041028c, // 3.05-3.09
  670. 0x5449128b, 0x0408928b, 0x5549128a, 0x0448928a, 0x0008008a, // 3.10-3.14
  671. 0x45091089, 0x00401089, 0x54491288, 0x41010288, 0x45499287, // 3.15-3.19
  672. 0x41090287, 0x00001087, 0x14489286, 0x01010086, 0x51491285, // 3.20-3.24
  673. 0x04089285, 0x00000085, 0x11098284, 0x01001084, 0x15099283, // 3.25-3.29
  674. 0x11010283, 0x51519282, 0x44481282, 0x00080282, 0x45499281, // 3.30-3.34
  675. 0x10411081, 0x00000281, 0x14489280, 0x40401080, 0x4549927f, // 3.35-3.39
  676. 0x1109027f, 0x0008027f, 0x1449927e, 0x0441027e, 0x0000027e, // 3.40-3.44
  677. 0x5141127d, 0x0108027d, 0x1549947c, 0x4448127c, 0x0401027c, // 3.45-3.49
  678. 0x1549927b, 0x1108927b, 0x1001007b, 0x5509127a, 0x1108127a, // 3.50-3.54
  679. 0x0040027a, 0x54491279, 0x41090279, 0x00001079, 0x51499278, // 3.55-3.59
  680. 0x11081078, 0x04001078, 0x45498277, 0x11081077, 0x00400277, // 3.60-3.64
  681. 0x15099276, 0x44410276, 0x01001076, 0x55091275, 0x11089275, // 3.65-3.69
  682. 0x04010075, 0x45499274, 0x11098274, 0x00409074, 0x15499273, // 3.70-3.74
  683. 0x11419273, 0x04081073, 0x00000273, 0x51481272, 0x04418272, // 3.75-3.79
  684. 0x00080072, 0x54491271, 0x11089271, 0x01001071, 0x00000071, // 3.80-3.84
  685. 0x45090270, 0x41010270, 0x00080070, 0x4548926f, 0x1108906f, // 3.85-3.89
  686. 0x1001006f, 0x4549926e, 0x4448926e, 0x1040106e, 0x0000106e, // 3.90-3.94
  687. 0x5509126d, 0x1109826d, 0x0401006d, 0x0000006d, 0x1448926c, // 3.95-3.99
  688. 0x1041026c, 0x0040026c, 0x4549926b, 0x4448126b, 0x1041026b, // 4.00-4.04
  689. 0x0001006b, 0x5449126a, 0x4448126a, 0x0408026a, 0x0000106a, // 4.05-4.09
  690. 0x45419269, 0x44411069, 0x10080269, 0x45899268, 0x14499268, // 4.10-4.14
  691. 0x41410268, 0x04080268, 0x00000068, 0x15099267, 0x44410267, // 4.15-4.19
  692. 0x04080267, 0x55511266, 0x54491266, 0x11089266, 0x10401066, // 4.20-4.24
  693. 0x00400066, 0x45498265, 0x11098265, 0x10401065, 0x00000265, // 4.25-4.29
  694. 0x15499264, 0x14489264, 0x41081064, 0x10010064, 0x15499263, // 4.30-4.34
  695. 0x45411263, 0x11081263, 0x04080263, 0x00080063, 0x51499062, // 4.35-4.39
  696. 0x14419062, 0x10401062, 0x04000262, 0x51499261, 0x14489261, // 4.40-4.44
  697. 0x04418261, 0x01009061, 0x00000061, 0x55091260, 0x44489260, // 4.45-4.49
  698. 0x04418060, 0x00080060, 0x5149945f, 0x4509925f, 0x4441025f, // 4.50-4.54
  699. 0x4101025f, 0x0008005f, 0x5549125e, 0x4509925e, 0x0448905e, // 4.55-4.59
  700. 0x4040105e, 0x0008005e, 0x5149925d, 0x1448925d, 0x4441025d, // 4.60-4.64
  701. 0x4040105d, 0x0008005d, 0x5149925c, 0x1449825c, 0x0441905c, // 4.65-4.69
  702. 0x4040105c, 0x0008005c, 0x4549925b, 0x5141125b, 0x1108925b, // 4.70-4.74
  703. 0x4041005b, 0x0001005b, 0x0000005b, 0x5148925a, 0x4448105a, // 4.75-4.79
  704. 0x4101025a, 0x0400105a, 0x0000005a, 0x55091259, 0x14489259, // 4.80-4.84
  705. 0x11081059, 0x10080259, 0x00080059, 0x54499258, 0x14498258, // 4.85-4.89
  706. 0x11410258, 0x10410258, 0x04001058, 0x00000058, 0x15419257, // 4.90-4.94
  707. 0x14489257, 0x11081057, 0x04080257, 0x40000257, 0x55099256, // 4.95-4.99
  708. 0x45419256, 0x11419056, 0x44081056, 0x01009056, 0x00000056, // 5.00-5.04
  709. 0x00000056, 0x15099055, 0x11418255, 0x04089055, 0x04010055, // 5.05-5.09
  710. 0x00010055, 0x51499254, 0x51481254, 0x45081254, 0x11010254, // 5.10-5.14
  711. 0x40400254, 0x10000054, 0x55489253, 0x51490253, 0x44481253, // 5.15-5.19
  712. 0x04418253, 0x01018053, 0x04000053, 0x45499252, 0x55091252, // 5.20-5.24
  713. 0x14489252, 0x11089052, 0x41010052, 0x40010052, 0x00000052, // 5.25-5.29
  714. 0x55099251, 0x45099051, 0x44481051, 0x11010251, 0x40400251, // 5.30-5.34
  715. 0x01000051, 0x15499250, 0x55091250, 0x14489250, 0x11089050, // 5.35-5.39
  716. 0x10401050, 0x01000250, 0x00001050, 0x5449924f, 0x5148924f, // 5.40-5.44
  717. 0x1448904f, 0x1108104f, 0x0408824f, 0x0040004f, 0x0000104f, // 5.45-5.49
  718. 0x5541924e, 0x1449904e, 0x5109024e, 0x0441824e, 0x4040104e, // 5.50-5.54
  719. 0x1001004e, 0x0000004e, 0x1549924d, 0x4541924d, 0x1141904d, // 5.55-5.59
  720. 0x0441824d, 0x1040104d, 0x0040024d, 0x0000024d, 0x5549124c, // 5.60-5.64
  721. 0x5449124c, 0x1141924c, 0x4441024c, 0x1101024c, 0x4040024c, // 5.65-5.69
  722. 0x0008004c, 0x0000004c, 0x5509924b, 0x1509904b, 0x1141824b, // 5.70-5.74
  723. 0x1108104b, 0x4101024b, 0x1001004b, 0x1000004b, 0x5541924a, // 5.75-5.79
  724. 0x1541924a, 0x1448924a, 0x1441824a, 0x0440904a, 0x4040104a, // 5.80-5.84
  725. 0x0001804a, 0x0000004a, 0x15499249, 0x55091249, 0x14489249, // 5.85-5.89
  726. 0x44410249, 0x04418249, 0x01018049, 0x00080049, 0x00000249, // 5.90-5.94
  727. 0x45499248, 0x55091248, 0x51411248, 0x11098248, 0x41081048, // 5.95-5.99
  728. 0x04080248, 0x00400248, 0x00000248, 0x00000048, 0x55411247, // 6.00-6.04
  729. 0x45419247, 0x14419047, 0x11089047, 0x10410047, 0x40400247, // 6.05-6.09
  730. 0x00080047, 0x00000047, 0x55491246, 0x54491246, 0x11419246, // 6.10-6.14
  731. 0x11418246, 0x41081046, 0x04080246, 0x00408246, 0x10000046, // 6.15-6.19
  732. 0x00000046, 0x55490245, 0x15099245, 0x45098245, 0x45081045, // 6.20-6.24
  733. 0x11081045, 0x04088245, 0x00088045, 0x10000045, 0x00000045, // 6.25-6.29
  734. 0x55491044, 0x15099244, 0x44498244, 0x44481044, 0x10418244, // 6.30-6.34
  735. 0x10410044, 0x01001044, 0x10000244, 0x00000044, 0x54499243, // 6.35-6.39
  736. 0x15419243, 0x14489243, 0x11098243, 0x04418243, 0x04089043, // 6.40-6.44
  737. 0x01018043, 0x00400043, 0x00001043, 0x00000043, 0x55481242, // 6.45-6.49
  738. 0x15099242, 0x45098242, 0x44481042, 0x10418242, 0x10401042, // 6.50-6.54
  739. 0x40400242, 0x00080042, 0x00001042, 0x55491241, 0x51499241, // 6.55-6.59
  740. 0x51481241, 0x14419241, 0x44418241, 0x44401041, 0x04089041, // 6.60-6.64
  741. 0x04010041, 0x10001041, 0x00000041, 0x00000041, 0x54499240, // 6.65-6.69
  742. 0x51498240, 0x51411040, 0x51081240, 0x04418240, 0x04089040, // 6.70-6.74
  743. 0x01018040, 0x40080040, 0x10000040, 0x00000040, 0x5509923f, // 6.75-6.79
  744. 0x1548923f, 0x5148123f, 0x1448923f, 0x4448103f, 0x1101823f, // 6.80-6.84
  745. 0x4101003f, 0x4040103f, 0x0008003f, 0x0000023f, 0x0000003f, // 6.85-6.89
  746. 0x5149923e, 0x1541923e, 0x5448123e, 0x4508123e, 0x1108923e, // 6.90-6.94
  747. 0x4108103e, 0x0408823e, 0x0401003e, 0x0100023e, 0x0001003e, // 6.95-6.99
  748. 0x0000003e, 0x5149923d, 0x5509123d, 0x4541923d, 0x5141103d, // 7.00-7.04
  749. 0x1141823d, 0x1108103d, 0x1101023d, 0x1008023d, 0x0100103d, // 7.05-7.09
  750. 0x4000023d, 0x0000003d, 0x0000003d, 0x1549903c, 0x1541923c, // 7.10-7.14
  751. 0x1448923c, 0x5109023c, 0x4441023c, 0x0441823c, 0x0440103c, // 7.15-7.19
  752. 0x0408023c, 0x0100103c, 0x0001003c, 0x0008003c, 0x5548923b, // 7.20-7.24
  753. 0x5509923b, 0x5449103b, 0x5141123b, 0x4448923b, 0x1108903b, // 7.25-7.29
  754. 0x1108103b, 0x4101023b, 0x4040103b, 0x0401003b, 0x0001003b, // 7.30-7.34
  755. 0x0001003b, 0x5549123a, 0x5549123a, 0x5509123a, 0x4541923a, // 7.35-7.39
  756. 0x5141103a, 0x1109823a, 0x1108903a, 0x4408103a, 0x1040103a, // 7.40-7.44
  757. 0x4040023a, 0x0008803a, 0x4000003a, 0x0000003a, 0x45499239, // 7.45-7.49
  758. 0x51499239, 0x45489239, 0x14498239, 0x45090239, 0x11089239, // 7.50-7.54
  759. 0x11089039, 0x44081039, 0x10401039, 0x40401039, 0x00088039, // 7.55-7.59
  760. 0x10000039, 0x00000039, 0x00000039, 0x55491038, 0x55091238, // 7.60-7.64
  761. 0x45419238, 0x51411038, 0x45081238, 0x44410238, 0x10418238, // 7.65-7.69
  762. 0x10401038, 0x04080238, 0x01000238, 0x04000238, 0x04000038, // 7.70-7.74
  763. 0x00000038, 0x55099237, 0x55099237, 0x54491037, 0x45419237, // 7.75-7.79
  764. 0x11419037, 0x11418237, 0x11089037, 0x44081037, 0x04089037, // 7.80-7.84
  765. 0x04018037, 0x40080037, 0x00400037, 0x00010037, 0x00000037, // 7.85-7.89
  766. 0x55491236, 0x45499236, 0x15419236, 0x51489236, 0x11419036, // 7.90-7.94
  767. 0x51090236, 0x44410236, 0x04418236, 0x04089036, 0x41010036, // 7.95-7.99
  768. 0x01009036, 0x00400036, 0x00008236, 0x00000036, 0x00000036, // 8.00-8.04
  769. 0x54499235, 0x55099235, 0x54491035, 0x51419235, 0x14419035, // 8.05-8.09
  770. 0x11418235, 0x44481035, 0x11088235, 0x10410035, 0x04088235, // 8.10-8.14
  771. 0x10080035, 0x04001035, 0x00080035, 0x00010035, 0x00000035, // 8.15-8.19
  772. 0x51499234, 0x54499234, 0x51498234, 0x54490234, 0x14489234, // 8.20-8.24
  773. 0x11418234, 0x44418234, 0x44081034, 0x10418234, 0x41010034, // 8.25-8.29
  774. 0x40401034, 0x04001034, 0x04000234, 0x00400034, 0x00000034, // 8.30-8.34
  775. 0x00000034, 0x55491233, 0x45499233, 0x45489233, 0x54490233, // 8.35-8.39
  776. 0x14489233, 0x51090233, 0x14418233, 0x11081033, 0x10418233, // 8.40-8.44
  777. 0x10410033, 0x04080233, 0x40400233, 0x40080033, 0x01000033, // 8.45-8.49
  778. 0x40000033, 0x00000033, 0x55489232, 0x54499232, 0x15489232, // 8.50-8.54
  779. 0x45489232, 0x45099032, 0x51411032, 0x51081232, 0x44410232, // 8.55-8.59
  780. 0x44410232, 0x41080232, 0x04088232, 0x01018032, 0x10010032, // 8.60-8.64
  781. 0x10001032, 0x00400032, 0x01000032, 0x00000032, 0x51499231, // 8.65-8.69
  782. 0x45499231, 0x55091231, 0x15099231, 0x51481231, 0x14489231, // 8.70-8.74
  783. 0x51090231, 0x14418231, 0x11089031, 0x04418031, 0x04409031, // 8.75-8.79
  784. 0x41010031, 0x01018031, 0x40400031, 0x00400031, 0x00001031, // 8.80-8.84
  785. 0x00080031, 0x00000031, 0x55489230, 0x55099230, 0x45498230, // 8.85-8.89
  786. 0x51489230, 0x45099030, 0x45090230, 0x44489230, 0x51081030, // 8.90-8.94
  787. 0x44410230, 0x11081030, 0x11010230, 0x04088230, 0x04018030, // 8.95-8.99
  788. 0x40400030, 0x00088030, 0x10000030, 0x00000030, 0x00001030, // 9.00-9.04
  789. 0x5541922f, 0x1549922f, 0x5449922f, 0x4549822f, 0x5449022f, // 9.05-9.09
  790. 0x5141122f, 0x1448922f, 0x1441902f, 0x4448102f, 0x4441022f, // 9.10-9.14
  791. 0x1108022f, 0x1101022f, 0x0408822f, 0x0401802f, 0x4040002f, // 9.15-9.19
  792. 0x0008802f, 0x0400002f, 0x0400002f, 0x0000002f, 0x0000002f, // 9.20-9.24
  793. 0x5541922e, 0x5509922e, 0x4549822e, 0x5148922e, 0x1509902e, // 9.25-9.29
  794. 0x4509822e, 0x1441902e, 0x1441822e, 0x1108902e, 0x1108902e, // 9.30-9.34
  795. 0x0441802e, 0x0440902e, 0x4101002e, 0x0101802e, 0x4008002e, // 9.35-9.39
  796. 0x0008802e, 0x0400002e, 0x0400002e, 0x0000002e, 0x0000002e, // 9.40-9.44
  797. 0x5449922d, 0x5149922d, 0x5541122d, 0x1509922d, 0x5148922d, // 9.45-9.49
  798. 0x5141902d, 0x1448902d, 0x1141822d, 0x4441102d, 0x4441022d, // 9.50-9.54
  799. 0x0441822d, 0x4408102d, 0x1040902d, 0x0408802d, 0x1008002d, // 9.55-9.59
  800. 0x0100102d, 0x0400022d, 0x0008002d, 0x0001002d, 0x0000002d, // 9.60-9.64
  801. 0x0000002d, 0x5549122c, 0x1549922c, 0x5449922c, 0x5149822c, // 9.65-9.69
  802. 0x5449022c, 0x5148122c, 0x1448922c, 0x1141902c, 0x1441822c, // 9.70-9.74
  803. 0x1108902c, 0x1108902c, 0x0441802c, 0x0440902c, 0x4101002c, // 9.75-9.79
  804. 0x4040102c, 0x0100102c, 0x0040822c, 0x0100002c, 0x0008002c, // 9.80-9.84
  805. 0x0008002c, 0x0000002c, 0x0000002c, 0x4549922b, 0x4549922b, // 9.85-9.89
  806. 0x5509922b, 0x5149902b, 0x5449102b, 0x5148122b, 0x1448922b, // 9.90-9.94
  807. 0x4509022b, 0x5108122b, 0x4441822b, 0x1108102b, 0x4441022b, // 9.95-9.99
  808. 0x00000000 };
  809. DWORD Power10ExpNum[] = {
  810. 1L,
  811. 10L,
  812. 100L,
  813. 1000L,
  814. 10000L,
  815. 100000L,
  816. 1000000L,
  817. 10000000L,
  818. 100000000L,
  819. 1000000000L
  820. };
  821. FD6
  822. HTENTRY
  823. Log(
  824. FD6 Number
  825. )
  826. /*++
  827. Routine Description:
  828. This functions calculate the common logarithm for the number passed in,
  829. this is 10 based logarithm.
  830. Arguments:
  831. Number - the decimal (FD6) number, this is a special format decimal number
  832. (FD6) it depends on the #define and may be floating number or
  833. six (6) lower digits as number to the right of the decimal
  834. points. that is 3 = 0.000003, 10000 = 0.010000, 1232321 = 1.232321
  835. and so on.
  836. Return Value:
  837. Now no error value is returned, but it will clip to the FD6 defined limit
  838. as following:
  839. FD6_LOG_MAX - if the Number passed in is >= FD6_MAX (ie. 2147.483647)
  840. then it returned FD6_LOG_MAX (ie. 3.331930).
  841. FD6_LOG_MIN - if the Number passed in is less or equal to 0 then it treated
  842. passed Number as 0.000001 so the return value will be
  843. FD6_LOG_MIN (ie. -6.0)
  844. othewise - the approximate logarithm (based 10) number is returnd as
  845. a FD6 number. The accuracy of the returned logarithm number
  846. as minimum/maximum errors as
  847. maximum error = +0.000005983
  848. minimum error = -0.0000009018
  849. Author:
  850. 16-Jan-1991 Wed 14:03:58 created -by- Daniel Chou (danielc)
  851. Revision History:
  852. 26-Sep-1991 Thu 12:10:52 updated -by- Daniel Chou (danielc)
  853. Rewrite for more accuracy up to six significant decimal digitis, and
  854. also make it durable to run under floating point package.
  855. --*/
  856. {
  857. FD6 Characteristic; // characteristics number
  858. FD6 Mantissa;
  859. LONG Rem;
  860. INT Quot;
  861. //
  862. // Do in-line binary search to find out how many digits of this
  863. // number (decimal left shift count), at here the range is from
  864. // 0.000001 to 999.999999, the goal is to make the number range in
  865. // 100.000000 to 999.999999 and also get its characteristic number.
  866. //
  867. // 100.000000 = 0
  868. // 10.000000 = 1
  869. // 1.000000 = 2
  870. // 0.100000 = 3
  871. // 0.010000 = 4
  872. // 0.001000 = 5
  873. // 0.000100 = 6
  874. // 0.000010 = 7
  875. // 0.000001 = 8
  876. //
  877. // first, find out what the characteristic is
  878. //
  879. if (Number >= FD6_p01) { // possible 0,1,2,3,4
  880. if (Number >= FD6_1) { // possible 0,1,2
  881. if (Number >= FD6_10) { // possible 0,1
  882. if (Number >= FD6_100) { // possible 0
  883. if (Number >= FD6_1000) {
  884. if (Number >= (FD6_MAX - FD6_p000005)) {
  885. return(FD6_LOG_MAX);
  886. }
  887. Characteristic = FD6_3;
  888. Number = FD6DivL(Number, 10);
  889. } else {
  890. // 100.000000 - 999.000000
  891. Characteristic = FD6_2; // alreay in range
  892. }
  893. } else { // possible 1
  894. // 10.000000 - 99.999999
  895. Characteristic = FD6_1;
  896. Number = FD6xL(Number, 10);
  897. }
  898. } else { // possible 2
  899. // 1.000000 - 9.999999
  900. Characteristic = FD6_0;
  901. Number = FD6xL(Number, 100);
  902. }
  903. } else if (Number >= FD6_p1) { // possible 3
  904. // 0.100000 - 0.999999
  905. Characteristic = -FD6_1;
  906. Number = FD6xL(Number, 1000);
  907. } else { // possible 4
  908. // 0.010000 - 0.099999
  909. Characteristic = -FD6_2;
  910. Number = FD6xL(Number, 10000);
  911. }
  912. } else if (Number >= FD6_p0001) { // possible 5,6
  913. if (Number >= FD6_p001) { // possible 5
  914. // 0.001000 - 0.009999
  915. Characteristic = -FD6_3;
  916. Number = FD6xL(Number, 100000);
  917. } else { // possible 6
  918. // 0.000100 - 0.000999
  919. Characteristic = -FD6_4;
  920. Number = FD6xL(Number, 1000000);
  921. }
  922. } else if (Number >= FD6_p00001) { // possible 7
  923. // 0.000010 - 0.000099
  924. Characteristic = -FD6_5;
  925. Number = FD6xL(Number, 10000000);
  926. } else if (Number > FD6_0) { // possible 8
  927. // 0.000001 - 0.000009
  928. Characteristic = -FD6_6;
  929. Number = FD6xL(Number, 100000000);
  930. } else {
  931. return(FD6_LOG_MIN); // invalid numbers
  932. }
  933. //
  934. // The number now range from 100.0000 to 999.999999
  935. //
  936. //
  937. // ASSERT((Number >= FD6_100) && (Number < FD6_1000));
  938. //
  939. //
  940. // The Number now range from 100.000000 - 999.999999 and we need to
  941. // find the mantissa for it. The number will be index
  942. // and/or interpolate from the table as following:
  943. //
  944. // Number 123.1234567
  945. // | |
  946. // | +----> 0.1234567 (if non zero) then interpolate with
  947. // | next table entry.
  948. // |
  949. // +-------> (123 - 100) will be index into the table
  950. //
  951. // For example:
  952. //
  953. // Log (1.234567) = 0.091515
  954. //
  955. // Characteristic = 0.000000
  956. // Mantissa = Table[123-100] = 0.089905
  957. // Fraction = (Table[124-100] - 0.089905) * 0.456700
  958. // = 0.003517 * 0.4567 = 0.001606
  959. // Return = (Characteristic + Mantissa + Fraction) =
  960. // = 0.000000 + 0.089905 + 0.001606 = 0.091511
  961. // Error = 0.091515 - 0.091511 = 0.000004
  962. //
  963. // Max/Min Errors are +0.000006/-0.000001
  964. //
  965. Mantissa = MantissaTable[Quot = (INT)(Number / FD6_1) - (INT)100];
  966. if (Rem = (LONG)(Number % FD6_1)) {
  967. Mantissa += FractionToMantissa((FD6)Rem,
  968. MantissaCorrectData[Quot]);
  969. }
  970. return(Characteristic + Mantissa);
  971. }
  972. FD6
  973. HTENTRY
  974. AntiLog(
  975. FD6 Number
  976. )
  977. /*++
  978. Routine Description:
  979. Calculate the antilogarithm for the logarithm number passed in, that is
  980. this function return the exponent of Number which base 10.
  981. Arguments:
  982. Number - the logarithm number, this is a special format decimal number
  983. (FD6) it depends on the #define and may be floating number or
  984. six (6) lower digits as number to the right of the decimal
  985. points. that is 3 = 0.000003, 10000 = 0.010000, 1232321 = 1.232321
  986. and so on.
  987. Return Value:
  988. Now no error returned, but it clipped the result to the FD6 limit, return
  989. values as following:
  990. 0.000001 - if the Number is <= -6.0
  991. FD6_MAX - if the Number is >= 3.331930 then it return FD6_MAX
  992. (ie. 2147.483647).
  993. othewise - approximate the antilogarithm (base 10) of the Number passed
  994. in. the accuracy of the function is abount +0.000008 to
  995. -0.000001.
  996. Author:
  997. 16-Jan-1991 Wed 15:34:17 created -by- Daniel Chou (danielc)
  998. Revision History:
  999. 26-Sep-1991 Thu 12:01:06 updated -by- Daniel Chou (danielc)
  1000. Rewrite for more accuracy up to six significant decimal digitis, and
  1001. also make it durable to run under floating point package.
  1002. --*/
  1003. {
  1004. INT Characteristic;
  1005. INT Index;
  1006. INT IndexH;
  1007. INT IndexL;
  1008. FD6 CurrentMantissa;
  1009. //
  1010. // The number range is from -5.999999 - 3.331928
  1011. // Separate the Number into Characteristic and Mantissa,
  1012. //
  1013. if (Number < FD6_0) {
  1014. if (Number <= FD6_LOG_MIN) {
  1015. return(FD6_p000001);
  1016. }
  1017. Characteristic = (INT)((Number - (FD6)999999) / FD6_1);
  1018. Number -= FD6xL(FD6_1, Characteristic);
  1019. } else if (Number >= FD6_1) {
  1020. if (Number >= FD6_LOG_MAX) {
  1021. return(FD6_MAX);
  1022. }
  1023. Characteristic = (INT)((Number + (FD6)999999) / FD6_1);
  1024. Number = FD6xL(FD6_1, Characteristic) - Number;
  1025. } else {
  1026. Characteristic = 0;
  1027. }
  1028. if (Number) {
  1029. //
  1030. // Do a modified binary search to find the closed low index, the
  1031. // SearchTable[] is a estimate index for the first 2 mantissa digits.
  1032. //
  1033. Index = (INT)(Number / FD6_p01); // divide by 0.01 for index
  1034. IndexL = (INT)MantSearchTable[Index++]; // starting estimate index
  1035. IndexH = (INT)(MantSearchTable[Index] + 1); // ending estimate index
  1036. while ((Index = (IndexL + IndexH) >> 1) != IndexL) {
  1037. if (Number < (CurrentMantissa = MantissaTable[Index])) {
  1038. IndexH = Index;
  1039. } else if (Number > CurrentMantissa) {
  1040. IndexL = Index;
  1041. } else {
  1042. Number = FD6_0;
  1043. break;
  1044. }
  1045. }
  1046. if (Number) { // Number = 0, if exactly match
  1047. ASSERT((IndexL == Index) && ((IndexL + 1) == IndexH));
  1048. //
  1049. // Here we try to estimate for lower 4 decimal digit Mantissa
  1050. // the table index is the index Mantissa of 0 - 900 (0.00 - 9.00)
  1051. // the interpolate Mantissa is betwen two table indics Mantissas
  1052. // such between 512 and 513 will be Mantissa between 5.12 and 5.13
  1053. //
  1054. Number = MantissaToFraction(Number - MantissaTable[IndexL],
  1055. MantissaCorrectData[IndexL]);
  1056. }
  1057. //
  1058. // The Index range is from 0-900
  1059. //
  1060. // Add in 100 to offset the mantissa table, since the first entry
  1061. // is 1.0000
  1062. //
  1063. Number += INTToFD6(Index + 100);
  1064. Characteristic -= 2;
  1065. } else { // Number = 0.0, the result is 1.0
  1066. Number = FD6_1;
  1067. }
  1068. //
  1069. // Now we need to shift the decimal point around, if characteristic is
  1070. // positive then we shift the decimal to the right (multiply), if the
  1071. // Mantissa is negative then we shift the decimal point to the left
  1072. // (divide), if it is a zero, then this is the final logarithm Mantissa.
  1073. //
  1074. if (Characteristic < 0) {
  1075. return(FD6DivL(Number, (LONG)Power10ExpNum[-Characteristic]));
  1076. } else if (Characteristic > 0) {
  1077. return(FD6xL(Number, (LONG)Power10ExpNum[Characteristic]));
  1078. } else {
  1079. return(Number);
  1080. }
  1081. }
  1082. FD6
  1083. HTENTRY
  1084. RaisePower(
  1085. FD6 BaseNumber,
  1086. FD6 Exponent,
  1087. WORD Flags
  1088. )
  1089. /*++
  1090. Routine Description:
  1091. Calculate the power of the base number (BaseNumber^Power).
  1092. Arguments:
  1093. BaseNumber - The decimal (FD6) number, this is a special format decimal
  1094. number FD6) it depends on the #define and may be floating
  1095. number or six (6) lower digits as number to the right of
  1096. the decimal points. that is 3 = 0.000003, 10000 = 0.010000,
  1097. 1232321 = 1.232321 and so on.
  1098. Exponent - The exponent number is nth number to raise power to, it
  1099. has same format as BaseNumber.
  1100. Flags - One or more of the following flags may be specified
  1101. RPF_RADICAL
  1102. 1: This is a radical expression, the Exponent is
  1103. equal to 1.0/Exponent that is,
  1104. 0: This is a regular power expression.
  1105. RPF_INTEXP
  1106. 1: The Exponent field is treated as long integer number
  1107. rather a FD6 number.
  1108. 0: The Exponent field is a FD6 number
  1109. Note: When BaseNumber is a negative number.
  1110. 1) Expoonent has fraction = .0 (ie. Integer only)
  1111. The whole BaseNumber is treated as an whole number.
  1112. 2.0 3.0
  1113. (-0.6) = 0.36 and (-0.6) = -0.216
  1114. 2) Exponent has fraction portion.
  1115. The negative sign is treated as a symbol.
  1116. 2.1 2.1
  1117. -0.6 = -(0.6 ) = -0.342072
  1118. The ONLY exception is that if Exponent = 0.0, then it returned
  1119. 1.0 - if BaseNumber != 0.0
  1120. 0.0 - if BaseNumber == 0.0 <-- Error Condition
  1121. Return Value:
  1122. Now no error value is returned, but it will clip to the FD6 defined limit
  1123. if condition occured as following and in this sequence:
  1124. 1) 0.0 - If BaseNumber = 0.0,
  1125. No error returned if Exponent <= 0.0, this number should
  1126. is not a real number.
  1127. 2) 1.0 - If Exponent = 0.0.
  1128. othewise - the approximate number for the nth power is returnd as
  1129. a FD6 number. The accuracy of the returned logarithm number
  1130. as minimum/maximum errors as
  1131. maximum error = +0.000005983
  1132. minimum error = -0.0000009018
  1133. Author:
  1134. 16-Jan-1991 Wed 14:03:58 created -by- Daniel Chou (danielc)
  1135. Revision History:
  1136. 26-Sep-1991 Thu 12:10:52 updated -by- Daniel Chou (danielc)
  1137. Delete OneOverExponent (BOOL) parameter
  1138. Rewrite for more accuracy up to six significant decimal digitis, and
  1139. also make it durable to run under floating point package.
  1140. --*/
  1141. {
  1142. BOOL NegativeBase;
  1143. FD6 PowerNumber;
  1144. //
  1145. // check if any illegal condition exists, and preprocess any necessary
  1146. // data
  1147. //
  1148. if (Flags & RPF_INTEXP) {
  1149. if (Exponent == 1L) {
  1150. return(BaseNumber);
  1151. }
  1152. } else {
  1153. if (Exponent == FD6_1) {
  1154. return(BaseNumber);
  1155. }
  1156. if (!(Exponent % FD6_1)) {
  1157. Exponent /= FD6_1;
  1158. Flags |= RPF_INTEXP;
  1159. }
  1160. }
  1161. if (NegativeBase = (BOOL)(BaseNumber <= FD6_0)) {
  1162. if (!(BaseNumber = -BaseNumber)) { // 0^-num, 0^0 are illegal!!
  1163. // but return as 0.0 now
  1164. return(FD6_0);
  1165. }
  1166. }
  1167. if (!Exponent) {
  1168. return((NegativeBase) ? -FD6_1 : FD6_1);
  1169. }
  1170. //
  1171. // y
  1172. // Calculating the x = N with logarithms by solving following formula:
  1173. //
  1174. // Log(N) = y * Log(x)
  1175. // ...
  1176. //
  1177. // N = AntiLog(y * Log(x))
  1178. //
  1179. // For example:
  1180. //
  1181. // y -1.654321
  1182. // x = 0.123456 using the above formula we have
  1183. // -----------------------
  1184. //
  1185. // Log(N) = y * Log(x)
  1186. // N = AntiLog(y * Log(x))
  1187. //
  1188. // ==> N = AntiLog(-1.654321 * Log(0.123456))
  1189. // ==> N = AntiLog(-1.654321 * -0.908488)
  1190. // ==> N = AntiLog(1.502931)
  1191. // ==> N = 31.836917 <=== apporoximate FD6 number
  1192. //
  1193. //
  1194. // If base number is 10.0 then do nothing with the logarithm, since
  1195. // Log(10.0) = 1.0
  1196. //
  1197. BaseNumber = (BaseNumber == FD6_10) ? FD6_1 : Log(BaseNumber);
  1198. if (Flags & RPF_INTEXP) {
  1199. //
  1200. // For EVEN interger exponent, the result always positive
  1201. //
  1202. if (!((DWORD)Exponent & 0x01)) {
  1203. NegativeBase = FALSE;
  1204. }
  1205. PowerNumber = AntiLog((Flags & RPF_RADICAL) ?
  1206. FD6DivL(BaseNumber, Exponent) :
  1207. FD6xL(BaseNumber, Exponent));
  1208. } else {
  1209. PowerNumber = AntiLog((Flags & RPF_RADICAL) ?
  1210. DivFD6(BaseNumber, Exponent) :
  1211. MulFD6(BaseNumber, Exponent));
  1212. }
  1213. return((NegativeBase) ? -PowerNumber : PowerNumber);
  1214. }
  1215. BOOL
  1216. HTENTRY
  1217. ComputeInverseMatrix3x3(
  1218. PMATRIX3x3 pInMatrix,
  1219. PMATRIX3x3 pOutMatrix
  1220. )
  1221. /*++
  1222. Routine Description:
  1223. -1
  1224. This function calculate inverse (Matrix ) of the input 3x3 matrix
  1225. Arguments:
  1226. pInMatrix - 3 x 3 matrix to be inversed
  1227. pOutMatrix - Inverse 3 x 3 matrix of the input 3 x 3 matrix.
  1228. Return Value:
  1229. The returned value will be TRUE if sucessfully invert the input matrix and
  1230. returned value will be FALSE if there is singular in the input matrix.
  1231. If the returned value is FALSE then the output matrix is not completed.
  1232. Author:
  1233. 11-Oct-1991 Fri 14:19:59 created -by- Daniel Chou (danielc)
  1234. Revision History:
  1235. --*/
  1236. {
  1237. MATRIX3x3 InMatrix;
  1238. MATRIX3x3 OutMatrix;
  1239. FD6 Temp;
  1240. BOOL NoSigular = TRUE;
  1241. INT i;
  1242. INT j;
  1243. INT k;
  1244. InMatrix = *pInMatrix; // do a local copy
  1245. //
  1246. // Clear all to zero and set diagnal to 1.0
  1247. //
  1248. ZeroMemory(&OutMatrix.m[0][0], sizeof(MATRIX3x3));
  1249. OutMatrix.m[0][0] = OutMatrix.m[1][1] = OutMatrix.m[2][2] = FD6_1;
  1250. //
  1251. // Using gaussian elimination.
  1252. //
  1253. for (i = 0; i < 3; i++) {
  1254. for (j = i + 1, k = i; j < 3; j++) {
  1255. if (ABSFD6(InMatrix.m[j][i]) > ABSFD6(InMatrix.m[k][i])) {
  1256. k = j;
  1257. }
  1258. }
  1259. if (InMatrix.m[k][i]) {
  1260. //
  1261. // Now we need to do pivot, we will switch row 'i' and row 'k' if
  1262. // they are not in order.
  1263. //
  1264. if (k != i) {
  1265. for (j = 0; j < 3; j++) {
  1266. SWAPFD6( InMatrix.m[i][j], InMatrix.m[k][j], Temp);
  1267. SWAPFD6(OutMatrix.m[i][j], OutMatrix.m[k][j], Temp);
  1268. }
  1269. }
  1270. //
  1271. // Normalize the row, make the diagonal (ie. Matrix[i][i]) to 1.0
  1272. // that is
  1273. //
  1274. for (j = 0, Temp = InMatrix.m[i][i]; j < 3; j++) {
  1275. InMatrix.m[i][j] = DivFD6(InMatrix.m[i][j], Temp);
  1276. OutMatrix.m[i][j] = DivFD6(OutMatrix.m[i][j], Temp);
  1277. }
  1278. //
  1279. // and, zero the non-diagonal items in this column (ie. column i).
  1280. //
  1281. for (j = 0; j < 3; j++) {
  1282. if ((j != i) && (Temp = InMatrix.m[j][i])) {
  1283. for (k = 0; k < 3; k++) {
  1284. InMatrix.m[j][k] -= MulFD6( InMatrix.m[i][k], Temp);
  1285. OutMatrix.m[j][k] -= MulFD6(OutMatrix.m[i][k], Temp);
  1286. }
  1287. }
  1288. }
  1289. } else {
  1290. NoSigular = FALSE;
  1291. }
  1292. }
  1293. *pOutMatrix = OutMatrix;
  1294. return(NoSigular);
  1295. }
  1296. VOID
  1297. HTENTRY
  1298. ConcatTwoMatrix3x3(
  1299. PMATRIX3x3 pConcat,
  1300. PMATRIX3x3 pMatrix,
  1301. PMATRIX3x3 pOutMatrix
  1302. )
  1303. /*++
  1304. Routine Description:
  1305. This function concatenate 'pMatrix' to 'pConcat' and output the result in
  1306. 'pOutMatrix', supposed you have
  1307. pConcat = RGB->YIQ and pMatrix = YIQ->XYZ
  1308. then pOutMatrix = RGB->XYZ
  1309. Arguments:
  1310. pConcat - Source matrix to be concat
  1311. pMatrix - Matrix to concatenate into pConcat
  1312. pOutMatrix - Concatenated 3 x 3 matrix.
  1313. Return Value:
  1314. There is no return value.
  1315. Author:
  1316. 11-Oct-1991 Fri 14:19:59 created -by- Daniel Chou (danielc)
  1317. Revision History:
  1318. --*/
  1319. {
  1320. MATRIX3x3 Concat = *pConcat;
  1321. MATRIX3x3 Matrix = *pMatrix;
  1322. MATRIX3x3 OutMatrix;
  1323. MULDIVPAIR MDPairs[4];
  1324. INT i;
  1325. INT j;
  1326. MAKE_MULDIV_INFO(MDPairs, 3, MULDIV_NO_DIVISOR);
  1327. for (i = 0; i < 3; i++) {
  1328. for (j = 0; j < 3; j++) {
  1329. MAKE_MULDIV_PAIR(MDPairs, 1, Matrix.m[i][0], Concat.m[0][j]);
  1330. MAKE_MULDIV_PAIR(MDPairs, 2, Matrix.m[i][1], Concat.m[1][j]);
  1331. MAKE_MULDIV_PAIR(MDPairs, 3, Matrix.m[i][2], Concat.m[2][j]);
  1332. OutMatrix.m[i][j] = MulDivFD6Pairs(MDPairs);
  1333. }
  1334. }
  1335. DBGP_IF(DBGP_CONCAT_M,
  1336. DBGP("== Concat two 3x3 matrixes ==");
  1337. DBGP("[%s %s %s] [%s %s %s] [%s %s %s]"
  1338. ARGFD6(Matrix.m[0][0],2,3)
  1339. ARGFD6(Matrix.m[0][1],2,3) ARGFD6(Matrix.m[0][2],2,3)
  1340. ARGFD6(Concat.m[0][0],2,3)
  1341. ARGFD6(Concat.m[0][1],2,3) ARGFD6(Concat.m[0][2],2,3)
  1342. ARGFD6(OutMatrix.m[0][0],2,3)
  1343. ARGFD6(OutMatrix.m[0][1],2,3) ARGFD6(OutMatrix.m[0][2],2,3));
  1344. DBGP("[%s %s %s] x [%s %s %s] = [%s %s %s]"
  1345. ARGFD6(Matrix.m[1][0],2,3)
  1346. ARGFD6(Matrix.m[1][1],2,3) ARGFD6(Matrix.m[1][2],2,3)
  1347. ARGFD6(Concat.m[1][0],2,3)
  1348. ARGFD6(Concat.m[1][1],2,3) ARGFD6(Concat.m[1][2],2,3)
  1349. ARGFD6(OutMatrix.m[1][0],2,3)
  1350. ARGFD6(OutMatrix.m[1][1],2,3) ARGFD6(OutMatrix.m[1][2],2,3));
  1351. DBGP("[%s %s %s] [%s %s %s] [%s %s %s]"
  1352. ARGFD6(Matrix.m[2][0],2,3)
  1353. ARGFD6(Matrix.m[2][1],2,3) ARGFD6(Matrix.m[2][2],2,3)
  1354. ARGFD6(Concat.m[2][0],2,3)
  1355. ARGFD6(Concat.m[2][1],2,3) ARGFD6(Concat.m[2][2],2,3)
  1356. ARGFD6(OutMatrix.m[2][0],2,3)
  1357. ARGFD6(OutMatrix.m[2][1],2,3) ARGFD6(OutMatrix.m[2][2],2,3));
  1358. );
  1359. *pOutMatrix = OutMatrix;
  1360. }
  1361. #ifndef HT_OK_GEN_80x86_CODES
  1362. //////////////////////////////////////////////////////////////////////////////
  1363. // //
  1364. // Following functions are compiled only if we cannot using 80x86 assembly //
  1365. // equvalent codes //
  1366. // //
  1367. //////////////////////////////////////////////////////////////////////////////
  1368. #define U32xU32_U64(uD1, uD2, QH, QL) { \
  1369. \
  1370. DWORD x0, x1, x2, x3; \
  1371. \
  1372. (x0)=(DWORD)((uD1) & 0xFFFF) * (DWORD)((uD2) & 0xFFFF); \
  1373. (x1)=(DWORD)((uD1) >> 16) * (DWORD)((uD2) & 0xFFFF); \
  1374. (x2)=(DWORD)((uD1) & 0xFFFF) * (DWORD)((uD2) >> 16); \
  1375. (QL)=(DWORD)((x0) >> 16) + ((x1) & 0xFFFF) + ((x2) & 0xFFFF); \
  1376. (x3)=((DWORD)((uD1)>>16) * (DWORD)((uD2)>>16)) + (DWORD)((QL)>>16); \
  1377. (QL)=(DWORD)((QL) << 16) | ((x0) & 0xFFFF); \
  1378. (QH)=(DWORD)((x1) >> 16) + (DWORD)((x2) >> 16) + (x3); \
  1379. }
  1380. #define NEG_U64(QH, QL) \
  1381. (DWORD)(QH)=(DWORD)~(DWORD)(QH); (DWORD)(QL)=(DWORD)~(DWORD)(QL); \
  1382. if (!(++((DWORD)(QL)))) { ++((DWORD)(QH)); }
  1383. #define U64AddU64(QH, QL, Q0H, Q0L) \
  1384. if (((DWORD)(QL)+=(DWORD)(Q0L))<(DWORD)(Q0L)) { ++((DWORD)(QH)); } \
  1385. (DWORD)(QH) += (DWORD)(Q0H)
  1386. #define U64AddU32(QH, QL, uD) \
  1387. if (((DWORD)(QL)+=(DWORD)(uD))<(DWORD)(uD)) { ++((DWORD)(QH)); }
  1388. #define U64DivFD6_1(xH, xL, uD) { \
  1389. DWORD xT; \
  1390. if (((DWORD)(xL)+=(DWORD)FD6_p5)<(DWORD)FD6_p5) { ++((DWORD)(xH)); }\
  1391. (DWORD)(uD)=(DWORD)(((xT=(DWORD)((DWORD)(xH) << 12) | \
  1392. (DWORD)((DWORD)(xL) >> 20)) / \
  1393. (DWORD)62500) << 16); \
  1394. (DWORD)(uD)|=(DWORD)((DWORD)((DWORD)((xT % (DWORD)62500)<<16) | \
  1395. (DWORD)(((DWORD)(xL)>>4) & 0xffffL)) / \
  1396. (DWORD)62500); }
  1397. FD6
  1398. HTENTRY
  1399. MulFD6(
  1400. FD6 Multiplicand,
  1401. FD6 Multiplier
  1402. )
  1403. /*++
  1404. Routine Description:
  1405. This function multiply two FD6 numbers.
  1406. Arguments:
  1407. Multiplicand - The Multiplicand in FD6 format.
  1408. Multiplier - The Multiplier in FD6 format.
  1409. Return Value:
  1410. No error returned, the return value is the products of multiplicand and
  1411. multiplier.
  1412. Author:
  1413. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1414. Revision History:
  1415. --*/
  1416. {
  1417. DWORD xH;
  1418. DWORD xL;
  1419. DWORD Result;
  1420. BOOL Sign;
  1421. if (Sign = (BOOL)(Multiplicand <= 0L)) {
  1422. if (!(Multiplicand = -Multiplicand)) {
  1423. return(0L); // if one of them is '0' then...
  1424. }
  1425. }
  1426. if (Multiplier <= 0L) {
  1427. if (Multiplier = -Multiplier) {
  1428. Sign = !Sign;
  1429. } else {
  1430. return(FD6_0); // if one of them is '0' then...
  1431. }
  1432. }
  1433. if (Multiplicand == FD6_1) {
  1434. Result = Multiplier;
  1435. } else if (Multiplier == FD6_1) {
  1436. Result = Multiplicand;
  1437. } else {
  1438. U32xU32_U64(Multiplicand, Multiplier, xH, xL);
  1439. U64DivFD6_1(xH, xL, Result);
  1440. }
  1441. return((Sign) ? -(FD6)Result : (FD6)Result);
  1442. }
  1443. DWORD
  1444. HTENTRY
  1445. U64DivU32RoundUp(
  1446. DWORD Dividend64H,
  1447. DWORD Dividend64L,
  1448. DWORD Divisor32
  1449. )
  1450. /*++
  1451. Routine Description:
  1452. This function divide a unsigned 64-bit number by a 32-bit unsigned number
  1453. Arguments:
  1454. Dividend64H - High 32-bit of a 64-bit unsigned dividend number
  1455. Dividend64L - Low 32-bit of a 64-bit unsigned dividend number
  1456. Divisor32 - 32-bit unsigned divisor number. (must not zero);
  1457. Return Value:
  1458. No error returned, the return value is the round up quotient of the
  1459. Divndend/Divisor.
  1460. if Dividend is equal to 0 then a 0 is returned,
  1461. Author:
  1462. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1463. Revision History:
  1464. --*/
  1465. {
  1466. DWORD xH;
  1467. DWORD xL;
  1468. DWORD xT;
  1469. DWORD xR;
  1470. WORD Correct;
  1471. WORD DvsrL;
  1472. WORD DvsrH;
  1473. WORD QH;
  1474. WORD QL;
  1475. ASSERT(Divisor32 != 0L);
  1476. if ((xL = Dividend64L + (Divisor32 >> 1)) < Dividend64L) {
  1477. xH = ++Dividend64H;
  1478. } else {
  1479. xH = Dividend64H;
  1480. }
  1481. DvsrH = U16_H_U32(Divisor32);
  1482. if ((DvsrL = U16_L_U32(Divisor32)) && (DvsrH)) {
  1483. //
  1484. // Both DvsrH/DvsrL are non-zero
  1485. //
  1486. xT = (DWORD)(QH = (WORD)(xH / (DWORD)DvsrH)) * (DWORD)DvsrL;
  1487. xR = ((xH - ((DWORD)QH * (DWORD)DvsrH)) << 16) | (DWORD)U16_H_U32(xL);
  1488. if ((LONG)xT < 0L) {
  1489. //
  1490. // The overrun just too high, let's reduce it so we can manage it
  1491. // (we like it to have overrun less then 0x80000000L
  1492. //
  1493. QH -= (Correct = (WORD)((xT - xR) / Divisor32));
  1494. xT -= (DWORD)Correct * Divisor32;
  1495. }
  1496. if ((LONG)(xR -= xT) < 0L) {
  1497. --QH;
  1498. if ((LONG)(xR += Divisor32) < 0L) {
  1499. --QH;
  1500. if ((LONG)(xR += Divisor32) < 0L) {
  1501. --QH;
  1502. if ((LONG)(xR += Divisor32) < 0L) {
  1503. --QH;
  1504. if ((LONG)(xR += Divisor32) < 0L) {
  1505. --QH;
  1506. if ((LONG)(xR += Divisor32) < 0L) {
  1507. --QH;
  1508. if ((LONG)(xR += Divisor32) < 0L) {
  1509. DWORD Rem;
  1510. QH -= (WORD)(NEGDW(xR) / Divisor32);
  1511. if (Rem = (DWORD)(NEGDW(xR) % Divisor32)) {
  1512. --QH;
  1513. xR = Divisor32 - Rem;
  1514. }
  1515. }
  1516. }
  1517. }
  1518. }
  1519. }
  1520. }
  1521. }
  1522. if (U16_H_U32(xR) < DvsrH) {
  1523. xT = (DWORD)(QL = (WORD)(xR / (DWORD)DvsrH)) * (DWORD)DvsrL;
  1524. xR = ((xR - ((DWORD)QL * (DWORD)DvsrH)) << 16) | (xL & 0xffffL);
  1525. if (xR < xT) {
  1526. --QL;
  1527. if ((xR += Divisor32) < xT) {
  1528. --QL;
  1529. if ((xR += Divisor32) < xT) {
  1530. --QL;
  1531. if ((xR += Divisor32) < xT) {
  1532. --QL;
  1533. if ((xR += Divisor32) < xT) {
  1534. QL -= Correct = (WORD)((xT -= xR)/Divisor32);
  1535. if (xT > (DWORD)Correct * Divisor32) {
  1536. --QL;
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. }
  1543. } else {
  1544. xR = ((DWORD)DvsrL << 16) - ((xR << 16) | (xL & 0xffffL));
  1545. QL = (WORD)(xR / Divisor32);
  1546. if (xR > ((DWORD)QL * Divisor32)) {
  1547. ++QL;
  1548. }
  1549. QL = -QL;
  1550. }
  1551. } else if (DvsrL) {
  1552. QH = (WORD)((xH = (xH << 16) | (xL >> 16)) / (DWORD)DvsrL);
  1553. QL = (WORD)((((xH % (DWORD)DvsrL) << 16) | (xL & 0xffffL)) /
  1554. (DWORD)DvsrL);
  1555. } else { // DvsrL = 0
  1556. QH = (WORD)(xH / (DWORD)DvsrH);
  1557. QL = (WORD)((((xH % (DWORD)DvsrH) << 16) | (xL >> 16)) /
  1558. (DWORD)DvsrH);
  1559. }
  1560. return(((DWORD)QH << 16) | (DWORD)QL);
  1561. }
  1562. FD6
  1563. HTENTRY
  1564. DivFD6(
  1565. FD6 Dividend,
  1566. FD6 Divisor
  1567. )
  1568. /*++
  1569. Routine Description:
  1570. This function divide two FD6 numbers.
  1571. Arguments:
  1572. Dividend - The Dividend in FD6 format.
  1573. Divisor - The Divosr in FD6 format.
  1574. Return Value:
  1575. No error returned, the return value is the round up quotient of the
  1576. Divndend/Divisor.
  1577. if Dividend is equal to 0 then a 0 is returned,
  1578. if Divisor is equal to zero then Dividend is returned.
  1579. Author:
  1580. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1581. Revision History:
  1582. --*/
  1583. {
  1584. DWORD x0;
  1585. DWORD x1;
  1586. DWORD xH;
  1587. DWORD xL;
  1588. BOOL Sign;
  1589. if (Sign = (BOOL)(Divisor <= FD6_0)) {
  1590. if (!(Divisor = -Divisor)) {
  1591. return((Dividend < 0) ? MAX_FD6 : MIN_FD6);
  1592. }
  1593. }
  1594. if (Divisor == FD6_1) {
  1595. return((Sign) ? -Dividend : Dividend);
  1596. }
  1597. if (Dividend <= 0L) {
  1598. if (Dividend = -Dividend) {
  1599. Sign = (BOOL)!Sign;
  1600. } else {
  1601. return(FD6_0); // nothing to divide, so return 0
  1602. }
  1603. }
  1604. if (Dividend == Divisor) {
  1605. return((Sign) ? -FD6_1 : FD6_1);
  1606. }
  1607. x0 = (DWORD)U16_L_U32(Dividend) * (DWORD)62500;
  1608. x1 = (DWORD)U16_H_U32(Dividend) * (DWORD)62500;
  1609. xH = (DWORD)U16_H_U32(x1);
  1610. if ((xL = x0 + (x1 << 16)) < x0) {
  1611. ++xH;
  1612. }
  1613. xH = (xH << 4) | (DWORD)(U16_H_U32(xL) >> 12);
  1614. xL <<= 4;
  1615. if (Sign) {
  1616. return(-(FD6)U64DivU32RoundUp(xH, xL, Divisor));
  1617. } else {
  1618. return((FD6)U64DivU32RoundUp(xH, xL, Divisor));
  1619. }
  1620. }
  1621. FD6
  1622. HTENTRY
  1623. FD6DivL(
  1624. FD6 Dividend,
  1625. LONG Divisor
  1626. )
  1627. /*++
  1628. Routine Description:
  1629. This function divide a FD6 number by a LONG integer.
  1630. Arguments:
  1631. Dividend - The Dividend in FD6 format.
  1632. Divisor - The Divosr in long format.
  1633. Return Value:
  1634. No error returned, the return value is the round up quotient of the
  1635. Divndend/Divisor.
  1636. if Dividend is equal to 0 then a 0 is returned,
  1637. if Divisor is equal to zero then Dividend is returned.
  1638. Author:
  1639. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1640. Revision History:
  1641. --*/
  1642. {
  1643. DWORD Quot;
  1644. BOOL Sign;
  1645. if (Sign = (BOOL)(Divisor <= 0L)) {
  1646. if (!(Divisor = -Divisor)) {
  1647. return(Dividend); // can not divide by 0, return as 1
  1648. }
  1649. }
  1650. if (Dividend <= 0L) {
  1651. if (Dividend = -Dividend) {
  1652. Sign = (BOOL)!Sign;
  1653. } else {
  1654. return(FD6_0); // nothing to divide, so return 0
  1655. }
  1656. }
  1657. Quot = ((DWORD)Dividend + (DWORD)((DWORD)Divisor >> 1)) / (DWORD)Divisor;
  1658. return((Sign) ? -(FD6)Quot : (FD6)Quot);
  1659. }
  1660. FD6
  1661. HTENTRY
  1662. MulDivFD6Pairs(
  1663. PMULDIVPAIR pMulDivPair
  1664. )
  1665. /*++
  1666. Routine Description:
  1667. This function multiply TotalFD6Pairs of FD6 numbers and optional divide by
  1668. passed divisor.
  1669. Arguments:
  1670. pMulDivPair - Pointer to array of MULDIVPAIR data structure, the first
  1671. structure in the array tell the count of the FD6 pairs,
  1672. a Divisor present flag and a Divisor, the FD6 pairs start
  1673. from second element in the array.
  1674. Return Value:
  1675. The return value is the 32-bit FD6 number which is round up from 7th
  1676. decimal points, there is no remainder returned.
  1677. NO ERROR returned, if divisor is zero then it assume no divisor is present,
  1678. if Count of FD6 pairs is zero then it return FD6_0
  1679. Author:
  1680. 27-Aug-1992 Thu 18:13:55 updated -by- Daniel Chou (danielc)
  1681. Re-write to remove variable argument conflict, and make it only passed
  1682. a pointer to the MULDIVPAIR structure array
  1683. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1684. Revision History:
  1685. --*/
  1686. {
  1687. FD6 Multiplicand;
  1688. FD6 Multiplier;
  1689. FD6 Divisor;
  1690. DWORD xH;
  1691. DWORD xL;
  1692. DWORD xPH;
  1693. DWORD xPL;
  1694. DWORD Result;
  1695. BOOL Sign;
  1696. INT cFD6Pairs;
  1697. if (!(cFD6Pairs = (INT)pMulDivPair->Pair1.Info.Size)) {
  1698. return(FD6_0);
  1699. }
  1700. Divisor = FD6_0;
  1701. if (pMulDivPair->Pair1.Info.Flag & MULDIV_HAS_DIVISOR) {
  1702. if ((Divisor = pMulDivPair->Pair2) == FD6_1) {
  1703. Divisor = FD6_0;
  1704. }
  1705. }
  1706. xH = xL = (DWORD)0;
  1707. while (cFD6Pairs--) {
  1708. ++pMulDivPair;
  1709. Multiplicand = pMulDivPair->Pair1.Mul;
  1710. Multiplier = pMulDivPair->Pair2;
  1711. if (Sign = (BOOL)(Multiplicand <= 0L)) {
  1712. if (!(Multiplicand = -Multiplicand)) {
  1713. continue; // this one will be zero, check next pair
  1714. }
  1715. }
  1716. if (Multiplier <= 0L) {
  1717. if (Multiplier = -Multiplier) {
  1718. Sign = (BOOL)!Sign;
  1719. } else {
  1720. continue; // this one will be zero, check next pair
  1721. }
  1722. }
  1723. U32xU32_U64(Multiplicand, Multiplier, xPH, xPL);
  1724. if (Sign) {
  1725. NEG_U64(xPH, xPL);
  1726. }
  1727. U64AddU64(xH, xL, xPH, xPL);
  1728. }
  1729. if (Sign = (BOOL)((LONG)xH < 0)) {
  1730. NEG_U64(xH, xL);
  1731. }
  1732. if (Divisor) {
  1733. if (Divisor < FD6_0) {
  1734. Divisor = -Divisor;
  1735. Sign = !Sign;
  1736. }
  1737. Result = U64DivU32RoundUp(xH, xL, (DWORD)Divisor);
  1738. } else {
  1739. //
  1740. // No Divisor, so just divide it by FD6_1
  1741. //
  1742. U64DivFD6_1(xH, xL, Result);
  1743. }
  1744. return((Sign) ? -(FD6)Result : (FD6)Result);
  1745. }
  1746. FD6
  1747. HTENTRY
  1748. FractionToMantissa(
  1749. FD6 Fraction,
  1750. DWORD CorrectData
  1751. )
  1752. /*++
  1753. Routine Description:
  1754. This function take decimal fraction and correct the logarithm mantissa
  1755. between x.xxyyyy x.xxzzzz, where fraction is laid between yyyy to zzzz.
  1756. Arguments:
  1757. Fraction - the fraction number after decimal place, because
  1758. we have mantissa table up to two decimal places, the
  1759. correction is necessary because logarithm numbers are
  1760. no linear. The number is range from 0.000000-0.999999
  1761. CorrectData - The correction data which from MantissaCorrectData[]
  1762. Return Value:
  1763. No error returned, the return value is the Mantissa value for the fraction
  1764. passed in.
  1765. Author:
  1766. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1767. Revision History:
  1768. --*/
  1769. {
  1770. DWORD Mantissa;
  1771. DWORD Rem;
  1772. INT Loop;
  1773. WORD Base;
  1774. WORD Error;
  1775. WORD NextErr;
  1776. WORD CorrL;
  1777. WORD CorrH;
  1778. //
  1779. // Mantissa Correction Data Bits Usage:
  1780. //
  1781. //
  1782. // <---High Word---> <----Low Word--->
  1783. // Bit# 3 2 1 0
  1784. // 10987654 32109876 54321098 76543210
  1785. // | | | | | | | || | |
  1786. // | | | | | | | || | +-- x.000 Minimum Difference
  1787. // | | | | | | | || +----- x.001-x.002 (0-7) Correct 1
  1788. // | | | | | | | |+-------- x.000-x.001 (0-7) Correct 2
  1789. // | | | | | | | +--------- x.009-y.000 (0-1) Correct 10
  1790. // | | | | | | +------------- x.009-y.000 (0-7) Correct 3
  1791. // | | | | | +---------------- x.008-x.009 (0-7) Correct 4
  1792. // | | | | +------------------ x.007-x.008 (0-3) Correct 5
  1793. // | | | +--------------------- x.006-x.007 (0-3) Correct 6
  1794. // | | +----------------------- x.005-x.006 (0-3) Correct 7
  1795. // | +------------------------- x.004-x.005 (0-3) Correct 8
  1796. // +--------------------------- x.003-x.004 (0-3) Correct 9
  1797. //
  1798. CorrL = U16_L_U32(CorrectData);
  1799. CorrH = U16_H_U32(CorrectData);
  1800. Rem = (DWORD)(Fraction % 100000L);
  1801. Loop = (INT)(Fraction / 100000L);
  1802. Base = (WORD)(CorrL & 0x1ff);
  1803. Error = 0;
  1804. NextErr = (WORD)(Base + ((CorrL >>= 9) & 0x07));
  1805. if (Loop--) {
  1806. Error += NextErr;
  1807. //
  1808. // bit 6, 0x40 = correct 10
  1809. //
  1810. NextErr = (WORD)(Base + ((CorrL >> 3) & 0x07));
  1811. if (Loop--) {
  1812. Error += NextErr;
  1813. NextErr = (WORD)(Base + (CorrH & 0x07));
  1814. if (Loop--) {
  1815. Error += NextErr;
  1816. NextErr = (WORD)(Base + ((CorrH >>= 3) & 0x07));
  1817. if (CorrL & 0x40) {
  1818. CorrH |= 0x2000; // add in correction 10
  1819. }
  1820. CorrH >>= 1; // pre-shift for next while
  1821. while (Loop--) {
  1822. Error += NextErr;
  1823. NextErr = (WORD)(Base + ((CorrH >>= 2) & 0x03));
  1824. }
  1825. }
  1826. }
  1827. }
  1828. Mantissa = (DWORD)Error +
  1829. ((((Rem * (DWORD)NextErr) >> 1) + 25000L) / 50000L);
  1830. return(FD6FromL(Mantissa));
  1831. }
  1832. FD6
  1833. HTENTRY
  1834. MantissaToFraction(
  1835. FD6 Mantissa,
  1836. DWORD CorrectData
  1837. )
  1838. /*++
  1839. Routine Description:
  1840. This function take mantissa number and convert it to the decimal fraction
  1841. Arguments:
  1842. Mantissa - the mantissa values which will converted to the the
  1843. fraction number.
  1844. CorrectData - The correction data which from MantissaCorrectData[]
  1845. Return Value:
  1846. No error returned, the return value is the fraction value for the mantissa
  1847. passed in, it range from 0.000000 - 1.000000
  1848. Author:
  1849. 10-Oct-1991 Thu 11:14:24 created -by- Daniel Chou (danielc)
  1850. Revision History:
  1851. --*/
  1852. {
  1853. static DWORD ul100000To900000[] = { 100000L, 200000L, 300000L, 400000L,
  1854. 500000L, 600000L, 700000L, 800000L,
  1855. 900000L
  1856. };
  1857. DWORD Fraction;
  1858. SHORT Index;
  1859. SHORT Base;
  1860. SHORT Error;
  1861. SHORT NextErr;
  1862. WORD CorrL;
  1863. WORD CorrH;
  1864. //
  1865. // Mantissa Correction Data Bits Usage:
  1866. //
  1867. //
  1868. // <---High Word---> <----Low Word--->
  1869. // Bit# 3 2 1 0
  1870. // 10987654 32109876 54321098 76543210
  1871. // | | | | | | | || | |
  1872. // | | | | | | | || | +-- x.000 Minimum Difference
  1873. // | | | | | | | || +----- x.001-x.002 (0-7) Correct 1
  1874. // | | | | | | | |+-------- x.000-x.001 (0-7) Correct 2
  1875. // | | | | | | | +--------- x.009-y.000 (0-1) Correct 10
  1876. // | | | | | | +------------- x.009-y.000 (0-7) Correct 3
  1877. // | | | | | +---------------- x.008-x.009 (0-7) Correct 4
  1878. // | | | | +------------------ x.007-x.008 (0-3) Correct 5
  1879. // | | | +--------------------- x.006-x.007 (0-3) Correct 6
  1880. // | | +----------------------- x.005-x.006 (0-3) Correct 7
  1881. // | +------------------------- x.004-x.005 (0-3) Correct 8
  1882. // +--------------------------- x.003-x.004 (0-3) Correct 9
  1883. //
  1884. Error = (SHORT)FD6ToL(Mantissa); // only need 16 bits
  1885. CorrL = U16_L_U32(CorrectData);
  1886. CorrH = U16_H_U32(CorrectData);
  1887. Base = (SHORT)(CorrL & 0x1ff);
  1888. Fraction = 0L;
  1889. Index = 1; // assume 1
  1890. NextErr = (WORD)(Base + ((CorrL >>= 9) & 0x07));
  1891. if ((Error -= NextErr) > 0) {
  1892. ++Index;
  1893. //
  1894. // bit 6, 0x40 = correct 10
  1895. //
  1896. NextErr = (WORD)(Base + ((CorrL >> 3) & 0x07));
  1897. if ((Error -= NextErr) > 0) {
  1898. ++Index;
  1899. NextErr = (WORD)(Base + (CorrH & 0x07));
  1900. if ((Error -= NextErr) > 0) {
  1901. ++Index;
  1902. NextErr = (WORD)(Base + ((CorrH >>= 3) & 0x07));
  1903. if (CorrL & 0x40) {
  1904. CorrH |= 0x2000; // add in correction 10
  1905. }
  1906. CorrH >>= 1; // pre-shift for next while
  1907. while ((Error -= NextErr) > 0) {
  1908. ++Index;
  1909. NextErr = (WORD)(Base + ((CorrH >>= 2) & 0x03));
  1910. }
  1911. }
  1912. }
  1913. }
  1914. if (Error) {
  1915. --Index;
  1916. Fraction = (((((DWORD)(Error + NextErr) * 50000L) << 1) +
  1917. (DWORD)(NextErr >> 1)) / (DWORD)NextErr);
  1918. }
  1919. if (Index--) {
  1920. Fraction += ul100000To900000[Index];
  1921. }
  1922. return(FD6FromL(Fraction));
  1923. }
  1924. DWORD
  1925. HTENTRY
  1926. ComputeChecksum(
  1927. LPBYTE pData,
  1928. DWORD InitialChecksum,
  1929. DWORD DataSize
  1930. )
  1931. /*++
  1932. Routine Description:
  1933. This function compute a 32-bit check sum for the pData passed in
  1934. Arguments:
  1935. pData - Pointer to data which checksum to be computed
  1936. InitChecksum - Initial checksum value, this value can be a checksum
  1937. value from last computed result, so it can generate a
  1938. single checksum from a large linked data.
  1939. DataSize - pData size in bytes
  1940. The Checksum is forming by two 16-bit checksum octets R,S and n is the
  1941. octet number, the addition is performed in one's complement arithmic.
  1942. S(n) = S(n-1) + Data(n)
  1943. R(n) = R(n-1) + S(n)
  1944. Checksum = (DWORD)(R << 16) | (DWORDS;
  1945. Return Value:
  1946. return value is a 32-bit checksum
  1947. Author:
  1948. 27-Apr-1992 Mon 18:36:03 created -by- Daniel Chou (danielc)
  1949. Revision History:
  1950. --*/
  1951. {
  1952. W2B w2b;
  1953. WORD OctetR;
  1954. WORD OctetS;
  1955. //
  1956. // We using two 16-bit checksum octets with one's complement arithmic
  1957. //
  1958. //
  1959. // 1. Get initial values for OctetR and OctetS
  1960. //
  1961. OctetR = HIWORD(InitialChecksum);
  1962. OctetS = LOWORD(InitialChecksum);
  1963. //
  1964. // 2. Since we doing 16-bit at a time, we will pack high byte with zero
  1965. // if data size in bytes is odd number
  1966. //
  1967. if (DataSize & 0x01) {
  1968. OctetR += (OctetS += (WORD)*pData++);
  1969. }
  1970. //
  1971. // 3. Now forming checksum 16-bit at a time
  1972. //
  1973. DataSize >>= 1;
  1974. while (DataSize--) {
  1975. w2b.b[0] = *pData++;
  1976. w2b.b[1] = *pData++;
  1977. OctetR += (OctetS += w2b.w);
  1978. }
  1979. return((DWORD)((DWORD)OctetR << 16) | (DWORD)OctetS);
  1980. }
  1981. #endif // HT_OK_GEN_80x86_CODES