MyBigLong.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const a = [
  6. "",
  7. "K",
  8. "M",
  9. "B",
  10. "T",
  11. "aa",
  12. "ab",
  13. "ac",
  14. "ad",
  15. "ae",
  16. "af",
  17. "ag",
  18. "ah",
  19. "ai",
  20. "aj",
  21. "ak",
  22. "al",
  23. "am",
  24. "an",
  25. "ao",
  26. "ap",
  27. "aq",
  28. "ar",
  29. "as",
  30. "at",
  31. "au",
  32. "av",
  33. "aw",
  34. "ax",
  35. "ay",
  36. "az",
  37. "ba",
  38. "bb",
  39. "bc",
  40. "bd",
  41. "be",
  42. "bf",
  43. "bg",
  44. "bh",
  45. "bi",
  46. "bj",
  47. "bk",
  48. "bl",
  49. "bm",
  50. "bn",
  51. "bo",
  52. "bp",
  53. "bq",
  54. "br",
  55. "bs",
  56. "bt",
  57. "bu",
  58. "bv",
  59. "bw",
  60. "bx",
  61. "by",
  62. "bz",
  63. "ca",
  64. "cb",
  65. "cc",
  66. "cd",
  67. "ce",
  68. "cf",
  69. "cg",
  70. "ch",
  71. "ci",
  72. "cj",
  73. "ck",
  74. "cl",
  75. "cm",
  76. "cn",
  77. "co",
  78. "cp",
  79. "cq",
  80. "cr",
  81. "cs",
  82. "ct",
  83. "cu",
  84. "cv",
  85. "cw",
  86. "cx",
  87. "cy",
  88. "cz"
  89. ];
  90. class s {
  91. constructor() {
  92. (this.value = 0), (this._numberStr = "");
  93. }
  94. init(t, e) {
  95. return t instanceof s ? this.initByBigNum(t) : this.initByNumber(t, e);
  96. }
  97. initByNumber(t, e) {
  98. return (this._numberStr = ""), (this.value = t * Math.pow(10, e)), this;
  99. }
  100. initByBigNum(t) {
  101. return (this._numberStr = ""), (this.value = t.value), this;
  102. }
  103. static create(t, e) {
  104. let i = s.pool.pop();
  105. return (i = i || new s()), t instanceof s ? i.initByBigNum(t) : i.initByNumber(t, e), i;
  106. }
  107. release() {
  108. s.pool.push(this);
  109. }
  110. divide(t) {
  111. return (
  112. (this.value = "number" == typeof t ? Math.floor(this.value / t) : Math.floor(this.value / t.value)),
  113. (this._numberStr = ""),
  114. this
  115. );
  116. }
  117. divideBigLong(t) {
  118. return this.value / t.value;
  119. }
  120. cmp(t) {
  121. return "number" == typeof t ? this.value - t : this.value - t.value;
  122. }
  123. add(t) {
  124. return (
  125. (this.value = "number" == typeof t ? Math.floor(this.value + t) : Math.floor(this.value + t.value)),
  126. (this._numberStr = ""),
  127. this
  128. );
  129. }
  130. sub(t) {
  131. return (
  132. (this.value = "number" == typeof t ? Math.floor(this.value - t) : Math.floor(this.value - t.value)),
  133. (this._numberStr = ""),
  134. this
  135. );
  136. }
  137. static toString(o) {
  138. if (o < 1e3) return Math.floor(o) + "";
  139. {
  140. let t = o.toPrecision(3),
  141. e = t.split("e+"),
  142. i = parseInt(e[1]),
  143. s = i % 3;
  144. return (
  145. (i -= s),
  146. s < 2
  147. ? (t = t.replace(".", "")).slice(0, 1 + s) + "." + t.slice(1 + s, 3) + a[i / 3]
  148. : t.replace(".", "").slice(0, 1 + s) + a[i / 3]
  149. );
  150. }
  151. }
  152. static unpackData(t) {
  153. var e = t.match(/(-?)([\d.]+)([a-z]{2}|M|K|T|B)?/);
  154. if (e) {
  155. if (e[3]) {
  156. t = a.indexOf(e[3]);
  157. return parseFloat(e[2]) * Math.pow(10, 3 * t);
  158. }
  159. return parseFloat(e[2]);
  160. }
  161. return 0;
  162. }
  163. toString() {
  164. if (this._numberStr) return this._numberStr;
  165. if (this.value < 1e3) return (this._numberStr = this.value + "");
  166. {
  167. let t = this.value.toPrecision(3),
  168. e = t.split("e+"),
  169. i = parseInt(e[1]),
  170. s = i % 3;
  171. return (
  172. (i -= s),
  173. s < 2
  174. ? ((t = t.replace(".", "")),
  175. (this._numberStr = t.slice(0, 1 + s) + "." + t.slice(1 + s, 3) + a[i / 3]))
  176. : (this._numberStr = t.replace(".", "").slice(0, 1 + s) + a[i / 3])
  177. );
  178. }
  179. }
  180. multiply(t) {
  181. return (
  182. (this.value = "number" == typeof t ? Math.floor(this.value * t) : Math.floor(this.value * t.value)),
  183. (this._numberStr = ""),
  184. this
  185. );
  186. }
  187. getMultiplyValue(t) {
  188. let o = 0;
  189. if ((o = "number" == typeof t ? Math.floor(this.value * t) : Math.floor(this.value * t.value)) < 1e3)
  190. return o + "";
  191. {
  192. let t = o.toPrecision(3),
  193. e = t.split("e+"),
  194. i = parseInt(e[1]),
  195. s = i % 3;
  196. return (
  197. (i -= s),
  198. s < 2
  199. ? (t = t.replace(".", "")).slice(0, 1 + s) + "." + t.slice(1 + s, 3) + a[i / 3]
  200. : t.replace(".", "").slice(0, 1 + s) + a[i / 3]
  201. );
  202. }
  203. }
  204. copy() {
  205. return s.create(this);
  206. }
  207. isZero() {
  208. return 0 === this.value;
  209. }
  210. clear() {
  211. (this.value = 0), (this._numberStr = "0");
  212. }
  213. getData() {
  214. return [this.value];
  215. }
  216. unPackData(t) {
  217. (this._numberStr = ""), (this.value = t[0]);
  218. }
  219. }
  220. (i.default = s), (s.pool = []), (s.tempNum = s.create(0, 0)), (window.MyBigLong = s);