index.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. // GENERATED FILE. DO NOT EDIT.
  2. var Long = (function(exports) {
  3. "use strict";
  4. Object.defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.default = void 0;
  8. /**
  9. * @license
  10. * Copyright 2009 The Closure Library Authors
  11. * Copyright 2020 Daniel Wirtz / The long.js Authors.
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. * SPDX-License-Identifier: Apache-2.0
  26. */
  27. // WebAssembly optimizations to do native i64 multiplication and divide
  28. var wasm = null;
  29. try {
  30. wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11])), {}).exports;
  31. } catch (e) {// no wasm support :(
  32. }
  33. /**
  34. * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
  35. * See the from* functions below for more convenient ways of constructing Longs.
  36. * @exports Long
  37. * @class A Long class for representing a 64 bit two's-complement integer value.
  38. * @param {number} low The low (signed) 32 bits of the long
  39. * @param {number} high The high (signed) 32 bits of the long
  40. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  41. * @constructor
  42. */
  43. function Long(low, high, unsigned) {
  44. /**
  45. * The low 32 bits as a signed value.
  46. * @type {number}
  47. */
  48. this.low = low | 0;
  49. /**
  50. * The high 32 bits as a signed value.
  51. * @type {number}
  52. */
  53. this.high = high | 0;
  54. /**
  55. * Whether unsigned or not.
  56. * @type {boolean}
  57. */
  58. this.unsigned = !!unsigned;
  59. } // The internal representation of a long is the two given signed, 32-bit values.
  60. // We use 32-bit pieces because these are the size of integers on which
  61. // Javascript performs bit-operations. For operations like addition and
  62. // multiplication, we split each number into 16 bit pieces, which can easily be
  63. // multiplied within Javascript's floating-point representation without overflow
  64. // or change in sign.
  65. //
  66. // In the algorithms below, we frequently reduce the negative case to the
  67. // positive case by negating the input(s) and then post-processing the result.
  68. // Note that we must ALWAYS check specially whether those values are MIN_VALUE
  69. // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
  70. // a positive number, it overflows back into a negative). Not handling this
  71. // case would often result in infinite recursion.
  72. //
  73. // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
  74. // methods on which they depend.
  75. /**
  76. * An indicator used to reliably determine if an object is a Long or not.
  77. * @type {boolean}
  78. * @const
  79. * @private
  80. */
  81. Long.prototype.__isLong__;
  82. Object.defineProperty(Long.prototype, "__isLong__", {
  83. value: true
  84. });
  85. /**
  86. * @function
  87. * @param {*} obj Object
  88. * @returns {boolean}
  89. * @inner
  90. */
  91. function isLong(obj) {
  92. return (obj && obj["__isLong__"]) === true;
  93. }
  94. /**
  95. * @function
  96. * @param {*} value number
  97. * @returns {number}
  98. * @inner
  99. */
  100. function ctz32(value) {
  101. var c = Math.clz32(value & -value);
  102. return value ? 31 - c : c;
  103. }
  104. /**
  105. * Tests if the specified object is a Long.
  106. * @function
  107. * @param {*} obj Object
  108. * @returns {boolean}
  109. */
  110. Long.isLong = isLong;
  111. /**
  112. * A cache of the Long representations of small integer values.
  113. * @type {!Object}
  114. * @inner
  115. */
  116. var INT_CACHE = {};
  117. /**
  118. * A cache of the Long representations of small unsigned integer values.
  119. * @type {!Object}
  120. * @inner
  121. */
  122. var UINT_CACHE = {};
  123. /**
  124. * @param {number} value
  125. * @param {boolean=} unsigned
  126. * @returns {!Long}
  127. * @inner
  128. */
  129. function fromInt(value, unsigned) {
  130. var obj, cachedObj, cache;
  131. if (unsigned) {
  132. value >>>= 0;
  133. if (cache = 0 <= value && value < 256) {
  134. cachedObj = UINT_CACHE[value];
  135. if (cachedObj) return cachedObj;
  136. }
  137. obj = fromBits(value, 0, true);
  138. if (cache) UINT_CACHE[value] = obj;
  139. return obj;
  140. } else {
  141. value |= 0;
  142. if (cache = -128 <= value && value < 128) {
  143. cachedObj = INT_CACHE[value];
  144. if (cachedObj) return cachedObj;
  145. }
  146. obj = fromBits(value, value < 0 ? -1 : 0, false);
  147. if (cache) INT_CACHE[value] = obj;
  148. return obj;
  149. }
  150. }
  151. /**
  152. * Returns a Long representing the given 32 bit integer value.
  153. * @function
  154. * @param {number} value The 32 bit integer in question
  155. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  156. * @returns {!Long} The corresponding Long value
  157. */
  158. Long.fromInt = fromInt;
  159. /**
  160. * @param {number} value
  161. * @param {boolean=} unsigned
  162. * @returns {!Long}
  163. * @inner
  164. */
  165. function fromNumber(value, unsigned) {
  166. if (isNaN(value)) return unsigned ? UZERO : ZERO;
  167. if (unsigned) {
  168. if (value < 0) return UZERO;
  169. if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
  170. } else {
  171. if (value <= -TWO_PWR_63_DBL) return MIN_VALUE;
  172. if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
  173. }
  174. if (value < 0) return fromNumber(-value, unsigned).neg();
  175. return fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
  176. }
  177. /**
  178. * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
  179. * @function
  180. * @param {number} value The number in question
  181. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  182. * @returns {!Long} The corresponding Long value
  183. */
  184. Long.fromNumber = fromNumber;
  185. /**
  186. * @param {number} lowBits
  187. * @param {number} highBits
  188. * @param {boolean=} unsigned
  189. * @returns {!Long}
  190. * @inner
  191. */
  192. function fromBits(lowBits, highBits, unsigned) {
  193. return new Long(lowBits, highBits, unsigned);
  194. }
  195. /**
  196. * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
  197. * assumed to use 32 bits.
  198. * @function
  199. * @param {number} lowBits The low 32 bits
  200. * @param {number} highBits The high 32 bits
  201. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  202. * @returns {!Long} The corresponding Long value
  203. */
  204. Long.fromBits = fromBits;
  205. /**
  206. * @function
  207. * @param {number} base
  208. * @param {number} exponent
  209. * @returns {number}
  210. * @inner
  211. */
  212. var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
  213. /**
  214. * @param {string} str
  215. * @param {(boolean|number)=} unsigned
  216. * @param {number=} radix
  217. * @returns {!Long}
  218. * @inner
  219. */
  220. function fromString(str, unsigned, radix) {
  221. if (str.length === 0) throw Error('empty string');
  222. if (typeof unsigned === 'number') {
  223. // For goog.math.long compatibility
  224. radix = unsigned;
  225. unsigned = false;
  226. } else {
  227. unsigned = !!unsigned;
  228. }
  229. if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") return unsigned ? UZERO : ZERO;
  230. radix = radix || 10;
  231. if (radix < 2 || 36 < radix) throw RangeError('radix');
  232. var p;
  233. if ((p = str.indexOf('-')) > 0) throw Error('interior hyphen');else if (p === 0) {
  234. return fromString(str.substring(1), unsigned, radix).neg();
  235. } // Do several (8) digits each time through the loop, so as to
  236. // minimize the calls to the very expensive emulated div.
  237. var radixToPower = fromNumber(pow_dbl(radix, 8));
  238. var result = ZERO;
  239. for (var i = 0; i < str.length; i += 8) {
  240. var size = Math.min(8, str.length - i),
  241. value = parseInt(str.substring(i, i + size), radix);
  242. if (size < 8) {
  243. var power = fromNumber(pow_dbl(radix, size));
  244. result = result.mul(power).add(fromNumber(value));
  245. } else {
  246. result = result.mul(radixToPower);
  247. result = result.add(fromNumber(value));
  248. }
  249. }
  250. result.unsigned = unsigned;
  251. return result;
  252. }
  253. /**
  254. * Returns a Long representation of the given string, written using the specified radix.
  255. * @function
  256. * @param {string} str The textual representation of the Long
  257. * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
  258. * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
  259. * @returns {!Long} The corresponding Long value
  260. */
  261. Long.fromString = fromString;
  262. /**
  263. * @function
  264. * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
  265. * @param {boolean=} unsigned
  266. * @returns {!Long}
  267. * @inner
  268. */
  269. function fromValue(val, unsigned) {
  270. if (typeof val === 'number') return fromNumber(val, unsigned);
  271. if (typeof val === 'string') return fromString(val, unsigned); // Throws for non-objects, converts non-instanceof Long:
  272. return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
  273. }
  274. /**
  275. * Converts the specified value to a Long using the appropriate from* function for its type.
  276. * @function
  277. * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
  278. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  279. * @returns {!Long}
  280. */
  281. Long.fromValue = fromValue; // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
  282. // no runtime penalty for these.
  283. /**
  284. * @type {number}
  285. * @const
  286. * @inner
  287. */
  288. var TWO_PWR_16_DBL = 1 << 16;
  289. /**
  290. * @type {number}
  291. * @const
  292. * @inner
  293. */
  294. var TWO_PWR_24_DBL = 1 << 24;
  295. /**
  296. * @type {number}
  297. * @const
  298. * @inner
  299. */
  300. var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
  301. /**
  302. * @type {number}
  303. * @const
  304. * @inner
  305. */
  306. var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
  307. /**
  308. * @type {number}
  309. * @const
  310. * @inner
  311. */
  312. var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
  313. /**
  314. * @type {!Long}
  315. * @const
  316. * @inner
  317. */
  318. var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
  319. /**
  320. * @type {!Long}
  321. * @inner
  322. */
  323. var ZERO = fromInt(0);
  324. /**
  325. * Signed zero.
  326. * @type {!Long}
  327. */
  328. Long.ZERO = ZERO;
  329. /**
  330. * @type {!Long}
  331. * @inner
  332. */
  333. var UZERO = fromInt(0, true);
  334. /**
  335. * Unsigned zero.
  336. * @type {!Long}
  337. */
  338. Long.UZERO = UZERO;
  339. /**
  340. * @type {!Long}
  341. * @inner
  342. */
  343. var ONE = fromInt(1);
  344. /**
  345. * Signed one.
  346. * @type {!Long}
  347. */
  348. Long.ONE = ONE;
  349. /**
  350. * @type {!Long}
  351. * @inner
  352. */
  353. var UONE = fromInt(1, true);
  354. /**
  355. * Unsigned one.
  356. * @type {!Long}
  357. */
  358. Long.UONE = UONE;
  359. /**
  360. * @type {!Long}
  361. * @inner
  362. */
  363. var NEG_ONE = fromInt(-1);
  364. /**
  365. * Signed negative one.
  366. * @type {!Long}
  367. */
  368. Long.NEG_ONE = NEG_ONE;
  369. /**
  370. * @type {!Long}
  371. * @inner
  372. */
  373. var MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false);
  374. /**
  375. * Maximum signed value.
  376. * @type {!Long}
  377. */
  378. Long.MAX_VALUE = MAX_VALUE;
  379. /**
  380. * @type {!Long}
  381. * @inner
  382. */
  383. var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true);
  384. /**
  385. * Maximum unsigned value.
  386. * @type {!Long}
  387. */
  388. Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
  389. /**
  390. * @type {!Long}
  391. * @inner
  392. */
  393. var MIN_VALUE = fromBits(0, 0x80000000 | 0, false);
  394. /**
  395. * Minimum signed value.
  396. * @type {!Long}
  397. */
  398. Long.MIN_VALUE = MIN_VALUE;
  399. /**
  400. * @alias Long.prototype
  401. * @inner
  402. */
  403. var LongPrototype = Long.prototype;
  404. /**
  405. * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
  406. * @this {!Long}
  407. * @returns {number}
  408. */
  409. LongPrototype.toInt = function toInt() {
  410. return this.unsigned ? this.low >>> 0 : this.low;
  411. };
  412. /**
  413. * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
  414. * @this {!Long}
  415. * @returns {number}
  416. */
  417. LongPrototype.toNumber = function toNumber() {
  418. if (this.unsigned) return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
  419. return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
  420. };
  421. /**
  422. * Converts the Long to a string written in the specified radix.
  423. * @this {!Long}
  424. * @param {number=} radix Radix (2-36), defaults to 10
  425. * @returns {string}
  426. * @override
  427. * @throws {RangeError} If `radix` is out of range
  428. */
  429. LongPrototype.toString = function toString(radix) {
  430. radix = radix || 10;
  431. if (radix < 2 || 36 < radix) throw RangeError('radix');
  432. if (this.isZero()) return '0';
  433. if (this.isNegative()) {
  434. // Unsigned Longs are never negative
  435. if (this.eq(MIN_VALUE)) {
  436. // We need to change the Long value before it can be negated, so we remove
  437. // the bottom-most digit in this base and then recurse to do the rest.
  438. var radixLong = fromNumber(radix),
  439. div = this.div(radixLong),
  440. rem1 = div.mul(radixLong).sub(this);
  441. return div.toString(radix) + rem1.toInt().toString(radix);
  442. } else return '-' + this.neg().toString(radix);
  443. } // Do several (6) digits each time through the loop, so as to
  444. // minimize the calls to the very expensive emulated div.
  445. var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
  446. rem = this;
  447. var result = '';
  448. while (true) {
  449. var remDiv = rem.div(radixToPower),
  450. intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
  451. digits = intval.toString(radix);
  452. rem = remDiv;
  453. if (rem.isZero()) return digits + result;else {
  454. while (digits.length < 6) digits = '0' + digits;
  455. result = '' + digits + result;
  456. }
  457. }
  458. };
  459. /**
  460. * Gets the high 32 bits as a signed integer.
  461. * @this {!Long}
  462. * @returns {number} Signed high bits
  463. */
  464. LongPrototype.getHighBits = function getHighBits() {
  465. return this.high;
  466. };
  467. /**
  468. * Gets the high 32 bits as an unsigned integer.
  469. * @this {!Long}
  470. * @returns {number} Unsigned high bits
  471. */
  472. LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
  473. return this.high >>> 0;
  474. };
  475. /**
  476. * Gets the low 32 bits as a signed integer.
  477. * @this {!Long}
  478. * @returns {number} Signed low bits
  479. */
  480. LongPrototype.getLowBits = function getLowBits() {
  481. return this.low;
  482. };
  483. /**
  484. * Gets the low 32 bits as an unsigned integer.
  485. * @this {!Long}
  486. * @returns {number} Unsigned low bits
  487. */
  488. LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
  489. return this.low >>> 0;
  490. };
  491. /**
  492. * Gets the number of bits needed to represent the absolute value of this Long.
  493. * @this {!Long}
  494. * @returns {number}
  495. */
  496. LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
  497. if (this.isNegative()) // Unsigned Longs are never negative
  498. return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
  499. var val = this.high != 0 ? this.high : this.low;
  500. for (var bit = 31; bit > 0; bit--) if ((val & 1 << bit) != 0) break;
  501. return this.high != 0 ? bit + 33 : bit + 1;
  502. };
  503. /**
  504. * Tests if this Long's value equals zero.
  505. * @this {!Long}
  506. * @returns {boolean}
  507. */
  508. LongPrototype.isZero = function isZero() {
  509. return this.high === 0 && this.low === 0;
  510. };
  511. /**
  512. * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
  513. * @returns {boolean}
  514. */
  515. LongPrototype.eqz = LongPrototype.isZero;
  516. /**
  517. * Tests if this Long's value is negative.
  518. * @this {!Long}
  519. * @returns {boolean}
  520. */
  521. LongPrototype.isNegative = function isNegative() {
  522. return !this.unsigned && this.high < 0;
  523. };
  524. /**
  525. * Tests if this Long's value is positive or zero.
  526. * @this {!Long}
  527. * @returns {boolean}
  528. */
  529. LongPrototype.isPositive = function isPositive() {
  530. return this.unsigned || this.high >= 0;
  531. };
  532. /**
  533. * Tests if this Long's value is odd.
  534. * @this {!Long}
  535. * @returns {boolean}
  536. */
  537. LongPrototype.isOdd = function isOdd() {
  538. return (this.low & 1) === 1;
  539. };
  540. /**
  541. * Tests if this Long's value is even.
  542. * @this {!Long}
  543. * @returns {boolean}
  544. */
  545. LongPrototype.isEven = function isEven() {
  546. return (this.low & 1) === 0;
  547. };
  548. /**
  549. * Tests if this Long's value equals the specified's.
  550. * @this {!Long}
  551. * @param {!Long|number|string} other Other value
  552. * @returns {boolean}
  553. */
  554. LongPrototype.equals = function equals(other) {
  555. if (!isLong(other)) other = fromValue(other);
  556. if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1) return false;
  557. return this.high === other.high && this.low === other.low;
  558. };
  559. /**
  560. * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
  561. * @function
  562. * @param {!Long|number|string} other Other value
  563. * @returns {boolean}
  564. */
  565. LongPrototype.eq = LongPrototype.equals;
  566. /**
  567. * Tests if this Long's value differs from the specified's.
  568. * @this {!Long}
  569. * @param {!Long|number|string} other Other value
  570. * @returns {boolean}
  571. */
  572. LongPrototype.notEquals = function notEquals(other) {
  573. return !this.eq(
  574. /* validates */
  575. other);
  576. };
  577. /**
  578. * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
  579. * @function
  580. * @param {!Long|number|string} other Other value
  581. * @returns {boolean}
  582. */
  583. LongPrototype.neq = LongPrototype.notEquals;
  584. /**
  585. * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
  586. * @function
  587. * @param {!Long|number|string} other Other value
  588. * @returns {boolean}
  589. */
  590. LongPrototype.ne = LongPrototype.notEquals;
  591. /**
  592. * Tests if this Long's value is less than the specified's.
  593. * @this {!Long}
  594. * @param {!Long|number|string} other Other value
  595. * @returns {boolean}
  596. */
  597. LongPrototype.lessThan = function lessThan(other) {
  598. return this.comp(
  599. /* validates */
  600. other) < 0;
  601. };
  602. /**
  603. * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
  604. * @function
  605. * @param {!Long|number|string} other Other value
  606. * @returns {boolean}
  607. */
  608. LongPrototype.lt = LongPrototype.lessThan;
  609. /**
  610. * Tests if this Long's value is less than or equal the specified's.
  611. * @this {!Long}
  612. * @param {!Long|number|string} other Other value
  613. * @returns {boolean}
  614. */
  615. LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
  616. return this.comp(
  617. /* validates */
  618. other) <= 0;
  619. };
  620. /**
  621. * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
  622. * @function
  623. * @param {!Long|number|string} other Other value
  624. * @returns {boolean}
  625. */
  626. LongPrototype.lte = LongPrototype.lessThanOrEqual;
  627. /**
  628. * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
  629. * @function
  630. * @param {!Long|number|string} other Other value
  631. * @returns {boolean}
  632. */
  633. LongPrototype.le = LongPrototype.lessThanOrEqual;
  634. /**
  635. * Tests if this Long's value is greater than the specified's.
  636. * @this {!Long}
  637. * @param {!Long|number|string} other Other value
  638. * @returns {boolean}
  639. */
  640. LongPrototype.greaterThan = function greaterThan(other) {
  641. return this.comp(
  642. /* validates */
  643. other) > 0;
  644. };
  645. /**
  646. * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
  647. * @function
  648. * @param {!Long|number|string} other Other value
  649. * @returns {boolean}
  650. */
  651. LongPrototype.gt = LongPrototype.greaterThan;
  652. /**
  653. * Tests if this Long's value is greater than or equal the specified's.
  654. * @this {!Long}
  655. * @param {!Long|number|string} other Other value
  656. * @returns {boolean}
  657. */
  658. LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
  659. return this.comp(
  660. /* validates */
  661. other) >= 0;
  662. };
  663. /**
  664. * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
  665. * @function
  666. * @param {!Long|number|string} other Other value
  667. * @returns {boolean}
  668. */
  669. LongPrototype.gte = LongPrototype.greaterThanOrEqual;
  670. /**
  671. * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
  672. * @function
  673. * @param {!Long|number|string} other Other value
  674. * @returns {boolean}
  675. */
  676. LongPrototype.ge = LongPrototype.greaterThanOrEqual;
  677. /**
  678. * Compares this Long's value with the specified's.
  679. * @this {!Long}
  680. * @param {!Long|number|string} other Other value
  681. * @returns {number} 0 if they are the same, 1 if the this is greater and -1
  682. * if the given one is greater
  683. */
  684. LongPrototype.compare = function compare(other) {
  685. if (!isLong(other)) other = fromValue(other);
  686. if (this.eq(other)) return 0;
  687. var thisNeg = this.isNegative(),
  688. otherNeg = other.isNegative();
  689. if (thisNeg && !otherNeg) return -1;
  690. if (!thisNeg && otherNeg) return 1; // At this point the sign bits are the same
  691. if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1; // Both are positive if at least one is unsigned
  692. return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
  693. };
  694. /**
  695. * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
  696. * @function
  697. * @param {!Long|number|string} other Other value
  698. * @returns {number} 0 if they are the same, 1 if the this is greater and -1
  699. * if the given one is greater
  700. */
  701. LongPrototype.comp = LongPrototype.compare;
  702. /**
  703. * Negates this Long's value.
  704. * @this {!Long}
  705. * @returns {!Long} Negated Long
  706. */
  707. LongPrototype.negate = function negate() {
  708. if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
  709. return this.not().add(ONE);
  710. };
  711. /**
  712. * Negates this Long's value. This is an alias of {@link Long#negate}.
  713. * @function
  714. * @returns {!Long} Negated Long
  715. */
  716. LongPrototype.neg = LongPrototype.negate;
  717. /**
  718. * Returns the sum of this and the specified Long.
  719. * @this {!Long}
  720. * @param {!Long|number|string} addend Addend
  721. * @returns {!Long} Sum
  722. */
  723. LongPrototype.add = function add(addend) {
  724. if (!isLong(addend)) addend = fromValue(addend); // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
  725. var a48 = this.high >>> 16;
  726. var a32 = this.high & 0xFFFF;
  727. var a16 = this.low >>> 16;
  728. var a00 = this.low & 0xFFFF;
  729. var b48 = addend.high >>> 16;
  730. var b32 = addend.high & 0xFFFF;
  731. var b16 = addend.low >>> 16;
  732. var b00 = addend.low & 0xFFFF;
  733. var c48 = 0,
  734. c32 = 0,
  735. c16 = 0,
  736. c00 = 0;
  737. c00 += a00 + b00;
  738. c16 += c00 >>> 16;
  739. c00 &= 0xFFFF;
  740. c16 += a16 + b16;
  741. c32 += c16 >>> 16;
  742. c16 &= 0xFFFF;
  743. c32 += a32 + b32;
  744. c48 += c32 >>> 16;
  745. c32 &= 0xFFFF;
  746. c48 += a48 + b48;
  747. c48 &= 0xFFFF;
  748. return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  749. };
  750. /**
  751. * Returns the difference of this and the specified Long.
  752. * @this {!Long}
  753. * @param {!Long|number|string} subtrahend Subtrahend
  754. * @returns {!Long} Difference
  755. */
  756. LongPrototype.subtract = function subtract(subtrahend) {
  757. if (!isLong(subtrahend)) subtrahend = fromValue(subtrahend);
  758. return this.add(subtrahend.neg());
  759. };
  760. /**
  761. * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
  762. * @function
  763. * @param {!Long|number|string} subtrahend Subtrahend
  764. * @returns {!Long} Difference
  765. */
  766. LongPrototype.sub = LongPrototype.subtract;
  767. /**
  768. * Returns the product of this and the specified Long.
  769. * @this {!Long}
  770. * @param {!Long|number|string} multiplier Multiplier
  771. * @returns {!Long} Product
  772. */
  773. LongPrototype.multiply = function multiply(multiplier) {
  774. if (this.isZero()) return this;
  775. if (!isLong(multiplier)) multiplier = fromValue(multiplier); // use wasm support if present
  776. if (wasm) {
  777. var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
  778. return fromBits(low, wasm["get_high"](), this.unsigned);
  779. }
  780. if (multiplier.isZero()) return this.unsigned ? UZERO : ZERO;
  781. if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
  782. if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
  783. if (this.isNegative()) {
  784. if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());else return this.neg().mul(multiplier).neg();
  785. } else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg(); // If both longs are small, use float multiplication
  786. if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
  787. // We can skip products that would overflow.
  788. var a48 = this.high >>> 16;
  789. var a32 = this.high & 0xFFFF;
  790. var a16 = this.low >>> 16;
  791. var a00 = this.low & 0xFFFF;
  792. var b48 = multiplier.high >>> 16;
  793. var b32 = multiplier.high & 0xFFFF;
  794. var b16 = multiplier.low >>> 16;
  795. var b00 = multiplier.low & 0xFFFF;
  796. var c48 = 0,
  797. c32 = 0,
  798. c16 = 0,
  799. c00 = 0;
  800. c00 += a00 * b00;
  801. c16 += c00 >>> 16;
  802. c00 &= 0xFFFF;
  803. c16 += a16 * b00;
  804. c32 += c16 >>> 16;
  805. c16 &= 0xFFFF;
  806. c16 += a00 * b16;
  807. c32 += c16 >>> 16;
  808. c16 &= 0xFFFF;
  809. c32 += a32 * b00;
  810. c48 += c32 >>> 16;
  811. c32 &= 0xFFFF;
  812. c32 += a16 * b16;
  813. c48 += c32 >>> 16;
  814. c32 &= 0xFFFF;
  815. c32 += a00 * b32;
  816. c48 += c32 >>> 16;
  817. c32 &= 0xFFFF;
  818. c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
  819. c48 &= 0xFFFF;
  820. return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  821. };
  822. /**
  823. * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
  824. * @function
  825. * @param {!Long|number|string} multiplier Multiplier
  826. * @returns {!Long} Product
  827. */
  828. LongPrototype.mul = LongPrototype.multiply;
  829. /**
  830. * Returns this Long divided by the specified. The result is signed if this Long is signed or
  831. * unsigned if this Long is unsigned.
  832. * @this {!Long}
  833. * @param {!Long|number|string} divisor Divisor
  834. * @returns {!Long} Quotient
  835. */
  836. LongPrototype.divide = function divide(divisor) {
  837. if (!isLong(divisor)) divisor = fromValue(divisor);
  838. if (divisor.isZero()) throw Error('division by zero'); // use wasm support if present
  839. if (wasm) {
  840. // guard against signed division overflow: the largest
  841. // negative number / -1 would be 1 larger than the largest
  842. // positive number, due to two's complement.
  843. if (!this.unsigned && this.high === -0x80000000 && divisor.low === -1 && divisor.high === -1) {
  844. // be consistent with non-wasm code path
  845. return this;
  846. }
  847. var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(this.low, this.high, divisor.low, divisor.high);
  848. return fromBits(low, wasm["get_high"](), this.unsigned);
  849. }
  850. if (this.isZero()) return this.unsigned ? UZERO : ZERO;
  851. var approx, rem, res;
  852. if (!this.unsigned) {
  853. // This section is only relevant for signed longs and is derived from the
  854. // closure library as a whole.
  855. if (this.eq(MIN_VALUE)) {
  856. if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
  857. else if (divisor.eq(MIN_VALUE)) return ONE;else {
  858. // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
  859. var halfThis = this.shr(1);
  860. approx = halfThis.div(divisor).shl(1);
  861. if (approx.eq(ZERO)) {
  862. return divisor.isNegative() ? ONE : NEG_ONE;
  863. } else {
  864. rem = this.sub(divisor.mul(approx));
  865. res = approx.add(rem.div(divisor));
  866. return res;
  867. }
  868. }
  869. } else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
  870. if (this.isNegative()) {
  871. if (divisor.isNegative()) return this.neg().div(divisor.neg());
  872. return this.neg().div(divisor).neg();
  873. } else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
  874. res = ZERO;
  875. } else {
  876. // The algorithm below has not been made for unsigned longs. It's therefore
  877. // required to take special care of the MSB prior to running it.
  878. if (!divisor.unsigned) divisor = divisor.toUnsigned();
  879. if (divisor.gt(this)) return UZERO;
  880. if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
  881. return UONE;
  882. res = UZERO;
  883. } // Repeat the following until the remainder is less than other: find a
  884. // floating-point that approximates remainder / other *from below*, add this
  885. // into the result, and subtract it from the remainder. It is critical that
  886. // the approximate value is less than or equal to the real value so that the
  887. // remainder never becomes negative.
  888. rem = this;
  889. while (rem.gte(divisor)) {
  890. // Approximate the result of division. This may be a little greater or
  891. // smaller than the actual value.
  892. approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); // We will tweak the approximate result by changing it in the 48-th digit or
  893. // the smallest non-fractional digit, whichever is larger.
  894. var log2 = Math.ceil(Math.log(approx) / Math.LN2),
  895. delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48),
  896. // Decrease the approximation until it is smaller than the remainder. Note
  897. // that if it is too large, the product overflows and is negative.
  898. approxRes = fromNumber(approx),
  899. approxRem = approxRes.mul(divisor);
  900. while (approxRem.isNegative() || approxRem.gt(rem)) {
  901. approx -= delta;
  902. approxRes = fromNumber(approx, this.unsigned);
  903. approxRem = approxRes.mul(divisor);
  904. } // We know the answer can't be zero... and actually, zero would cause
  905. // infinite recursion since we would make no progress.
  906. if (approxRes.isZero()) approxRes = ONE;
  907. res = res.add(approxRes);
  908. rem = rem.sub(approxRem);
  909. }
  910. return res;
  911. };
  912. /**
  913. * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
  914. * @function
  915. * @param {!Long|number|string} divisor Divisor
  916. * @returns {!Long} Quotient
  917. */
  918. LongPrototype.div = LongPrototype.divide;
  919. /**
  920. * Returns this Long modulo the specified.
  921. * @this {!Long}
  922. * @param {!Long|number|string} divisor Divisor
  923. * @returns {!Long} Remainder
  924. */
  925. LongPrototype.modulo = function modulo(divisor) {
  926. if (!isLong(divisor)) divisor = fromValue(divisor); // use wasm support if present
  927. if (wasm) {
  928. var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(this.low, this.high, divisor.low, divisor.high);
  929. return fromBits(low, wasm["get_high"](), this.unsigned);
  930. }
  931. return this.sub(this.div(divisor).mul(divisor));
  932. };
  933. /**
  934. * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
  935. * @function
  936. * @param {!Long|number|string} divisor Divisor
  937. * @returns {!Long} Remainder
  938. */
  939. LongPrototype.mod = LongPrototype.modulo;
  940. /**
  941. * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
  942. * @function
  943. * @param {!Long|number|string} divisor Divisor
  944. * @returns {!Long} Remainder
  945. */
  946. LongPrototype.rem = LongPrototype.modulo;
  947. /**
  948. * Returns the bitwise NOT of this Long.
  949. * @this {!Long}
  950. * @returns {!Long}
  951. */
  952. LongPrototype.not = function not() {
  953. return fromBits(~this.low, ~this.high, this.unsigned);
  954. };
  955. /**
  956. * Returns count leading zeros of this Long.
  957. * @this {!Long}
  958. * @returns {!number}
  959. */
  960. LongPrototype.countLeadingZeros = function countLeadingZeros() {
  961. return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
  962. };
  963. /**
  964. * Returns count leading zeros. This is an alias of {@link Long#countLeadingZeros}.
  965. * @function
  966. * @param {!Long}
  967. * @returns {!number}
  968. */
  969. LongPrototype.clz = LongPrototype.countLeadingZeros;
  970. /**
  971. * Returns count trailing zeros of this Long.
  972. * @this {!Long}
  973. * @returns {!number}
  974. */
  975. LongPrototype.countTrailingZeros = function countTrailingZeros() {
  976. return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
  977. };
  978. /**
  979. * Returns count trailing zeros. This is an alias of {@link Long#countTrailingZeros}.
  980. * @function
  981. * @param {!Long}
  982. * @returns {!number}
  983. */
  984. LongPrototype.ctz = LongPrototype.countTrailingZeros;
  985. /**
  986. * Returns the bitwise AND of this Long and the specified.
  987. * @this {!Long}
  988. * @param {!Long|number|string} other Other Long
  989. * @returns {!Long}
  990. */
  991. LongPrototype.and = function and(other) {
  992. if (!isLong(other)) other = fromValue(other);
  993. return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
  994. };
  995. /**
  996. * Returns the bitwise OR of this Long and the specified.
  997. * @this {!Long}
  998. * @param {!Long|number|string} other Other Long
  999. * @returns {!Long}
  1000. */
  1001. LongPrototype.or = function or(other) {
  1002. if (!isLong(other)) other = fromValue(other);
  1003. return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
  1004. };
  1005. /**
  1006. * Returns the bitwise XOR of this Long and the given one.
  1007. * @this {!Long}
  1008. * @param {!Long|number|string} other Other Long
  1009. * @returns {!Long}
  1010. */
  1011. LongPrototype.xor = function xor(other) {
  1012. if (!isLong(other)) other = fromValue(other);
  1013. return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
  1014. };
  1015. /**
  1016. * Returns this Long with bits shifted to the left by the given amount.
  1017. * @this {!Long}
  1018. * @param {number|!Long} numBits Number of bits
  1019. * @returns {!Long} Shifted Long
  1020. */
  1021. LongPrototype.shiftLeft = function shiftLeft(numBits) {
  1022. if (isLong(numBits)) numBits = numBits.toInt();
  1023. if ((numBits &= 63) === 0) return this;else if (numBits < 32) return fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);else return fromBits(0, this.low << numBits - 32, this.unsigned);
  1024. };
  1025. /**
  1026. * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
  1027. * @function
  1028. * @param {number|!Long} numBits Number of bits
  1029. * @returns {!Long} Shifted Long
  1030. */
  1031. LongPrototype.shl = LongPrototype.shiftLeft;
  1032. /**
  1033. * Returns this Long with bits arithmetically shifted to the right by the given amount.
  1034. * @this {!Long}
  1035. * @param {number|!Long} numBits Number of bits
  1036. * @returns {!Long} Shifted Long
  1037. */
  1038. LongPrototype.shiftRight = function shiftRight(numBits) {
  1039. if (isLong(numBits)) numBits = numBits.toInt();
  1040. if ((numBits &= 63) === 0) return this;else if (numBits < 32) return fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);else return fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
  1041. };
  1042. /**
  1043. * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
  1044. * @function
  1045. * @param {number|!Long} numBits Number of bits
  1046. * @returns {!Long} Shifted Long
  1047. */
  1048. LongPrototype.shr = LongPrototype.shiftRight;
  1049. /**
  1050. * Returns this Long with bits logically shifted to the right by the given amount.
  1051. * @this {!Long}
  1052. * @param {number|!Long} numBits Number of bits
  1053. * @returns {!Long} Shifted Long
  1054. */
  1055. LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
  1056. if (isLong(numBits)) numBits = numBits.toInt();
  1057. if ((numBits &= 63) === 0) return this;
  1058. if (numBits < 32) return fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >>> numBits, this.unsigned);
  1059. if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
  1060. return fromBits(this.high >>> numBits - 32, 0, this.unsigned);
  1061. };
  1062. /**
  1063. * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
  1064. * @function
  1065. * @param {number|!Long} numBits Number of bits
  1066. * @returns {!Long} Shifted Long
  1067. */
  1068. LongPrototype.shru = LongPrototype.shiftRightUnsigned;
  1069. /**
  1070. * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
  1071. * @function
  1072. * @param {number|!Long} numBits Number of bits
  1073. * @returns {!Long} Shifted Long
  1074. */
  1075. LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
  1076. /**
  1077. * Returns this Long with bits rotated to the left by the given amount.
  1078. * @this {!Long}
  1079. * @param {number|!Long} numBits Number of bits
  1080. * @returns {!Long} Rotated Long
  1081. */
  1082. LongPrototype.rotateLeft = function rotateLeft(numBits) {
  1083. var b;
  1084. if (isLong(numBits)) numBits = numBits.toInt();
  1085. if ((numBits &= 63) === 0) return this;
  1086. if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
  1087. if (numBits < 32) {
  1088. b = 32 - numBits;
  1089. return fromBits(this.low << numBits | this.high >>> b, this.high << numBits | this.low >>> b, this.unsigned);
  1090. }
  1091. numBits -= 32;
  1092. b = 32 - numBits;
  1093. return fromBits(this.high << numBits | this.low >>> b, this.low << numBits | this.high >>> b, this.unsigned);
  1094. };
  1095. /**
  1096. * Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}.
  1097. * @function
  1098. * @param {number|!Long} numBits Number of bits
  1099. * @returns {!Long} Rotated Long
  1100. */
  1101. LongPrototype.rotl = LongPrototype.rotateLeft;
  1102. /**
  1103. * Returns this Long with bits rotated to the right by the given amount.
  1104. * @this {!Long}
  1105. * @param {number|!Long} numBits Number of bits
  1106. * @returns {!Long} Rotated Long
  1107. */
  1108. LongPrototype.rotateRight = function rotateRight(numBits) {
  1109. var b;
  1110. if (isLong(numBits)) numBits = numBits.toInt();
  1111. if ((numBits &= 63) === 0) return this;
  1112. if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
  1113. if (numBits < 32) {
  1114. b = 32 - numBits;
  1115. return fromBits(this.high << b | this.low >>> numBits, this.low << b | this.high >>> numBits, this.unsigned);
  1116. }
  1117. numBits -= 32;
  1118. b = 32 - numBits;
  1119. return fromBits(this.low << b | this.high >>> numBits, this.high << b | this.low >>> numBits, this.unsigned);
  1120. };
  1121. /**
  1122. * Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}.
  1123. * @function
  1124. * @param {number|!Long} numBits Number of bits
  1125. * @returns {!Long} Rotated Long
  1126. */
  1127. LongPrototype.rotr = LongPrototype.rotateRight;
  1128. /**
  1129. * Converts this Long to signed.
  1130. * @this {!Long}
  1131. * @returns {!Long} Signed long
  1132. */
  1133. LongPrototype.toSigned = function toSigned() {
  1134. if (!this.unsigned) return this;
  1135. return fromBits(this.low, this.high, false);
  1136. };
  1137. /**
  1138. * Converts this Long to unsigned.
  1139. * @this {!Long}
  1140. * @returns {!Long} Unsigned long
  1141. */
  1142. LongPrototype.toUnsigned = function toUnsigned() {
  1143. if (this.unsigned) return this;
  1144. return fromBits(this.low, this.high, true);
  1145. };
  1146. /**
  1147. * Converts this Long to its byte representation.
  1148. * @param {boolean=} le Whether little or big endian, defaults to big endian
  1149. * @this {!Long}
  1150. * @returns {!Array.<number>} Byte representation
  1151. */
  1152. LongPrototype.toBytes = function toBytes(le) {
  1153. return le ? this.toBytesLE() : this.toBytesBE();
  1154. };
  1155. /**
  1156. * Converts this Long to its little endian byte representation.
  1157. * @this {!Long}
  1158. * @returns {!Array.<number>} Little endian byte representation
  1159. */
  1160. LongPrototype.toBytesLE = function toBytesLE() {
  1161. var hi = this.high,
  1162. lo = this.low;
  1163. return [lo & 0xff, lo >>> 8 & 0xff, lo >>> 16 & 0xff, lo >>> 24, hi & 0xff, hi >>> 8 & 0xff, hi >>> 16 & 0xff, hi >>> 24];
  1164. };
  1165. /**
  1166. * Converts this Long to its big endian byte representation.
  1167. * @this {!Long}
  1168. * @returns {!Array.<number>} Big endian byte representation
  1169. */
  1170. LongPrototype.toBytesBE = function toBytesBE() {
  1171. var hi = this.high,
  1172. lo = this.low;
  1173. return [hi >>> 24, hi >>> 16 & 0xff, hi >>> 8 & 0xff, hi & 0xff, lo >>> 24, lo >>> 16 & 0xff, lo >>> 8 & 0xff, lo & 0xff];
  1174. };
  1175. /**
  1176. * Creates a Long from its byte representation.
  1177. * @param {!Array.<number>} bytes Byte representation
  1178. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1179. * @param {boolean=} le Whether little or big endian, defaults to big endian
  1180. * @returns {Long} The corresponding Long value
  1181. */
  1182. Long.fromBytes = function fromBytes(bytes, unsigned, le) {
  1183. return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
  1184. };
  1185. /**
  1186. * Creates a Long from its little endian byte representation.
  1187. * @param {!Array.<number>} bytes Little endian byte representation
  1188. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1189. * @returns {Long} The corresponding Long value
  1190. */
  1191. Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
  1192. return new Long(bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24, bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24, unsigned);
  1193. };
  1194. /**
  1195. * Creates a Long from its big endian byte representation.
  1196. * @param {!Array.<number>} bytes Big endian byte representation
  1197. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1198. * @returns {Long} The corresponding Long value
  1199. */
  1200. Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
  1201. return new Long(bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7], bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], unsigned);
  1202. };
  1203. var _default = Long;
  1204. exports.default = _default;
  1205. return "default" in exports ? exports.default : exports;
  1206. })({});
  1207. if (typeof define === 'function' && define.amd) define([], function() { return Long; });
  1208. else if (typeof module === 'object' && typeof exports === 'object') module.exports = Long;