Advertisement
Guest User

Untitled

a guest
Sep 4th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. /**********************************************************************************************************************************
  2. * *
  3. * )( Unsigned Long 61 Bit [Long Yoyo] )( *
  4. * *
  5. * Copyright � 2018 Abyss Morgan. All rights reserved. *
  6. * *
  7. * Website: adm.ct8.pl *
  8. * Download: adm.ct8.pl/r/download *
  9. * *
  10. * Plugins: None *
  11. * Modules: None *
  12. * *
  13. * File Version: 1.6.1 *
  14. * *
  15. * Pawn Unsigned Long for 32 Bit language (precision 61-bit) *
  16. * Available limit: *
  17. * 0 - 2 147 483 647 000 000 000 *
  18. * 0 - 2 000 000 000 000 000 000 *
  19. * *
  20. * Functions: *
  21. * IsValueContainLY(prefix,suffix,value); *
  22. * GetLYString(prefix,suffix,string[],maxdest = sizeof(string)); *
  23. * LYStringToLY(&prefix,&suffix,string[]); //Reverse to GetLYString *
  24. * UpdateLY(&prefix,&suffix,value,limitprefix = DEFAULT_MAX_LY_PREFIX); *
  25. * AddSeparatorLY(string[],separator[]); *
  26. * DeleteSeparatorLY(string[],separator[]); *
  27. * CalculatePercentLY(&prefix,&suffix,Float:percent = 0.0,increase = true,limitprefix = DEFAULT_MAX_LY_PREFIX); *
  28. * GetPercentLY(prefix,suffix,&o_prefix,&o_suffix,Float:percent = 0.0,limitprefix = DEFAULT_MAX_LY_PREFIX); *
  29. * *
  30. * Operators: *
  31. * IsLYEqual(prefix,suffix,from_prefix,from_suffix); *
  32. * IsLYSmallerThan(prefix,suffix,from_prefix,from_suffix); *
  33. * IsLYSmallerThanOrEqual(prefix,suffix,from_prefix,from_suffix); *
  34. * IsLYBiggerThan(prefix,suffix,from_prefix,from_suffix); *
  35. * IsLYBiggerThanOrEqual(prefix,suffix,from_prefix,from_suffix); *
  36. * *
  37. **********************************************************************************************************************************/
  38.  
  39. /*
  40. //Check Version LY.inc
  41. #if !defined _Long_Yoyo
  42. #error [ADM] You need LY.inc v1.6.1
  43. #elseif !defined Long_Yoyo_Version
  44. #error [ADM] Update you LY.inc to v1.6.1
  45. #elseif (Long_Yoyo_Version < 10601)
  46. #error [ADM] Update you LY.inc to v1.6.1
  47. #endif
  48. */
  49.  
  50. #if defined _Long_Yoyo
  51. #endinput
  52. #endif
  53. #define _Long_Yoyo
  54.  
  55. #define Long_Yoyo_Version (10601) //a.b.c 10000*a+100*b+c
  56.  
  57. #define LY_STRING_LEN (20)
  58. #define SEP_LY_STRING_LEN (LY_STRING_LEN+10)
  59. #define MAX_LY_STRING (LY_STRING_LEN)
  60. #define MAX_SEP_LY_STRING (SEP_LY_STRING_LEN)
  61.  
  62. #define MAX_LY_PREFIX (2147483647)
  63. #define DEFAULT_MAX_LY_PREFIX (2000000000)
  64.  
  65. stock IsValueContainLY(prefix,suffix,value){
  66. if((prefix == 0) && (suffix == 0)) return false;
  67. if((suffix < value) && (prefix == 0)) return false;
  68. return true;
  69. }
  70.  
  71. stock GetLYString(prefix,suffix,string[],maxdest = sizeof(string)){
  72. if(prefix == 0){
  73. format(string,maxdest,"%d",suffix);
  74. } else {
  75. format(string,maxdest,"%d%09d",prefix,suffix);
  76. }
  77. }
  78.  
  79. //Pawn Unsigned Long for 32 Bit language (precision 61-bit)
  80. stock UpdateLY(&prefix,&suffix,value,limitprefix = DEFAULT_MAX_LY_PREFIX){
  81. if(value == 0) return 1; //skip
  82.  
  83. new tmp = value;
  84.  
  85. if((tmp > 0) && (prefix >= limitprefix) && (suffix >= 0)){
  86. prefix = limitprefix;
  87. suffix = 0;
  88. } else if((tmp > 0) && (prefix >= limitprefix-1) && (suffix >= 999999999)){
  89. prefix = limitprefix;
  90. suffix = 0;
  91. } else if((tmp > 0) && (prefix >= limitprefix) && (suffix >= 999999999)){
  92. prefix = limitprefix;
  93. suffix = 0;
  94. } else {
  95. if(value >= 0){
  96. while(tmp >= 1000000000){
  97. tmp -= 1000000000;
  98. prefix += 1;
  99. }
  100. suffix += tmp;
  101. while(suffix > 999999999){
  102. suffix -= 1000000000;
  103. prefix += 1;
  104. }
  105. } else if(value < 0){
  106. while(tmp <= -1000000000){
  107. prefix -= 1;
  108. tmp += 1000000000;
  109. }
  110. suffix += (tmp);
  111. while(suffix < 0){
  112. suffix += 1000000000;
  113. prefix -= 1;
  114. }
  115. if(prefix < 0){
  116. prefix = 0;
  117. suffix = 0;
  118. }
  119. }
  120. }
  121. if((prefix >= limitprefix) && (suffix >= 0)){
  122. prefix = limitprefix;
  123. suffix = 0;
  124. }
  125. return 1;
  126. }
  127.  
  128. stock AddSeparatorLY(string[],separator[]){
  129. new tStr[MAX_SEP_LY_STRING];
  130. format(tStr,sizeof(tStr),"%s",string);
  131.  
  132. if(strlen(tStr) < 4) return tStr;
  133. new iPos = strlen(tStr), iCount = 1;
  134.  
  135. while(iPos > 0){
  136. if(iCount == 4){
  137. iCount = 0;
  138. strins(tStr,separator[0],iPos,1);
  139. iPos++;
  140. }
  141. iCount++;
  142. iPos--;
  143. }
  144. return tStr;
  145. }
  146.  
  147. stock DeleteSeparatorLY(string[],separator[]){
  148. new tStr[MAX_LY_STRING], idx = 0;
  149. for(new i = 0, j = strlen(string); i < j ; i++){
  150. if(string[i] != separator[0]){
  151. tStr[idx] = string[i];
  152. idx++;
  153. }
  154. }
  155. return tStr;
  156. }
  157.  
  158. stock CalculatePercentLY(&prefix,&suffix,Float:percent = 0.0,bool:increase = true,limitprefix = DEFAULT_MAX_LY_PREFIX){
  159. new Float:lycut = (prefix*(percent/100.0)),
  160. modify_p = floatround(lycut),
  161. modify_s = floatround((lycut-modify_p)*100000) * 10000;
  162.  
  163. if(increase){
  164. prefix += modify_p;
  165. UpdateLY(prefix,suffix,modify_s,limitprefix);
  166. modify_s = floatround(suffix*(percent/100.0));
  167. UpdateLY(prefix,suffix,modify_s,limitprefix);
  168. } else {
  169. prefix -= modify_p;
  170. UpdateLY(prefix,suffix,-modify_s,limitprefix);
  171. modify_s = floatround(suffix*(percent/100.0));
  172. UpdateLY(prefix,suffix,-modify_s,limitprefix);
  173. }
  174. }
  175.  
  176. stock GetPercentLY(prefix,suffix,&o_prefix,&o_suffix,Float:percent = 0.0,limitprefix = DEFAULT_MAX_LY_PREFIX){
  177. o_suffix = 0, o_prefix = 0;
  178.  
  179. new Float:lycut = (prefix*(percent/100.0)),
  180. modify_p = floatround(lycut),
  181. modify_s = floatround((lycut-modify_p)*100000) * 10000;
  182.  
  183. o_prefix += modify_p;
  184. UpdateLY(o_prefix,o_suffix,modify_s,limitprefix);
  185. modify_s = floatround(suffix*(percent/100.0));
  186. UpdateLY(o_prefix,o_suffix,modify_s,limitprefix);
  187.  
  188. }
  189.  
  190. //Operator a == b
  191. stock IsLYEqual(prefix,suffix,from_prefix,from_suffix){
  192. if(prefix == from_prefix && suffix == from_suffix) return true;
  193. return false;
  194. }
  195.  
  196. //Operator a < b
  197. stock IsLYSmallerThan(prefix,suffix,from_prefix,from_suffix){
  198. if(prefix < from_prefix) return true;
  199. if(prefix == from_prefix && suffix < from_suffix) return true;
  200. return false;
  201. }
  202.  
  203. //Operator a <= b
  204. stock IsLYSmallerThanOrEqual(prefix,suffix,from_prefix,from_suffix){
  205. if(prefix <= from_prefix) return true;
  206. if(prefix == from_prefix && suffix <= from_suffix) return true;
  207. return false;
  208. }
  209.  
  210. //Operator a > b
  211. stock IsLYBiggerThan(prefix,suffix,from_prefix,from_suffix){
  212. if(prefix > from_prefix) return true;
  213. if(prefix == from_prefix && suffix > from_suffix) return true;
  214. return false;
  215. }
  216.  
  217. //Operator a >= b
  218. stock IsLYBiggerThanOrEqual(prefix,suffix,from_prefix,from_suffix){
  219. if(prefix >= from_prefix) return true;
  220. if(prefix == from_prefix && suffix >= from_suffix) return true;
  221. return false;
  222. }
  223.  
  224. //Reverse to GetLYString
  225. stock LYStringToLY(&prefix,&suffix,string[]){
  226. new len = strlen(string);
  227. prefix = 0, suffix = 0;
  228. for(new i = strlen(string)-1; i >= 0; i--){
  229. if(len-i <= 9){
  230. suffix += (string[i]-48)*floatround(floatpower(10,len-i-1));
  231. } else {
  232. prefix += (string[i]-48)*floatround(floatpower(10,len-i-10));
  233. }
  234. }
  235. }
  236.  
  237. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement