home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / largeint.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  5KB  |  258 lines

  1. /*--
  2.  
  3. Module Name:
  4.  
  5.     largeint.h
  6.  
  7. Abstract:
  8.  
  9.     Include file for sample Large Integer Arithmetic routines.  
  10.     This file includes all of the prototypes for the routines found in 
  11.     largeint.lib.  For complete descriptions of these functions, see the
  12.     largeint.s source file for MIPS, or the divlarge.c and largeint.asm 
  13.     source files for x86. 
  14.  
  15. Revision History:
  16.  
  17. --*/
  18.  
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22.  
  23. //
  24. //Large integer arithmetic routines.
  25. //
  26.  
  27. //
  28. // Large integer add - 64-bits + 64-bits -> 64-bits
  29. //
  30.  
  31. LARGE_INTEGER
  32. WINAPI
  33. LargeIntegerAdd (
  34.     LARGE_INTEGER Addend1,
  35.     LARGE_INTEGER Addend2
  36.     );
  37.  
  38. //
  39. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  40. //
  41.  
  42. LARGE_INTEGER
  43. WINAPI
  44. EnlargedIntegerMultiply (
  45.     LONG Multiplicand,
  46.     LONG Multiplier
  47.     );
  48.  
  49. //
  50. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  51. //
  52.  
  53. LARGE_INTEGER
  54. WINAPI
  55. EnlargedUnsignedMultiply (
  56.     ULONG Multiplicand,
  57.     ULONG Multiplier
  58.     );
  59.  
  60. //
  61. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  62. //
  63.  
  64. ULONG
  65. WINAPI
  66. EnlargedUnsignedDivide (
  67.     IN ULARGE_INTEGER Dividend,
  68.     IN ULONG Divisor,
  69.     IN PULONG Remainder
  70.     );
  71.  
  72. //
  73. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  74. //
  75.  
  76. LARGE_INTEGER
  77. WINAPI
  78. ExtendedMagicDivide (
  79.     LARGE_INTEGER Dividend,
  80.     LARGE_INTEGER MagicDivisor,
  81.     CCHAR ShiftCount
  82.     );
  83.  
  84. //
  85. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  86. //
  87.  
  88. LARGE_INTEGER
  89. WINAPI
  90. ExtendedLargeIntegerDivide (
  91.     LARGE_INTEGER Dividend,
  92.     ULONG Divisor,
  93.     PULONG Remainder
  94.     );
  95.  
  96. //
  97. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  98. //
  99.  
  100. LARGE_INTEGER
  101. WINAPI
  102. LargeIntegerDivide (
  103.     LARGE_INTEGER Dividend,
  104.     LARGE_INTEGER Divisor,
  105.     PLARGE_INTEGER Remainder
  106.     );
  107.  
  108. //
  109. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  110. //
  111.  
  112. LARGE_INTEGER
  113. WINAPI
  114. ExtendedIntegerMultiply (
  115.     LARGE_INTEGER Multiplicand,
  116.     LONG Multiplier
  117.     );
  118.  
  119. //
  120. // Large integer negation - -(64-bits)
  121. //
  122.  
  123. LARGE_INTEGER
  124. WINAPI
  125. LargeIntegerNegate (
  126.     LARGE_INTEGER Subtrahend
  127.     );
  128.  
  129. //
  130. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  131. //
  132.  
  133. LARGE_INTEGER
  134. WINAPI
  135. LargeIntegerSubtract (
  136.     LARGE_INTEGER Minuend,
  137.     LARGE_INTEGER Subtrahend
  138.     );
  139.  
  140. //
  141. // Large integer and - 64-bite & 64-bits -> 64-bits.
  142. //
  143.  
  144. #define LargeIntegerAnd(Result, Source, Mask)   \
  145.         {                                           \
  146.             Result.HighPart = Source.HighPart & Mask.HighPart; \
  147.             Result.LowPart = Source.LowPart & Mask.LowPart; \
  148.         }
  149.  
  150.  
  151. //
  152. // Large integer conversion routines.
  153. //
  154.  
  155. //
  156. // Convert signed integer to large integer.
  157. //
  158.  
  159. LARGE_INTEGER
  160. WINAPI
  161. ConvertLongToLargeInteger (
  162.     LONG SignedInteger
  163.     );
  164.  
  165. //
  166. // Convert unsigned integer to large integer.
  167. //
  168.  
  169. LARGE_INTEGER
  170. WINAPI
  171. ConvertUlongToLargeInteger (
  172.     ULONG UnsignedInteger
  173.     );
  174.  
  175.  
  176. //
  177. // Large integer shift routines.
  178. //
  179.  
  180. LARGE_INTEGER
  181. WINAPI
  182. LargeIntegerShiftLeft (
  183.     LARGE_INTEGER LargeInteger,
  184.     CCHAR ShiftCount
  185.     );
  186.  
  187. LARGE_INTEGER
  188. WINAPI
  189. LargeIntegerShiftRight (
  190.     LARGE_INTEGER LargeInteger,
  191.     CCHAR ShiftCount
  192.     );
  193.  
  194. LARGE_INTEGER
  195. WINAPI
  196. LargeIntegerArithmeticShift (
  197.     LARGE_INTEGER LargeInteger,
  198.     CCHAR ShiftCount
  199.     );
  200.  
  201. #define LargeIntegerGreaterThan(X,Y) (                              \
  202.     (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  203.     ((X).HighPart > (Y).HighPart)                                      \
  204. )
  205.  
  206. #define LargeIntegerGreaterThanOrEqualTo(X,Y) (                      \
  207.     (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  208.     ((X).HighPart > (Y).HighPart)                                       \
  209. )
  210.  
  211. #define LargeIntegerEqualTo(X,Y) (                              \
  212.     !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  213. )
  214.  
  215. #define LargeIntegerNotEqualTo(X,Y) (                          \
  216.     (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  217. )
  218.  
  219. #define LargeIntegerLessThan(X,Y) (                                 \
  220.     (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  221.     ((X).HighPart < (Y).HighPart)                                      \
  222. )
  223.  
  224. #define LargeIntegerLessThanOrEqualTo(X,Y) (                         \
  225.     (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  226.     ((X).HighPart < (Y).HighPart)                                       \
  227. )
  228.  
  229. #define LargeIntegerGreaterThanZero(X) (       \
  230.     (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  231.     ((X).HighPart > 0 )                           \
  232. )
  233.  
  234. #define LargeIntegerGreaterOrEqualToZero(X) ( \
  235.     (X).HighPart >= 0                            \
  236. )
  237.  
  238. #define LargeIntegerEqualToZero(X) ( \
  239.     !((X).LowPart | (X).HighPart)       \
  240. )
  241.  
  242. #define LargeIntegerNotEqualToZero(X) ( \
  243.     ((X).LowPart | (X).HighPart)           \
  244. )
  245.  
  246. #define LargeIntegerLessThanZero(X) ( \
  247.     ((X).HighPart < 0)                   \
  248. )
  249.  
  250. #define LargeIntegerLessOrEqualToZero(X) (           \
  251.     ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  252. )
  253.  
  254. #ifdef __cplusplus
  255. }
  256. #endif
  257.  
  258.