blitz_cclib.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #ifndef BLITZ_CCLIB_H
  2. #define BLITZ_CCLIB_H
  3. #include "blitz_types.h"
  4. #include <math.h>
  5. #ifdef __cplusplus
  6. extern "C"{
  7. #endif
  8. #define bbPOSNANf (0.0f/0.0f)
  9. #define bbPOSNANd (0.0/0.0)
  10. #define bbNEGNANf (-0.0f/0.0f)
  11. #define bbNEGNANd (-0.0/0.0)
  12. #define bbPOSINFf (1.0f/0.0f)
  13. #define bbPOSINFd (1.0/0.0)
  14. #define bbNEGINFf (-1.0f/0.0f)
  15. #define bbNEGINFd (-1.0/0.0)
  16. #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  17. inline int bbIntAbs( int x ){
  18. return x>=0 ? x : -x;
  19. }
  20. inline int bbIntSgn( int x ){
  21. return x==0 ? 0 : (x>0 ? 1 : -1);
  22. }
  23. inline int bbIntMod( int x,int y ){
  24. return x % y;
  25. }
  26. inline int bbIntMin( int x,int y ){
  27. return x<y ? x : y;
  28. }
  29. inline int bbIntMax( int x,int y ){
  30. return x>y ? x : y;
  31. }
  32. inline void bbIntToLong( BBInt64 *r,int x ){
  33. *r=x;
  34. }
  35. inline double bbFloatAbs( double x ){
  36. return fabs( x );
  37. }
  38. inline double bbFloatSgn( double x ){
  39. return x==0 ? 0 : (x>0 ? 1 : -1);
  40. }
  41. inline double bbFloatPow( double x,double y ){
  42. return pow(x,y);
  43. }
  44. inline double bbFloatMod( double x,double y ){
  45. return fmod( x,y );
  46. }
  47. inline double bbFloatMin( double x,double y ){
  48. return x<y ? x : y;
  49. }
  50. inline double bbFloatMax( double x,double y ){
  51. return x>y ? x : y;
  52. }
  53. inline void bbFloatToLong( BBInt64 *r,double x ){
  54. *r=x;
  55. }
  56. inline BBInt64 bbLongNeg( BBInt64 x ){
  57. return -x;
  58. }
  59. inline BBInt64 bbLongNot( BBInt64 x ){
  60. return ~x;
  61. }
  62. inline BBInt64 bbLongAbs( BBInt64 x ){
  63. return x>=0 ? x : -x;
  64. }
  65. inline BBInt64 bbLongSgn( BBInt64 x ){
  66. return x>0 ? 1 : (x<0 ? -1 : 0);
  67. }
  68. inline void bbLongAdd( BBInt64 *r,BBInt64 x,BBInt64 y ){
  69. *r=x+y;
  70. }
  71. inline void bbLongSub( BBInt64 *r,BBInt64 x,BBInt64 y ){
  72. *r=x-y;
  73. }
  74. inline void bbLongMul( BBInt64 *r,BBInt64 x,BBInt64 y ){
  75. *r=x*y;
  76. }
  77. inline void bbLongDiv( BBInt64 *r,BBInt64 x,BBInt64 y ){
  78. *r=x/y;
  79. }
  80. inline void bbLongMod( BBInt64 *r,BBInt64 x,BBInt64 y ){
  81. *r=x%y;
  82. }
  83. inline BBInt64 bbLongMin( BBInt64 x,BBInt64 y ){
  84. return x<y ? x : y;
  85. }
  86. inline BBInt64 bbLongMax( BBInt64 x,BBInt64 y ){
  87. return x>y ? x : y;
  88. }
  89. inline void bbLongAnd( BBInt64 *r,BBInt64 x,BBInt64 y ){
  90. *r=x&y;
  91. }
  92. inline void bbLongOrl( BBInt64 *r,BBInt64 x,BBInt64 y ){
  93. *r=x|y;
  94. }
  95. inline void bbLongXor( BBInt64 *r,BBInt64 x,BBInt64 y ){
  96. *r=x^y;
  97. }
  98. inline void bbLongShl( BBInt64 *r,BBInt64 x,BBInt64 y ){
  99. *r=x<<y;
  100. }
  101. inline void bbLongShr( BBInt64 *r,BBInt64 x,BBInt64 y ){
  102. *r=(BBUInt64)x>>(BBUInt64)y;
  103. }
  104. inline void bbLongSar( BBInt64 *r,BBInt64 x,BBInt64 y ){
  105. *r=x>>y;
  106. }
  107. inline int bbLongSlt( BBInt64 x,BBInt64 y ){
  108. return x<y;
  109. }
  110. inline int bbLongSgt( BBInt64 x,BBInt64 y ){
  111. return x>y;
  112. }
  113. inline int bbLongSle( BBInt64 x,BBInt64 y ){
  114. return x<=y;
  115. }
  116. inline int bbLongSge( BBInt64 x,BBInt64 y ){
  117. return x>=y;
  118. }
  119. inline int bbLongSeq( BBInt64 x,BBInt64 y ){
  120. return x==y;
  121. }
  122. inline int bbLongSne( BBInt64 x,BBInt64 y ){
  123. return x!=y;
  124. }
  125. inline double bbLongToFloat( BBInt64 x ){
  126. return (double)x;
  127. }
  128. inline BBSIZET bbSizetAbs( BBSIZET x ){
  129. return x>=0 ? x : -x;
  130. }
  131. inline BBSIZET bbSizetSgn( BBSIZET x ){
  132. return x==0 ? 0 : (x>0 ? 1 : -1);
  133. }
  134. inline BBSIZET bbSizetMin( BBSIZET x,BBSIZET y ){
  135. return x<y ? x : y;
  136. }
  137. inline BBSIZET bbSizetMax( BBSIZET x,BBSIZET y ){
  138. return x>y ? x : y;
  139. }
  140. inline BBUINT bbUIntAbs( BBUINT x ){
  141. return x>=0 ? x : -x;
  142. }
  143. inline BBUINT bbUIntSgn( BBUINT x ){
  144. return x==0 ? 0 : (x>0 ? 1 : -1);
  145. }
  146. inline BBUINT bbUIntMin( BBUINT x,BBUINT y ){
  147. return x<y ? x : y;
  148. }
  149. inline BBUINT bbUIntMax( BBUINT x,BBUINT y ){
  150. return x>y ? x : y;
  151. }
  152. inline BBULONG bbULongAbs( BBULONG x ){
  153. return x>=0 ? x : -x;
  154. }
  155. inline BBULONG bbULongSgn( BBULONG x ){
  156. return x==0 ? 0 : (x>0 ? 1 : -1);
  157. }
  158. inline BBULONG bbULongMin( BBULONG x,BBULONG y ){
  159. return x<y ? x : y;
  160. }
  161. inline BBULONG bbULongMax( BBULONG x,BBULONG y ){
  162. return x>y ? x : y;
  163. }
  164. #else
  165. int bbIntAbs( int x );
  166. int bbIntSgn( int x );
  167. int bbIntMod( int x,int y );
  168. void bbIntToLong( BBInt64 *r,int x );
  169. double bbFloatAbs( double x );
  170. double bbFloatSgn( double x );
  171. double bbFloatPow( double x,double y );
  172. double bbFloatMod( double x,double y );
  173. int bbFloatToInt( double x );
  174. void bbFloatToLong( BBInt64 *r,double x );
  175. BBInt64 bbLongNeg( BBInt64 x );
  176. BBInt64 bbLongNot( BBInt64 x );
  177. BBInt64 bbLongAbs( BBInt64 x );
  178. BBInt64 bbLongSgn( BBInt64 x );
  179. void bbLongAdd( BBInt64 *r,BBInt64 x,BBInt64 y );
  180. void bbLongSub( BBInt64 *r,BBInt64 x,BBInt64 y );
  181. void bbLongMul( BBInt64 *r,BBInt64 x,BBInt64 y );
  182. void bbLongDiv( BBInt64 *r,BBInt64 x,BBInt64 y );
  183. void bbLongMod( BBInt64 *r,BBInt64 x,BBInt64 y );
  184. void bbLongAnd( BBInt64 *r,BBInt64 x,BBInt64 y );
  185. void bbLongOrl( BBInt64 *r,BBInt64 x,BBInt64 y );
  186. void bbLongXor( BBInt64 *r,BBInt64 x,BBInt64 y );
  187. void bbLongShl( BBInt64 *r,BBInt64 x,BBInt64 y );
  188. void bbLongShr( BBInt64 *r,BBInt64 x,BBInt64 y );
  189. void bbLongSar( BBInt64 *r,BBInt64 x,BBInt64 y );
  190. int bbLongSlt( BBInt64 x,BBInt64 y );
  191. int bbLongSgt( BBInt64 x,BBInt64 y );
  192. int bbLongSle( BBInt64 x,BBInt64 y );
  193. int bbLongSge( BBInt64 x,BBInt64 y );
  194. int bbLongSeq( BBInt64 x,BBInt64 y );
  195. int bbLongSne( BBInt64 x,BBInt64 y );
  196. double bbLongToFloat( BBInt64 x );
  197. BBSIZET bbSizetSgn( BBSIZET x );
  198. BBSIZET bbSizetAbs( BBSIZET x );
  199. BBUINT bbUIntSgn( BBUINT x );
  200. BBUINT bbUIntAbs( BBUINT x );
  201. BBULONG bbULongSgn( BBULONG x );
  202. BBULONG bbULongAbs( BBULONG x );
  203. #endif
  204. BBLONG bbLongPow(BBLONG base, BBBYTE exp);
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208. #endif