@openfeature/flagd-provider 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs.js +1467 -1325
  2. package/index.esm.js +1467 -1325
  3. package/package.json +3 -3
package/index.cjs.js CHANGED
@@ -92,1332 +92,1474 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
92
92
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
93
93
  };
94
94
 
95
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
95
+ /**
96
+ * @license
97
+ * Copyright 2009 The Closure Library Authors
98
+ * Copyright 2020 Daniel Wirtz / The long.js Authors.
99
+ *
100
+ * Licensed under the Apache License, Version 2.0 (the "License");
101
+ * you may not use this file except in compliance with the License.
102
+ * You may obtain a copy of the License at
103
+ *
104
+ * http://www.apache.org/licenses/LICENSE-2.0
105
+ *
106
+ * Unless required by applicable law or agreed to in writing, software
107
+ * distributed under the License is distributed on an "AS IS" BASIS,
108
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109
+ * See the License for the specific language governing permissions and
110
+ * limitations under the License.
111
+ *
112
+ * SPDX-License-Identifier: Apache-2.0
113
+ */
96
114
 
97
- var long = Long;
98
-
99
- /**
100
- * wasm optimizations, to do native i64 multiplication and divide
101
- */
102
- var wasm = null;
103
-
104
- try {
105
- wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
106
- 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
107
- ])), {}).exports;
108
- } catch (e) {
109
- // no wasm support :(
110
- }
111
-
112
- /**
113
- * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
114
- * See the from* functions below for more convenient ways of constructing Longs.
115
- * @exports Long
116
- * @class A Long class for representing a 64 bit two's-complement integer value.
117
- * @param {number} low The low (signed) 32 bits of the long
118
- * @param {number} high The high (signed) 32 bits of the long
119
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
120
- * @constructor
121
- */
122
- function Long(low, high, unsigned) {
123
-
124
- /**
125
- * The low 32 bits as a signed value.
126
- * @type {number}
127
- */
128
- this.low = low | 0;
129
-
130
- /**
131
- * The high 32 bits as a signed value.
132
- * @type {number}
133
- */
134
- this.high = high | 0;
135
-
136
- /**
137
- * Whether unsigned or not.
138
- * @type {boolean}
139
- */
140
- this.unsigned = !!unsigned;
141
- }
142
-
143
- // The internal representation of a long is the two given signed, 32-bit values.
144
- // We use 32-bit pieces because these are the size of integers on which
145
- // Javascript performs bit-operations. For operations like addition and
146
- // multiplication, we split each number into 16 bit pieces, which can easily be
147
- // multiplied within Javascript's floating-point representation without overflow
148
- // or change in sign.
149
- //
150
- // In the algorithms below, we frequently reduce the negative case to the
151
- // positive case by negating the input(s) and then post-processing the result.
152
- // Note that we must ALWAYS check specially whether those values are MIN_VALUE
153
- // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
154
- // a positive number, it overflows back into a negative). Not handling this
155
- // case would often result in infinite recursion.
156
- //
157
- // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
158
- // methods on which they depend.
159
-
160
- /**
161
- * An indicator used to reliably determine if an object is a Long or not.
162
- * @type {boolean}
163
- * @const
164
- * @private
165
- */
166
- Long.prototype.__isLong__;
167
-
168
- Object.defineProperty(Long.prototype, "__isLong__", { value: true });
169
-
170
- /**
171
- * @function
172
- * @param {*} obj Object
173
- * @returns {boolean}
174
- * @inner
175
- */
176
- function isLong(obj) {
177
- return (obj && obj["__isLong__"]) === true;
178
- }
179
-
180
- /**
181
- * Tests if the specified object is a Long.
182
- * @function
183
- * @param {*} obj Object
184
- * @returns {boolean}
185
- */
186
- Long.isLong = isLong;
187
-
188
- /**
189
- * A cache of the Long representations of small integer values.
190
- * @type {!Object}
191
- * @inner
192
- */
193
- var INT_CACHE = {};
194
-
195
- /**
196
- * A cache of the Long representations of small unsigned integer values.
197
- * @type {!Object}
198
- * @inner
199
- */
200
- var UINT_CACHE = {};
201
-
202
- /**
203
- * @param {number} value
204
- * @param {boolean=} unsigned
205
- * @returns {!Long}
206
- * @inner
207
- */
208
- function fromInt(value, unsigned) {
209
- var obj, cachedObj, cache;
210
- if (unsigned) {
211
- value >>>= 0;
212
- if (cache = (0 <= value && value < 256)) {
213
- cachedObj = UINT_CACHE[value];
214
- if (cachedObj)
215
- return cachedObj;
216
- }
217
- obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
218
- if (cache)
219
- UINT_CACHE[value] = obj;
220
- return obj;
221
- } else {
222
- value |= 0;
223
- if (cache = (-128 <= value && value < 128)) {
224
- cachedObj = INT_CACHE[value];
225
- if (cachedObj)
226
- return cachedObj;
227
- }
228
- obj = fromBits(value, value < 0 ? -1 : 0, false);
229
- if (cache)
230
- INT_CACHE[value] = obj;
231
- return obj;
232
- }
233
- }
234
-
235
- /**
236
- * Returns a Long representing the given 32 bit integer value.
237
- * @function
238
- * @param {number} value The 32 bit integer in question
239
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
240
- * @returns {!Long} The corresponding Long value
241
- */
242
- Long.fromInt = fromInt;
243
-
244
- /**
245
- * @param {number} value
246
- * @param {boolean=} unsigned
247
- * @returns {!Long}
248
- * @inner
249
- */
250
- function fromNumber(value, unsigned) {
251
- if (isNaN(value))
252
- return unsigned ? UZERO : ZERO;
253
- if (unsigned) {
254
- if (value < 0)
255
- return UZERO;
256
- if (value >= TWO_PWR_64_DBL)
257
- return MAX_UNSIGNED_VALUE;
258
- } else {
259
- if (value <= -TWO_PWR_63_DBL)
260
- return MIN_VALUE;
261
- if (value + 1 >= TWO_PWR_63_DBL)
262
- return MAX_VALUE;
263
- }
264
- if (value < 0)
265
- return fromNumber(-value, unsigned).neg();
266
- return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
267
- }
268
-
269
- /**
270
- * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
271
- * @function
272
- * @param {number} value The number in question
273
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
274
- * @returns {!Long} The corresponding Long value
275
- */
276
- Long.fromNumber = fromNumber;
277
-
278
- /**
279
- * @param {number} lowBits
280
- * @param {number} highBits
281
- * @param {boolean=} unsigned
282
- * @returns {!Long}
283
- * @inner
284
- */
285
- function fromBits(lowBits, highBits, unsigned) {
286
- return new Long(lowBits, highBits, unsigned);
287
- }
288
-
289
- /**
290
- * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
291
- * assumed to use 32 bits.
292
- * @function
293
- * @param {number} lowBits The low 32 bits
294
- * @param {number} highBits The high 32 bits
295
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
296
- * @returns {!Long} The corresponding Long value
297
- */
298
- Long.fromBits = fromBits;
299
-
300
- /**
301
- * @function
302
- * @param {number} base
303
- * @param {number} exponent
304
- * @returns {number}
305
- * @inner
306
- */
307
- var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
308
-
309
- /**
310
- * @param {string} str
311
- * @param {(boolean|number)=} unsigned
312
- * @param {number=} radix
313
- * @returns {!Long}
314
- * @inner
315
- */
316
- function fromString(str, unsigned, radix) {
317
- if (str.length === 0)
318
- throw Error('empty string');
319
- if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
320
- return ZERO;
321
- if (typeof unsigned === 'number') {
322
- // For goog.math.long compatibility
323
- radix = unsigned,
324
- unsigned = false;
325
- } else {
326
- unsigned = !! unsigned;
327
- }
328
- radix = radix || 10;
329
- if (radix < 2 || 36 < radix)
330
- throw RangeError('radix');
331
-
332
- var p;
333
- if ((p = str.indexOf('-')) > 0)
334
- throw Error('interior hyphen');
335
- else if (p === 0) {
336
- return fromString(str.substring(1), unsigned, radix).neg();
337
- }
338
-
339
- // Do several (8) digits each time through the loop, so as to
340
- // minimize the calls to the very expensive emulated div.
341
- var radixToPower = fromNumber(pow_dbl(radix, 8));
342
-
343
- var result = ZERO;
344
- for (var i = 0; i < str.length; i += 8) {
345
- var size = Math.min(8, str.length - i),
346
- value = parseInt(str.substring(i, i + size), radix);
347
- if (size < 8) {
348
- var power = fromNumber(pow_dbl(radix, size));
349
- result = result.mul(power).add(fromNumber(value));
350
- } else {
351
- result = result.mul(radixToPower);
352
- result = result.add(fromNumber(value));
353
- }
354
- }
355
- result.unsigned = unsigned;
356
- return result;
357
- }
358
-
359
- /**
360
- * Returns a Long representation of the given string, written using the specified radix.
361
- * @function
362
- * @param {string} str The textual representation of the Long
363
- * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
364
- * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
365
- * @returns {!Long} The corresponding Long value
366
- */
367
- Long.fromString = fromString;
368
-
369
- /**
370
- * @function
371
- * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
372
- * @param {boolean=} unsigned
373
- * @returns {!Long}
374
- * @inner
375
- */
376
- function fromValue(val, unsigned) {
377
- if (typeof val === 'number')
378
- return fromNumber(val, unsigned);
379
- if (typeof val === 'string')
380
- return fromString(val, unsigned);
381
- // Throws for non-objects, converts non-instanceof Long:
382
- return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
383
- }
384
-
385
- /**
386
- * Converts the specified value to a Long using the appropriate from* function for its type.
387
- * @function
388
- * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
389
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
390
- * @returns {!Long}
391
- */
392
- Long.fromValue = fromValue;
393
-
394
- // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
395
- // no runtime penalty for these.
396
-
397
- /**
398
- * @type {number}
399
- * @const
400
- * @inner
401
- */
402
- var TWO_PWR_16_DBL = 1 << 16;
403
-
404
- /**
405
- * @type {number}
406
- * @const
407
- * @inner
408
- */
409
- var TWO_PWR_24_DBL = 1 << 24;
410
-
411
- /**
412
- * @type {number}
413
- * @const
414
- * @inner
415
- */
416
- var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
417
-
418
- /**
419
- * @type {number}
420
- * @const
421
- * @inner
422
- */
423
- var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
424
-
425
- /**
426
- * @type {number}
427
- * @const
428
- * @inner
429
- */
430
- var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
431
-
432
- /**
433
- * @type {!Long}
434
- * @const
435
- * @inner
436
- */
437
- var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
438
-
439
- /**
440
- * @type {!Long}
441
- * @inner
442
- */
443
- var ZERO = fromInt(0);
444
-
445
- /**
446
- * Signed zero.
447
- * @type {!Long}
448
- */
449
- Long.ZERO = ZERO;
450
-
451
- /**
452
- * @type {!Long}
453
- * @inner
454
- */
455
- var UZERO = fromInt(0, true);
456
-
457
- /**
458
- * Unsigned zero.
459
- * @type {!Long}
460
- */
461
- Long.UZERO = UZERO;
462
-
463
- /**
464
- * @type {!Long}
465
- * @inner
466
- */
467
- var ONE = fromInt(1);
468
-
469
- /**
470
- * Signed one.
471
- * @type {!Long}
472
- */
473
- Long.ONE = ONE;
474
-
475
- /**
476
- * @type {!Long}
477
- * @inner
478
- */
479
- var UONE = fromInt(1, true);
480
-
481
- /**
482
- * Unsigned one.
483
- * @type {!Long}
484
- */
485
- Long.UONE = UONE;
486
-
487
- /**
488
- * @type {!Long}
489
- * @inner
490
- */
491
- var NEG_ONE = fromInt(-1);
492
-
493
- /**
494
- * Signed negative one.
495
- * @type {!Long}
496
- */
497
- Long.NEG_ONE = NEG_ONE;
498
-
499
- /**
500
- * @type {!Long}
501
- * @inner
502
- */
503
- var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false);
504
-
505
- /**
506
- * Maximum signed value.
507
- * @type {!Long}
508
- */
509
- Long.MAX_VALUE = MAX_VALUE;
510
-
511
- /**
512
- * @type {!Long}
513
- * @inner
514
- */
515
- var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true);
516
-
517
- /**
518
- * Maximum unsigned value.
519
- * @type {!Long}
520
- */
521
- Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
522
-
523
- /**
524
- * @type {!Long}
525
- * @inner
526
- */
527
- var MIN_VALUE = fromBits(0, 0x80000000|0, false);
528
-
529
- /**
530
- * Minimum signed value.
531
- * @type {!Long}
532
- */
533
- Long.MIN_VALUE = MIN_VALUE;
534
-
535
- /**
536
- * @alias Long.prototype
537
- * @inner
538
- */
539
- var LongPrototype = Long.prototype;
540
-
541
- /**
542
- * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
543
- * @returns {number}
544
- */
545
- LongPrototype.toInt = function toInt() {
546
- return this.unsigned ? this.low >>> 0 : this.low;
547
- };
548
-
549
- /**
550
- * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
551
- * @returns {number}
552
- */
553
- LongPrototype.toNumber = function toNumber() {
554
- if (this.unsigned)
555
- return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
556
- return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
557
- };
558
-
559
- /**
560
- * Converts the Long to a string written in the specified radix.
561
- * @param {number=} radix Radix (2-36), defaults to 10
562
- * @returns {string}
563
- * @override
564
- * @throws {RangeError} If `radix` is out of range
565
- */
566
- LongPrototype.toString = function toString(radix) {
567
- radix = radix || 10;
568
- if (radix < 2 || 36 < radix)
569
- throw RangeError('radix');
570
- if (this.isZero())
571
- return '0';
572
- if (this.isNegative()) { // Unsigned Longs are never negative
573
- if (this.eq(MIN_VALUE)) {
574
- // We need to change the Long value before it can be negated, so we remove
575
- // the bottom-most digit in this base and then recurse to do the rest.
576
- var radixLong = fromNumber(radix),
577
- div = this.div(radixLong),
578
- rem1 = div.mul(radixLong).sub(this);
579
- return div.toString(radix) + rem1.toInt().toString(radix);
580
- } else
581
- return '-' + this.neg().toString(radix);
582
- }
583
-
584
- // Do several (6) digits each time through the loop, so as to
585
- // minimize the calls to the very expensive emulated div.
586
- var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
587
- rem = this;
588
- var result = '';
589
- while (true) {
590
- var remDiv = rem.div(radixToPower),
591
- intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
592
- digits = intval.toString(radix);
593
- rem = remDiv;
594
- if (rem.isZero())
595
- return digits + result;
596
- else {
597
- while (digits.length < 6)
598
- digits = '0' + digits;
599
- result = '' + digits + result;
600
- }
601
- }
602
- };
603
-
604
- /**
605
- * Gets the high 32 bits as a signed integer.
606
- * @returns {number} Signed high bits
607
- */
608
- LongPrototype.getHighBits = function getHighBits() {
609
- return this.high;
610
- };
611
-
612
- /**
613
- * Gets the high 32 bits as an unsigned integer.
614
- * @returns {number} Unsigned high bits
615
- */
616
- LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
617
- return this.high >>> 0;
618
- };
619
-
620
- /**
621
- * Gets the low 32 bits as a signed integer.
622
- * @returns {number} Signed low bits
623
- */
624
- LongPrototype.getLowBits = function getLowBits() {
625
- return this.low;
626
- };
627
-
628
- /**
629
- * Gets the low 32 bits as an unsigned integer.
630
- * @returns {number} Unsigned low bits
631
- */
632
- LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
633
- return this.low >>> 0;
634
- };
635
-
636
- /**
637
- * Gets the number of bits needed to represent the absolute value of this Long.
638
- * @returns {number}
639
- */
640
- LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
641
- if (this.isNegative()) // Unsigned Longs are never negative
642
- return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
643
- var val = this.high != 0 ? this.high : this.low;
644
- for (var bit = 31; bit > 0; bit--)
645
- if ((val & (1 << bit)) != 0)
646
- break;
647
- return this.high != 0 ? bit + 33 : bit + 1;
648
- };
649
-
650
- /**
651
- * Tests if this Long's value equals zero.
652
- * @returns {boolean}
653
- */
654
- LongPrototype.isZero = function isZero() {
655
- return this.high === 0 && this.low === 0;
656
- };
657
-
658
- /**
659
- * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
660
- * @returns {boolean}
661
- */
662
- LongPrototype.eqz = LongPrototype.isZero;
663
-
664
- /**
665
- * Tests if this Long's value is negative.
666
- * @returns {boolean}
667
- */
668
- LongPrototype.isNegative = function isNegative() {
669
- return !this.unsigned && this.high < 0;
670
- };
671
-
672
- /**
673
- * Tests if this Long's value is positive.
674
- * @returns {boolean}
675
- */
676
- LongPrototype.isPositive = function isPositive() {
677
- return this.unsigned || this.high >= 0;
678
- };
679
-
680
- /**
681
- * Tests if this Long's value is odd.
682
- * @returns {boolean}
683
- */
684
- LongPrototype.isOdd = function isOdd() {
685
- return (this.low & 1) === 1;
686
- };
687
-
688
- /**
689
- * Tests if this Long's value is even.
690
- * @returns {boolean}
691
- */
692
- LongPrototype.isEven = function isEven() {
693
- return (this.low & 1) === 0;
694
- };
695
-
696
- /**
697
- * Tests if this Long's value equals the specified's.
698
- * @param {!Long|number|string} other Other value
699
- * @returns {boolean}
700
- */
701
- LongPrototype.equals = function equals(other) {
702
- if (!isLong(other))
703
- other = fromValue(other);
704
- if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
705
- return false;
706
- return this.high === other.high && this.low === other.low;
707
- };
708
-
709
- /**
710
- * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
711
- * @function
712
- * @param {!Long|number|string} other Other value
713
- * @returns {boolean}
714
- */
715
- LongPrototype.eq = LongPrototype.equals;
716
-
717
- /**
718
- * Tests if this Long's value differs from the specified's.
719
- * @param {!Long|number|string} other Other value
720
- * @returns {boolean}
721
- */
722
- LongPrototype.notEquals = function notEquals(other) {
723
- return !this.eq(/* validates */ other);
724
- };
725
-
726
- /**
727
- * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
728
- * @function
729
- * @param {!Long|number|string} other Other value
730
- * @returns {boolean}
731
- */
732
- LongPrototype.neq = LongPrototype.notEquals;
733
-
734
- /**
735
- * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
736
- * @function
737
- * @param {!Long|number|string} other Other value
738
- * @returns {boolean}
739
- */
740
- LongPrototype.ne = LongPrototype.notEquals;
741
-
742
- /**
743
- * Tests if this Long's value is less than the specified's.
744
- * @param {!Long|number|string} other Other value
745
- * @returns {boolean}
746
- */
747
- LongPrototype.lessThan = function lessThan(other) {
748
- return this.comp(/* validates */ other) < 0;
749
- };
750
-
751
- /**
752
- * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
753
- * @function
754
- * @param {!Long|number|string} other Other value
755
- * @returns {boolean}
756
- */
757
- LongPrototype.lt = LongPrototype.lessThan;
758
-
759
- /**
760
- * Tests if this Long's value is less than or equal the specified's.
761
- * @param {!Long|number|string} other Other value
762
- * @returns {boolean}
763
- */
764
- LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
765
- return this.comp(/* validates */ other) <= 0;
766
- };
767
-
768
- /**
769
- * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
770
- * @function
771
- * @param {!Long|number|string} other Other value
772
- * @returns {boolean}
773
- */
774
- LongPrototype.lte = LongPrototype.lessThanOrEqual;
775
-
776
- /**
777
- * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
778
- * @function
779
- * @param {!Long|number|string} other Other value
780
- * @returns {boolean}
781
- */
782
- LongPrototype.le = LongPrototype.lessThanOrEqual;
783
-
784
- /**
785
- * Tests if this Long's value is greater than the specified's.
786
- * @param {!Long|number|string} other Other value
787
- * @returns {boolean}
788
- */
789
- LongPrototype.greaterThan = function greaterThan(other) {
790
- return this.comp(/* validates */ other) > 0;
791
- };
792
-
793
- /**
794
- * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
795
- * @function
796
- * @param {!Long|number|string} other Other value
797
- * @returns {boolean}
798
- */
799
- LongPrototype.gt = LongPrototype.greaterThan;
800
-
801
- /**
802
- * Tests if this Long's value is greater than or equal the specified's.
803
- * @param {!Long|number|string} other Other value
804
- * @returns {boolean}
805
- */
806
- LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
807
- return this.comp(/* validates */ other) >= 0;
808
- };
809
-
810
- /**
811
- * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
812
- * @function
813
- * @param {!Long|number|string} other Other value
814
- * @returns {boolean}
815
- */
816
- LongPrototype.gte = LongPrototype.greaterThanOrEqual;
817
-
818
- /**
819
- * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
820
- * @function
821
- * @param {!Long|number|string} other Other value
822
- * @returns {boolean}
823
- */
824
- LongPrototype.ge = LongPrototype.greaterThanOrEqual;
825
-
826
- /**
827
- * Compares this Long's value with the specified's.
828
- * @param {!Long|number|string} other Other value
829
- * @returns {number} 0 if they are the same, 1 if the this is greater and -1
830
- * if the given one is greater
831
- */
832
- LongPrototype.compare = function compare(other) {
833
- if (!isLong(other))
834
- other = fromValue(other);
835
- if (this.eq(other))
836
- return 0;
837
- var thisNeg = this.isNegative(),
838
- otherNeg = other.isNegative();
839
- if (thisNeg && !otherNeg)
840
- return -1;
841
- if (!thisNeg && otherNeg)
842
- return 1;
843
- // At this point the sign bits are the same
844
- if (!this.unsigned)
845
- return this.sub(other).isNegative() ? -1 : 1;
846
- // Both are positive if at least one is unsigned
847
- return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
848
- };
849
-
850
- /**
851
- * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
852
- * @function
853
- * @param {!Long|number|string} other Other value
854
- * @returns {number} 0 if they are the same, 1 if the this is greater and -1
855
- * if the given one is greater
856
- */
857
- LongPrototype.comp = LongPrototype.compare;
858
-
859
- /**
860
- * Negates this Long's value.
861
- * @returns {!Long} Negated Long
862
- */
863
- LongPrototype.negate = function negate() {
864
- if (!this.unsigned && this.eq(MIN_VALUE))
865
- return MIN_VALUE;
866
- return this.not().add(ONE);
867
- };
868
-
869
- /**
870
- * Negates this Long's value. This is an alias of {@link Long#negate}.
871
- * @function
872
- * @returns {!Long} Negated Long
873
- */
874
- LongPrototype.neg = LongPrototype.negate;
875
-
876
- /**
877
- * Returns the sum of this and the specified Long.
878
- * @param {!Long|number|string} addend Addend
879
- * @returns {!Long} Sum
880
- */
881
- LongPrototype.add = function add(addend) {
882
- if (!isLong(addend))
883
- addend = fromValue(addend);
884
-
885
- // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
886
-
887
- var a48 = this.high >>> 16;
888
- var a32 = this.high & 0xFFFF;
889
- var a16 = this.low >>> 16;
890
- var a00 = this.low & 0xFFFF;
891
-
892
- var b48 = addend.high >>> 16;
893
- var b32 = addend.high & 0xFFFF;
894
- var b16 = addend.low >>> 16;
895
- var b00 = addend.low & 0xFFFF;
896
-
897
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
898
- c00 += a00 + b00;
899
- c16 += c00 >>> 16;
900
- c00 &= 0xFFFF;
901
- c16 += a16 + b16;
902
- c32 += c16 >>> 16;
903
- c16 &= 0xFFFF;
904
- c32 += a32 + b32;
905
- c48 += c32 >>> 16;
906
- c32 &= 0xFFFF;
907
- c48 += a48 + b48;
908
- c48 &= 0xFFFF;
909
- return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
910
- };
911
-
912
- /**
913
- * Returns the difference of this and the specified Long.
914
- * @param {!Long|number|string} subtrahend Subtrahend
915
- * @returns {!Long} Difference
916
- */
917
- LongPrototype.subtract = function subtract(subtrahend) {
918
- if (!isLong(subtrahend))
919
- subtrahend = fromValue(subtrahend);
920
- return this.add(subtrahend.neg());
921
- };
922
-
923
- /**
924
- * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
925
- * @function
926
- * @param {!Long|number|string} subtrahend Subtrahend
927
- * @returns {!Long} Difference
928
- */
929
- LongPrototype.sub = LongPrototype.subtract;
930
-
931
- /**
932
- * Returns the product of this and the specified Long.
933
- * @param {!Long|number|string} multiplier Multiplier
934
- * @returns {!Long} Product
935
- */
936
- LongPrototype.multiply = function multiply(multiplier) {
937
- if (this.isZero())
938
- return ZERO;
939
- if (!isLong(multiplier))
940
- multiplier = fromValue(multiplier);
941
-
942
- // use wasm support if present
943
- if (wasm) {
944
- var low = wasm.mul(this.low,
945
- this.high,
946
- multiplier.low,
947
- multiplier.high);
948
- return fromBits(low, wasm.get_high(), this.unsigned);
949
- }
950
-
951
- if (multiplier.isZero())
952
- return ZERO;
953
- if (this.eq(MIN_VALUE))
954
- return multiplier.isOdd() ? MIN_VALUE : ZERO;
955
- if (multiplier.eq(MIN_VALUE))
956
- return this.isOdd() ? MIN_VALUE : ZERO;
957
-
958
- if (this.isNegative()) {
959
- if (multiplier.isNegative())
960
- return this.neg().mul(multiplier.neg());
961
- else
962
- return this.neg().mul(multiplier).neg();
963
- } else if (multiplier.isNegative())
964
- return this.mul(multiplier.neg()).neg();
965
-
966
- // If both longs are small, use float multiplication
967
- if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
968
- return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
969
-
970
- // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
971
- // We can skip products that would overflow.
972
-
973
- var a48 = this.high >>> 16;
974
- var a32 = this.high & 0xFFFF;
975
- var a16 = this.low >>> 16;
976
- var a00 = this.low & 0xFFFF;
977
-
978
- var b48 = multiplier.high >>> 16;
979
- var b32 = multiplier.high & 0xFFFF;
980
- var b16 = multiplier.low >>> 16;
981
- var b00 = multiplier.low & 0xFFFF;
982
-
983
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
984
- c00 += a00 * b00;
985
- c16 += c00 >>> 16;
986
- c00 &= 0xFFFF;
987
- c16 += a16 * b00;
988
- c32 += c16 >>> 16;
989
- c16 &= 0xFFFF;
990
- c16 += a00 * b16;
991
- c32 += c16 >>> 16;
992
- c16 &= 0xFFFF;
993
- c32 += a32 * b00;
994
- c48 += c32 >>> 16;
995
- c32 &= 0xFFFF;
996
- c32 += a16 * b16;
997
- c48 += c32 >>> 16;
998
- c32 &= 0xFFFF;
999
- c32 += a00 * b32;
1000
- c48 += c32 >>> 16;
1001
- c32 &= 0xFFFF;
1002
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
1003
- c48 &= 0xFFFF;
1004
- return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
1005
- };
1006
-
1007
- /**
1008
- * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
1009
- * @function
1010
- * @param {!Long|number|string} multiplier Multiplier
1011
- * @returns {!Long} Product
1012
- */
1013
- LongPrototype.mul = LongPrototype.multiply;
1014
-
1015
- /**
1016
- * Returns this Long divided by the specified. The result is signed if this Long is signed or
1017
- * unsigned if this Long is unsigned.
1018
- * @param {!Long|number|string} divisor Divisor
1019
- * @returns {!Long} Quotient
1020
- */
1021
- LongPrototype.divide = function divide(divisor) {
1022
- if (!isLong(divisor))
1023
- divisor = fromValue(divisor);
1024
- if (divisor.isZero())
1025
- throw Error('division by zero');
1026
-
1027
- // use wasm support if present
1028
- if (wasm) {
1029
- // guard against signed division overflow: the largest
1030
- // negative number / -1 would be 1 larger than the largest
1031
- // positive number, due to two's complement.
1032
- if (!this.unsigned &&
1033
- this.high === -0x80000000 &&
1034
- divisor.low === -1 && divisor.high === -1) {
1035
- // be consistent with non-wasm code path
1036
- return this;
1037
- }
1038
- var low = (this.unsigned ? wasm.div_u : wasm.div_s)(
1039
- this.low,
1040
- this.high,
1041
- divisor.low,
1042
- divisor.high
1043
- );
1044
- return fromBits(low, wasm.get_high(), this.unsigned);
1045
- }
1046
-
1047
- if (this.isZero())
1048
- return this.unsigned ? UZERO : ZERO;
1049
- var approx, rem, res;
1050
- if (!this.unsigned) {
1051
- // This section is only relevant for signed longs and is derived from the
1052
- // closure library as a whole.
1053
- if (this.eq(MIN_VALUE)) {
1054
- if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
1055
- return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
1056
- else if (divisor.eq(MIN_VALUE))
1057
- return ONE;
1058
- else {
1059
- // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
1060
- var halfThis = this.shr(1);
1061
- approx = halfThis.div(divisor).shl(1);
1062
- if (approx.eq(ZERO)) {
1063
- return divisor.isNegative() ? ONE : NEG_ONE;
1064
- } else {
1065
- rem = this.sub(divisor.mul(approx));
1066
- res = approx.add(rem.div(divisor));
1067
- return res;
1068
- }
1069
- }
1070
- } else if (divisor.eq(MIN_VALUE))
1071
- return this.unsigned ? UZERO : ZERO;
1072
- if (this.isNegative()) {
1073
- if (divisor.isNegative())
1074
- return this.neg().div(divisor.neg());
1075
- return this.neg().div(divisor).neg();
1076
- } else if (divisor.isNegative())
1077
- return this.div(divisor.neg()).neg();
1078
- res = ZERO;
1079
- } else {
1080
- // The algorithm below has not been made for unsigned longs. It's therefore
1081
- // required to take special care of the MSB prior to running it.
1082
- if (!divisor.unsigned)
1083
- divisor = divisor.toUnsigned();
1084
- if (divisor.gt(this))
1085
- return UZERO;
1086
- if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
1087
- return UONE;
1088
- res = UZERO;
1089
- }
1090
-
1091
- // Repeat the following until the remainder is less than other: find a
1092
- // floating-point that approximates remainder / other *from below*, add this
1093
- // into the result, and subtract it from the remainder. It is critical that
1094
- // the approximate value is less than or equal to the real value so that the
1095
- // remainder never becomes negative.
1096
- rem = this;
1097
- while (rem.gte(divisor)) {
1098
- // Approximate the result of division. This may be a little greater or
1099
- // smaller than the actual value.
1100
- approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
1101
-
1102
- // We will tweak the approximate result by changing it in the 48-th digit or
1103
- // the smallest non-fractional digit, whichever is larger.
1104
- var log2 = Math.ceil(Math.log(approx) / Math.LN2),
1105
- delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
1106
-
1107
- // Decrease the approximation until it is smaller than the remainder. Note
1108
- // that if it is too large, the product overflows and is negative.
1109
- approxRes = fromNumber(approx),
1110
- approxRem = approxRes.mul(divisor);
1111
- while (approxRem.isNegative() || approxRem.gt(rem)) {
1112
- approx -= delta;
1113
- approxRes = fromNumber(approx, this.unsigned);
1114
- approxRem = approxRes.mul(divisor);
1115
- }
1116
-
1117
- // We know the answer can't be zero... and actually, zero would cause
1118
- // infinite recursion since we would make no progress.
1119
- if (approxRes.isZero())
1120
- approxRes = ONE;
1121
-
1122
- res = res.add(approxRes);
1123
- rem = rem.sub(approxRem);
1124
- }
1125
- return res;
1126
- };
1127
-
1128
- /**
1129
- * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
1130
- * @function
1131
- * @param {!Long|number|string} divisor Divisor
1132
- * @returns {!Long} Quotient
1133
- */
1134
- LongPrototype.div = LongPrototype.divide;
1135
-
1136
- /**
1137
- * Returns this Long modulo the specified.
1138
- * @param {!Long|number|string} divisor Divisor
1139
- * @returns {!Long} Remainder
1140
- */
1141
- LongPrototype.modulo = function modulo(divisor) {
1142
- if (!isLong(divisor))
1143
- divisor = fromValue(divisor);
1144
-
1145
- // use wasm support if present
1146
- if (wasm) {
1147
- var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(
1148
- this.low,
1149
- this.high,
1150
- divisor.low,
1151
- divisor.high
1152
- );
1153
- return fromBits(low, wasm.get_high(), this.unsigned);
1154
- }
1155
-
1156
- return this.sub(this.div(divisor).mul(divisor));
1157
- };
1158
-
1159
- /**
1160
- * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
1161
- * @function
1162
- * @param {!Long|number|string} divisor Divisor
1163
- * @returns {!Long} Remainder
1164
- */
1165
- LongPrototype.mod = LongPrototype.modulo;
1166
-
1167
- /**
1168
- * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
1169
- * @function
1170
- * @param {!Long|number|string} divisor Divisor
1171
- * @returns {!Long} Remainder
1172
- */
1173
- LongPrototype.rem = LongPrototype.modulo;
1174
-
1175
- /**
1176
- * Returns the bitwise NOT of this Long.
1177
- * @returns {!Long}
1178
- */
1179
- LongPrototype.not = function not() {
1180
- return fromBits(~this.low, ~this.high, this.unsigned);
1181
- };
1182
-
1183
- /**
1184
- * Returns the bitwise AND of this Long and the specified.
1185
- * @param {!Long|number|string} other Other Long
1186
- * @returns {!Long}
1187
- */
1188
- LongPrototype.and = function and(other) {
1189
- if (!isLong(other))
1190
- other = fromValue(other);
1191
- return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
1192
- };
1193
-
1194
- /**
1195
- * Returns the bitwise OR of this Long and the specified.
1196
- * @param {!Long|number|string} other Other Long
1197
- * @returns {!Long}
1198
- */
1199
- LongPrototype.or = function or(other) {
1200
- if (!isLong(other))
1201
- other = fromValue(other);
1202
- return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
1203
- };
1204
-
1205
- /**
1206
- * Returns the bitwise XOR of this Long and the given one.
1207
- * @param {!Long|number|string} other Other Long
1208
- * @returns {!Long}
1209
- */
1210
- LongPrototype.xor = function xor(other) {
1211
- if (!isLong(other))
1212
- other = fromValue(other);
1213
- return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
1214
- };
1215
-
1216
- /**
1217
- * Returns this Long with bits shifted to the left by the given amount.
1218
- * @param {number|!Long} numBits Number of bits
1219
- * @returns {!Long} Shifted Long
1220
- */
1221
- LongPrototype.shiftLeft = function shiftLeft(numBits) {
1222
- if (isLong(numBits))
1223
- numBits = numBits.toInt();
1224
- if ((numBits &= 63) === 0)
1225
- return this;
1226
- else if (numBits < 32)
1227
- return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
1228
- else
1229
- return fromBits(0, this.low << (numBits - 32), this.unsigned);
1230
- };
1231
-
1232
- /**
1233
- * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
1234
- * @function
1235
- * @param {number|!Long} numBits Number of bits
1236
- * @returns {!Long} Shifted Long
1237
- */
1238
- LongPrototype.shl = LongPrototype.shiftLeft;
1239
-
1240
- /**
1241
- * Returns this Long with bits arithmetically shifted to the right by the given amount.
1242
- * @param {number|!Long} numBits Number of bits
1243
- * @returns {!Long} Shifted Long
1244
- */
1245
- LongPrototype.shiftRight = function shiftRight(numBits) {
1246
- if (isLong(numBits))
1247
- numBits = numBits.toInt();
1248
- if ((numBits &= 63) === 0)
1249
- return this;
1250
- else if (numBits < 32)
1251
- return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
1252
- else
1253
- return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
1254
- };
1255
-
1256
- /**
1257
- * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
1258
- * @function
1259
- * @param {number|!Long} numBits Number of bits
1260
- * @returns {!Long} Shifted Long
1261
- */
1262
- LongPrototype.shr = LongPrototype.shiftRight;
1263
-
1264
- /**
1265
- * Returns this Long with bits logically shifted to the right by the given amount.
1266
- * @param {number|!Long} numBits Number of bits
1267
- * @returns {!Long} Shifted Long
1268
- */
1269
- LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
1270
- if (isLong(numBits))
1271
- numBits = numBits.toInt();
1272
- numBits &= 63;
1273
- if (numBits === 0)
1274
- return this;
1275
- else {
1276
- var high = this.high;
1277
- if (numBits < 32) {
1278
- var low = this.low;
1279
- return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
1280
- } else if (numBits === 32)
1281
- return fromBits(high, 0, this.unsigned);
1282
- else
1283
- return fromBits(high >>> (numBits - 32), 0, this.unsigned);
1284
- }
1285
- };
1286
-
1287
- /**
1288
- * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
1289
- * @function
1290
- * @param {number|!Long} numBits Number of bits
1291
- * @returns {!Long} Shifted Long
1292
- */
1293
- LongPrototype.shru = LongPrototype.shiftRightUnsigned;
1294
-
1295
- /**
1296
- * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
1297
- * @function
1298
- * @param {number|!Long} numBits Number of bits
1299
- * @returns {!Long} Shifted Long
1300
- */
1301
- LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
1302
-
1303
- /**
1304
- * Converts this Long to signed.
1305
- * @returns {!Long} Signed long
1306
- */
1307
- LongPrototype.toSigned = function toSigned() {
1308
- if (!this.unsigned)
1309
- return this;
1310
- return fromBits(this.low, this.high, false);
1311
- };
1312
-
1313
- /**
1314
- * Converts this Long to unsigned.
1315
- * @returns {!Long} Unsigned long
1316
- */
1317
- LongPrototype.toUnsigned = function toUnsigned() {
1318
- if (this.unsigned)
1319
- return this;
1320
- return fromBits(this.low, this.high, true);
1321
- };
1322
-
1323
- /**
1324
- * Converts this Long to its byte representation.
1325
- * @param {boolean=} le Whether little or big endian, defaults to big endian
1326
- * @returns {!Array.<number>} Byte representation
1327
- */
1328
- LongPrototype.toBytes = function toBytes(le) {
1329
- return le ? this.toBytesLE() : this.toBytesBE();
1330
- };
1331
-
1332
- /**
1333
- * Converts this Long to its little endian byte representation.
1334
- * @returns {!Array.<number>} Little endian byte representation
1335
- */
1336
- LongPrototype.toBytesLE = function toBytesLE() {
1337
- var hi = this.high,
1338
- lo = this.low;
1339
- return [
1340
- lo & 0xff,
1341
- lo >>> 8 & 0xff,
1342
- lo >>> 16 & 0xff,
1343
- lo >>> 24 ,
1344
- hi & 0xff,
1345
- hi >>> 8 & 0xff,
1346
- hi >>> 16 & 0xff,
1347
- hi >>> 24
1348
- ];
1349
- };
1350
-
1351
- /**
1352
- * Converts this Long to its big endian byte representation.
1353
- * @returns {!Array.<number>} Big endian byte representation
1354
- */
1355
- LongPrototype.toBytesBE = function toBytesBE() {
1356
- var hi = this.high,
1357
- lo = this.low;
1358
- return [
1359
- hi >>> 24 ,
1360
- hi >>> 16 & 0xff,
1361
- hi >>> 8 & 0xff,
1362
- hi & 0xff,
1363
- lo >>> 24 ,
1364
- lo >>> 16 & 0xff,
1365
- lo >>> 8 & 0xff,
1366
- lo & 0xff
1367
- ];
1368
- };
1369
-
1370
- /**
1371
- * Creates a Long from its byte representation.
1372
- * @param {!Array.<number>} bytes Byte representation
1373
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1374
- * @param {boolean=} le Whether little or big endian, defaults to big endian
1375
- * @returns {Long} The corresponding Long value
1376
- */
1377
- Long.fromBytes = function fromBytes(bytes, unsigned, le) {
1378
- return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
1379
- };
1380
-
1381
- /**
1382
- * Creates a Long from its little endian byte representation.
1383
- * @param {!Array.<number>} bytes Little endian byte representation
1384
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1385
- * @returns {Long} The corresponding Long value
1386
- */
1387
- Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
1388
- return new Long(
1389
- bytes[0] |
1390
- bytes[1] << 8 |
1391
- bytes[2] << 16 |
1392
- bytes[3] << 24,
1393
- bytes[4] |
1394
- bytes[5] << 8 |
1395
- bytes[6] << 16 |
1396
- bytes[7] << 24,
1397
- unsigned
1398
- );
1399
- };
1400
-
1401
- /**
1402
- * Creates a Long from its big endian byte representation.
1403
- * @param {!Array.<number>} bytes Big endian byte representation
1404
- * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1405
- * @returns {Long} The corresponding Long value
1406
- */
1407
- Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
1408
- return new Long(
1409
- bytes[4] << 24 |
1410
- bytes[5] << 16 |
1411
- bytes[6] << 8 |
1412
- bytes[7],
1413
- bytes[0] << 24 |
1414
- bytes[1] << 16 |
1415
- bytes[2] << 8 |
1416
- bytes[3],
1417
- unsigned
1418
- );
115
+ // WebAssembly optimizations to do native i64 multiplication and divide
116
+ var wasm = null;
117
+ try {
118
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
119
+ 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
120
+ ])), {}).exports;
121
+ } catch (e) {
122
+ // no wasm support :(
123
+ }
124
+
125
+ /**
126
+ * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
127
+ * See the from* functions below for more convenient ways of constructing Longs.
128
+ * @exports Long
129
+ * @class A Long class for representing a 64 bit two's-complement integer value.
130
+ * @param {number} low The low (signed) 32 bits of the long
131
+ * @param {number} high The high (signed) 32 bits of the long
132
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
133
+ * @constructor
134
+ */
135
+ function Long(low, high, unsigned) {
136
+
137
+ /**
138
+ * The low 32 bits as a signed value.
139
+ * @type {number}
140
+ */
141
+ this.low = low | 0;
142
+
143
+ /**
144
+ * The high 32 bits as a signed value.
145
+ * @type {number}
146
+ */
147
+ this.high = high | 0;
148
+
149
+ /**
150
+ * Whether unsigned or not.
151
+ * @type {boolean}
152
+ */
153
+ this.unsigned = !!unsigned;
154
+ }
155
+
156
+ // The internal representation of a long is the two given signed, 32-bit values.
157
+ // We use 32-bit pieces because these are the size of integers on which
158
+ // Javascript performs bit-operations. For operations like addition and
159
+ // multiplication, we split each number into 16 bit pieces, which can easily be
160
+ // multiplied within Javascript's floating-point representation without overflow
161
+ // or change in sign.
162
+ //
163
+ // In the algorithms below, we frequently reduce the negative case to the
164
+ // positive case by negating the input(s) and then post-processing the result.
165
+ // Note that we must ALWAYS check specially whether those values are MIN_VALUE
166
+ // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
167
+ // a positive number, it overflows back into a negative). Not handling this
168
+ // case would often result in infinite recursion.
169
+ //
170
+ // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
171
+ // methods on which they depend.
172
+
173
+ /**
174
+ * An indicator used to reliably determine if an object is a Long or not.
175
+ * @type {boolean}
176
+ * @const
177
+ * @private
178
+ */
179
+ Long.prototype.__isLong__;
180
+
181
+ Object.defineProperty(Long.prototype, "__isLong__", { value: true });
182
+
183
+ /**
184
+ * @function
185
+ * @param {*} obj Object
186
+ * @returns {boolean}
187
+ * @inner
188
+ */
189
+ function isLong(obj) {
190
+ return (obj && obj["__isLong__"]) === true;
191
+ }
192
+
193
+ /**
194
+ * @function
195
+ * @param {*} value number
196
+ * @returns {number}
197
+ * @inner
198
+ */
199
+ function ctz32(value) {
200
+ var c = Math.clz32(value & -value);
201
+ return value ? 31 - c : c;
202
+ }
203
+
204
+ /**
205
+ * Tests if the specified object is a Long.
206
+ * @function
207
+ * @param {*} obj Object
208
+ * @returns {boolean}
209
+ */
210
+ Long.isLong = isLong;
211
+
212
+ /**
213
+ * A cache of the Long representations of small integer values.
214
+ * @type {!Object}
215
+ * @inner
216
+ */
217
+ var INT_CACHE = {};
218
+
219
+ /**
220
+ * A cache of the Long representations of small unsigned integer values.
221
+ * @type {!Object}
222
+ * @inner
223
+ */
224
+ var UINT_CACHE = {};
225
+
226
+ /**
227
+ * @param {number} value
228
+ * @param {boolean=} unsigned
229
+ * @returns {!Long}
230
+ * @inner
231
+ */
232
+ function fromInt(value, unsigned) {
233
+ var obj, cachedObj, cache;
234
+ if (unsigned) {
235
+ value >>>= 0;
236
+ if (cache = (0 <= value && value < 256)) {
237
+ cachedObj = UINT_CACHE[value];
238
+ if (cachedObj)
239
+ return cachedObj;
240
+ }
241
+ obj = fromBits(value, 0, true);
242
+ if (cache)
243
+ UINT_CACHE[value] = obj;
244
+ return obj;
245
+ } else {
246
+ value |= 0;
247
+ if (cache = (-128 <= value && value < 128)) {
248
+ cachedObj = INT_CACHE[value];
249
+ if (cachedObj)
250
+ return cachedObj;
251
+ }
252
+ obj = fromBits(value, value < 0 ? -1 : 0, false);
253
+ if (cache)
254
+ INT_CACHE[value] = obj;
255
+ return obj;
256
+ }
257
+ }
258
+
259
+ /**
260
+ * Returns a Long representing the given 32 bit integer value.
261
+ * @function
262
+ * @param {number} value The 32 bit integer in question
263
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
264
+ * @returns {!Long} The corresponding Long value
265
+ */
266
+ Long.fromInt = fromInt;
267
+
268
+ /**
269
+ * @param {number} value
270
+ * @param {boolean=} unsigned
271
+ * @returns {!Long}
272
+ * @inner
273
+ */
274
+ function fromNumber(value, unsigned) {
275
+ if (isNaN(value))
276
+ return unsigned ? UZERO : ZERO;
277
+ if (unsigned) {
278
+ if (value < 0)
279
+ return UZERO;
280
+ if (value >= TWO_PWR_64_DBL)
281
+ return MAX_UNSIGNED_VALUE;
282
+ } else {
283
+ if (value <= -TWO_PWR_63_DBL)
284
+ return MIN_VALUE;
285
+ if (value + 1 >= TWO_PWR_63_DBL)
286
+ return MAX_VALUE;
287
+ }
288
+ if (value < 0)
289
+ return fromNumber(-value, unsigned).neg();
290
+ return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
291
+ }
292
+
293
+ /**
294
+ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
295
+ * @function
296
+ * @param {number} value The number in question
297
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
298
+ * @returns {!Long} The corresponding Long value
299
+ */
300
+ Long.fromNumber = fromNumber;
301
+
302
+ /**
303
+ * @param {number} lowBits
304
+ * @param {number} highBits
305
+ * @param {boolean=} unsigned
306
+ * @returns {!Long}
307
+ * @inner
308
+ */
309
+ function fromBits(lowBits, highBits, unsigned) {
310
+ return new Long(lowBits, highBits, unsigned);
311
+ }
312
+
313
+ /**
314
+ * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
315
+ * assumed to use 32 bits.
316
+ * @function
317
+ * @param {number} lowBits The low 32 bits
318
+ * @param {number} highBits The high 32 bits
319
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
320
+ * @returns {!Long} The corresponding Long value
321
+ */
322
+ Long.fromBits = fromBits;
323
+
324
+ /**
325
+ * @function
326
+ * @param {number} base
327
+ * @param {number} exponent
328
+ * @returns {number}
329
+ * @inner
330
+ */
331
+ var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
332
+
333
+ /**
334
+ * @param {string} str
335
+ * @param {(boolean|number)=} unsigned
336
+ * @param {number=} radix
337
+ * @returns {!Long}
338
+ * @inner
339
+ */
340
+ function fromString(str, unsigned, radix) {
341
+ if (str.length === 0)
342
+ throw Error('empty string');
343
+ if (typeof unsigned === 'number') {
344
+ // For goog.math.long compatibility
345
+ radix = unsigned;
346
+ unsigned = false;
347
+ } else {
348
+ unsigned = !!unsigned;
349
+ }
350
+ if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
351
+ return unsigned ? UZERO : ZERO;
352
+ radix = radix || 10;
353
+ if (radix < 2 || 36 < radix)
354
+ throw RangeError('radix');
355
+
356
+ var p;
357
+ if ((p = str.indexOf('-')) > 0)
358
+ throw Error('interior hyphen');
359
+ else if (p === 0) {
360
+ return fromString(str.substring(1), unsigned, radix).neg();
361
+ }
362
+
363
+ // Do several (8) digits each time through the loop, so as to
364
+ // minimize the calls to the very expensive emulated div.
365
+ var radixToPower = fromNumber(pow_dbl(radix, 8));
366
+
367
+ var result = ZERO;
368
+ for (var i = 0; i < str.length; i += 8) {
369
+ var size = Math.min(8, str.length - i),
370
+ value = parseInt(str.substring(i, i + size), radix);
371
+ if (size < 8) {
372
+ var power = fromNumber(pow_dbl(radix, size));
373
+ result = result.mul(power).add(fromNumber(value));
374
+ } else {
375
+ result = result.mul(radixToPower);
376
+ result = result.add(fromNumber(value));
377
+ }
378
+ }
379
+ result.unsigned = unsigned;
380
+ return result;
381
+ }
382
+
383
+ /**
384
+ * Returns a Long representation of the given string, written using the specified radix.
385
+ * @function
386
+ * @param {string} str The textual representation of the Long
387
+ * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
388
+ * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
389
+ * @returns {!Long} The corresponding Long value
390
+ */
391
+ Long.fromString = fromString;
392
+
393
+ /**
394
+ * @function
395
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
396
+ * @param {boolean=} unsigned
397
+ * @returns {!Long}
398
+ * @inner
399
+ */
400
+ function fromValue(val, unsigned) {
401
+ if (typeof val === 'number')
402
+ return fromNumber(val, unsigned);
403
+ if (typeof val === 'string')
404
+ return fromString(val, unsigned);
405
+ // Throws for non-objects, converts non-instanceof Long:
406
+ return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
407
+ }
408
+
409
+ /**
410
+ * Converts the specified value to a Long using the appropriate from* function for its type.
411
+ * @function
412
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
413
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
414
+ * @returns {!Long}
415
+ */
416
+ Long.fromValue = fromValue;
417
+
418
+ // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
419
+ // no runtime penalty for these.
420
+
421
+ /**
422
+ * @type {number}
423
+ * @const
424
+ * @inner
425
+ */
426
+ var TWO_PWR_16_DBL = 1 << 16;
427
+
428
+ /**
429
+ * @type {number}
430
+ * @const
431
+ * @inner
432
+ */
433
+ var TWO_PWR_24_DBL = 1 << 24;
434
+
435
+ /**
436
+ * @type {number}
437
+ * @const
438
+ * @inner
439
+ */
440
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
441
+
442
+ /**
443
+ * @type {number}
444
+ * @const
445
+ * @inner
446
+ */
447
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
448
+
449
+ /**
450
+ * @type {number}
451
+ * @const
452
+ * @inner
453
+ */
454
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
455
+
456
+ /**
457
+ * @type {!Long}
458
+ * @const
459
+ * @inner
460
+ */
461
+ var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
462
+
463
+ /**
464
+ * @type {!Long}
465
+ * @inner
466
+ */
467
+ var ZERO = fromInt(0);
468
+
469
+ /**
470
+ * Signed zero.
471
+ * @type {!Long}
472
+ */
473
+ Long.ZERO = ZERO;
474
+
475
+ /**
476
+ * @type {!Long}
477
+ * @inner
478
+ */
479
+ var UZERO = fromInt(0, true);
480
+
481
+ /**
482
+ * Unsigned zero.
483
+ * @type {!Long}
484
+ */
485
+ Long.UZERO = UZERO;
486
+
487
+ /**
488
+ * @type {!Long}
489
+ * @inner
490
+ */
491
+ var ONE = fromInt(1);
492
+
493
+ /**
494
+ * Signed one.
495
+ * @type {!Long}
496
+ */
497
+ Long.ONE = ONE;
498
+
499
+ /**
500
+ * @type {!Long}
501
+ * @inner
502
+ */
503
+ var UONE = fromInt(1, true);
504
+
505
+ /**
506
+ * Unsigned one.
507
+ * @type {!Long}
508
+ */
509
+ Long.UONE = UONE;
510
+
511
+ /**
512
+ * @type {!Long}
513
+ * @inner
514
+ */
515
+ var NEG_ONE = fromInt(-1);
516
+
517
+ /**
518
+ * Signed negative one.
519
+ * @type {!Long}
520
+ */
521
+ Long.NEG_ONE = NEG_ONE;
522
+
523
+ /**
524
+ * @type {!Long}
525
+ * @inner
526
+ */
527
+ var MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false);
528
+
529
+ /**
530
+ * Maximum signed value.
531
+ * @type {!Long}
532
+ */
533
+ Long.MAX_VALUE = MAX_VALUE;
534
+
535
+ /**
536
+ * @type {!Long}
537
+ * @inner
538
+ */
539
+ var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true);
540
+
541
+ /**
542
+ * Maximum unsigned value.
543
+ * @type {!Long}
544
+ */
545
+ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
546
+
547
+ /**
548
+ * @type {!Long}
549
+ * @inner
550
+ */
551
+ var MIN_VALUE = fromBits(0, 0x80000000 | 0, false);
552
+
553
+ /**
554
+ * Minimum signed value.
555
+ * @type {!Long}
556
+ */
557
+ Long.MIN_VALUE = MIN_VALUE;
558
+
559
+ /**
560
+ * @alias Long.prototype
561
+ * @inner
562
+ */
563
+ var LongPrototype = Long.prototype;
564
+
565
+ /**
566
+ * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
567
+ * @this {!Long}
568
+ * @returns {number}
569
+ */
570
+ LongPrototype.toInt = function toInt() {
571
+ return this.unsigned ? this.low >>> 0 : this.low;
572
+ };
573
+
574
+ /**
575
+ * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
576
+ * @this {!Long}
577
+ * @returns {number}
578
+ */
579
+ LongPrototype.toNumber = function toNumber() {
580
+ if (this.unsigned)
581
+ return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
582
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
583
+ };
584
+
585
+ /**
586
+ * Converts the Long to a string written in the specified radix.
587
+ * @this {!Long}
588
+ * @param {number=} radix Radix (2-36), defaults to 10
589
+ * @returns {string}
590
+ * @override
591
+ * @throws {RangeError} If `radix` is out of range
592
+ */
593
+ LongPrototype.toString = function toString(radix) {
594
+ radix = radix || 10;
595
+ if (radix < 2 || 36 < radix)
596
+ throw RangeError('radix');
597
+ if (this.isZero())
598
+ return '0';
599
+ if (this.isNegative()) { // Unsigned Longs are never negative
600
+ if (this.eq(MIN_VALUE)) {
601
+ // We need to change the Long value before it can be negated, so we remove
602
+ // the bottom-most digit in this base and then recurse to do the rest.
603
+ var radixLong = fromNumber(radix),
604
+ div = this.div(radixLong),
605
+ rem1 = div.mul(radixLong).sub(this);
606
+ return div.toString(radix) + rem1.toInt().toString(radix);
607
+ } else
608
+ return '-' + this.neg().toString(radix);
609
+ }
610
+
611
+ // Do several (6) digits each time through the loop, so as to
612
+ // minimize the calls to the very expensive emulated div.
613
+ var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
614
+ rem = this;
615
+ var result = '';
616
+ while (true) {
617
+ var remDiv = rem.div(radixToPower),
618
+ intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
619
+ digits = intval.toString(radix);
620
+ rem = remDiv;
621
+ if (rem.isZero())
622
+ return digits + result;
623
+ else {
624
+ while (digits.length < 6)
625
+ digits = '0' + digits;
626
+ result = '' + digits + result;
627
+ }
628
+ }
629
+ };
630
+
631
+ /**
632
+ * Gets the high 32 bits as a signed integer.
633
+ * @this {!Long}
634
+ * @returns {number} Signed high bits
635
+ */
636
+ LongPrototype.getHighBits = function getHighBits() {
637
+ return this.high;
638
+ };
639
+
640
+ /**
641
+ * Gets the high 32 bits as an unsigned integer.
642
+ * @this {!Long}
643
+ * @returns {number} Unsigned high bits
644
+ */
645
+ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
646
+ return this.high >>> 0;
647
+ };
648
+
649
+ /**
650
+ * Gets the low 32 bits as a signed integer.
651
+ * @this {!Long}
652
+ * @returns {number} Signed low bits
653
+ */
654
+ LongPrototype.getLowBits = function getLowBits() {
655
+ return this.low;
656
+ };
657
+
658
+ /**
659
+ * Gets the low 32 bits as an unsigned integer.
660
+ * @this {!Long}
661
+ * @returns {number} Unsigned low bits
662
+ */
663
+ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
664
+ return this.low >>> 0;
665
+ };
666
+
667
+ /**
668
+ * Gets the number of bits needed to represent the absolute value of this Long.
669
+ * @this {!Long}
670
+ * @returns {number}
671
+ */
672
+ LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
673
+ if (this.isNegative()) // Unsigned Longs are never negative
674
+ return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
675
+ var val = this.high != 0 ? this.high : this.low;
676
+ for (var bit = 31; bit > 0; bit--)
677
+ if ((val & (1 << bit)) != 0)
678
+ break;
679
+ return this.high != 0 ? bit + 33 : bit + 1;
680
+ };
681
+
682
+ /**
683
+ * Tests if this Long's value equals zero.
684
+ * @this {!Long}
685
+ * @returns {boolean}
686
+ */
687
+ LongPrototype.isZero = function isZero() {
688
+ return this.high === 0 && this.low === 0;
689
+ };
690
+
691
+ /**
692
+ * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
693
+ * @returns {boolean}
694
+ */
695
+ LongPrototype.eqz = LongPrototype.isZero;
696
+
697
+ /**
698
+ * Tests if this Long's value is negative.
699
+ * @this {!Long}
700
+ * @returns {boolean}
701
+ */
702
+ LongPrototype.isNegative = function isNegative() {
703
+ return !this.unsigned && this.high < 0;
704
+ };
705
+
706
+ /**
707
+ * Tests if this Long's value is positive or zero.
708
+ * @this {!Long}
709
+ * @returns {boolean}
710
+ */
711
+ LongPrototype.isPositive = function isPositive() {
712
+ return this.unsigned || this.high >= 0;
713
+ };
714
+
715
+ /**
716
+ * Tests if this Long's value is odd.
717
+ * @this {!Long}
718
+ * @returns {boolean}
719
+ */
720
+ LongPrototype.isOdd = function isOdd() {
721
+ return (this.low & 1) === 1;
722
+ };
723
+
724
+ /**
725
+ * Tests if this Long's value is even.
726
+ * @this {!Long}
727
+ * @returns {boolean}
728
+ */
729
+ LongPrototype.isEven = function isEven() {
730
+ return (this.low & 1) === 0;
731
+ };
732
+
733
+ /**
734
+ * Tests if this Long's value equals the specified's.
735
+ * @this {!Long}
736
+ * @param {!Long|number|string} other Other value
737
+ * @returns {boolean}
738
+ */
739
+ LongPrototype.equals = function equals(other) {
740
+ if (!isLong(other))
741
+ other = fromValue(other);
742
+ if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
743
+ return false;
744
+ return this.high === other.high && this.low === other.low;
745
+ };
746
+
747
+ /**
748
+ * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
749
+ * @function
750
+ * @param {!Long|number|string} other Other value
751
+ * @returns {boolean}
752
+ */
753
+ LongPrototype.eq = LongPrototype.equals;
754
+
755
+ /**
756
+ * Tests if this Long's value differs from the specified's.
757
+ * @this {!Long}
758
+ * @param {!Long|number|string} other Other value
759
+ * @returns {boolean}
760
+ */
761
+ LongPrototype.notEquals = function notEquals(other) {
762
+ return !this.eq(/* validates */ other);
763
+ };
764
+
765
+ /**
766
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
767
+ * @function
768
+ * @param {!Long|number|string} other Other value
769
+ * @returns {boolean}
770
+ */
771
+ LongPrototype.neq = LongPrototype.notEquals;
772
+
773
+ /**
774
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
775
+ * @function
776
+ * @param {!Long|number|string} other Other value
777
+ * @returns {boolean}
778
+ */
779
+ LongPrototype.ne = LongPrototype.notEquals;
780
+
781
+ /**
782
+ * Tests if this Long's value is less than the specified's.
783
+ * @this {!Long}
784
+ * @param {!Long|number|string} other Other value
785
+ * @returns {boolean}
786
+ */
787
+ LongPrototype.lessThan = function lessThan(other) {
788
+ return this.comp(/* validates */ other) < 0;
789
+ };
790
+
791
+ /**
792
+ * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
793
+ * @function
794
+ * @param {!Long|number|string} other Other value
795
+ * @returns {boolean}
796
+ */
797
+ LongPrototype.lt = LongPrototype.lessThan;
798
+
799
+ /**
800
+ * Tests if this Long's value is less than or equal the specified's.
801
+ * @this {!Long}
802
+ * @param {!Long|number|string} other Other value
803
+ * @returns {boolean}
804
+ */
805
+ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
806
+ return this.comp(/* validates */ other) <= 0;
807
+ };
808
+
809
+ /**
810
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
811
+ * @function
812
+ * @param {!Long|number|string} other Other value
813
+ * @returns {boolean}
814
+ */
815
+ LongPrototype.lte = LongPrototype.lessThanOrEqual;
816
+
817
+ /**
818
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
819
+ * @function
820
+ * @param {!Long|number|string} other Other value
821
+ * @returns {boolean}
822
+ */
823
+ LongPrototype.le = LongPrototype.lessThanOrEqual;
824
+
825
+ /**
826
+ * Tests if this Long's value is greater than the specified's.
827
+ * @this {!Long}
828
+ * @param {!Long|number|string} other Other value
829
+ * @returns {boolean}
830
+ */
831
+ LongPrototype.greaterThan = function greaterThan(other) {
832
+ return this.comp(/* validates */ other) > 0;
833
+ };
834
+
835
+ /**
836
+ * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
837
+ * @function
838
+ * @param {!Long|number|string} other Other value
839
+ * @returns {boolean}
840
+ */
841
+ LongPrototype.gt = LongPrototype.greaterThan;
842
+
843
+ /**
844
+ * Tests if this Long's value is greater than or equal the specified's.
845
+ * @this {!Long}
846
+ * @param {!Long|number|string} other Other value
847
+ * @returns {boolean}
848
+ */
849
+ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
850
+ return this.comp(/* validates */ other) >= 0;
851
+ };
852
+
853
+ /**
854
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
855
+ * @function
856
+ * @param {!Long|number|string} other Other value
857
+ * @returns {boolean}
858
+ */
859
+ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
860
+
861
+ /**
862
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
863
+ * @function
864
+ * @param {!Long|number|string} other Other value
865
+ * @returns {boolean}
866
+ */
867
+ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
868
+
869
+ /**
870
+ * Compares this Long's value with the specified's.
871
+ * @this {!Long}
872
+ * @param {!Long|number|string} other Other value
873
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
874
+ * if the given one is greater
875
+ */
876
+ LongPrototype.compare = function compare(other) {
877
+ if (!isLong(other))
878
+ other = fromValue(other);
879
+ if (this.eq(other))
880
+ return 0;
881
+ var thisNeg = this.isNegative(),
882
+ otherNeg = other.isNegative();
883
+ if (thisNeg && !otherNeg)
884
+ return -1;
885
+ if (!thisNeg && otherNeg)
886
+ return 1;
887
+ // At this point the sign bits are the same
888
+ if (!this.unsigned)
889
+ return this.sub(other).isNegative() ? -1 : 1;
890
+ // Both are positive if at least one is unsigned
891
+ return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
892
+ };
893
+
894
+ /**
895
+ * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
896
+ * @function
897
+ * @param {!Long|number|string} other Other value
898
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
899
+ * if the given one is greater
900
+ */
901
+ LongPrototype.comp = LongPrototype.compare;
902
+
903
+ /**
904
+ * Negates this Long's value.
905
+ * @this {!Long}
906
+ * @returns {!Long} Negated Long
907
+ */
908
+ LongPrototype.negate = function negate() {
909
+ if (!this.unsigned && this.eq(MIN_VALUE))
910
+ return MIN_VALUE;
911
+ return this.not().add(ONE);
912
+ };
913
+
914
+ /**
915
+ * Negates this Long's value. This is an alias of {@link Long#negate}.
916
+ * @function
917
+ * @returns {!Long} Negated Long
918
+ */
919
+ LongPrototype.neg = LongPrototype.negate;
920
+
921
+ /**
922
+ * Returns the sum of this and the specified Long.
923
+ * @this {!Long}
924
+ * @param {!Long|number|string} addend Addend
925
+ * @returns {!Long} Sum
926
+ */
927
+ LongPrototype.add = function add(addend) {
928
+ if (!isLong(addend))
929
+ addend = fromValue(addend);
930
+
931
+ // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
932
+
933
+ var a48 = this.high >>> 16;
934
+ var a32 = this.high & 0xFFFF;
935
+ var a16 = this.low >>> 16;
936
+ var a00 = this.low & 0xFFFF;
937
+
938
+ var b48 = addend.high >>> 16;
939
+ var b32 = addend.high & 0xFFFF;
940
+ var b16 = addend.low >>> 16;
941
+ var b00 = addend.low & 0xFFFF;
942
+
943
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
944
+ c00 += a00 + b00;
945
+ c16 += c00 >>> 16;
946
+ c00 &= 0xFFFF;
947
+ c16 += a16 + b16;
948
+ c32 += c16 >>> 16;
949
+ c16 &= 0xFFFF;
950
+ c32 += a32 + b32;
951
+ c48 += c32 >>> 16;
952
+ c32 &= 0xFFFF;
953
+ c48 += a48 + b48;
954
+ c48 &= 0xFFFF;
955
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
956
+ };
957
+
958
+ /**
959
+ * Returns the difference of this and the specified Long.
960
+ * @this {!Long}
961
+ * @param {!Long|number|string} subtrahend Subtrahend
962
+ * @returns {!Long} Difference
963
+ */
964
+ LongPrototype.subtract = function subtract(subtrahend) {
965
+ if (!isLong(subtrahend))
966
+ subtrahend = fromValue(subtrahend);
967
+ return this.add(subtrahend.neg());
968
+ };
969
+
970
+ /**
971
+ * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
972
+ * @function
973
+ * @param {!Long|number|string} subtrahend Subtrahend
974
+ * @returns {!Long} Difference
975
+ */
976
+ LongPrototype.sub = LongPrototype.subtract;
977
+
978
+ /**
979
+ * Returns the product of this and the specified Long.
980
+ * @this {!Long}
981
+ * @param {!Long|number|string} multiplier Multiplier
982
+ * @returns {!Long} Product
983
+ */
984
+ LongPrototype.multiply = function multiply(multiplier) {
985
+ if (this.isZero())
986
+ return this;
987
+ if (!isLong(multiplier))
988
+ multiplier = fromValue(multiplier);
989
+
990
+ // use wasm support if present
991
+ if (wasm) {
992
+ var low = wasm["mul"](this.low,
993
+ this.high,
994
+ multiplier.low,
995
+ multiplier.high);
996
+ return fromBits(low, wasm["get_high"](), this.unsigned);
997
+ }
998
+
999
+ if (multiplier.isZero())
1000
+ return this.unsigned ? UZERO : ZERO;
1001
+ if (this.eq(MIN_VALUE))
1002
+ return multiplier.isOdd() ? MIN_VALUE : ZERO;
1003
+ if (multiplier.eq(MIN_VALUE))
1004
+ return this.isOdd() ? MIN_VALUE : ZERO;
1005
+
1006
+ if (this.isNegative()) {
1007
+ if (multiplier.isNegative())
1008
+ return this.neg().mul(multiplier.neg());
1009
+ else
1010
+ return this.neg().mul(multiplier).neg();
1011
+ } else if (multiplier.isNegative())
1012
+ return this.mul(multiplier.neg()).neg();
1013
+
1014
+ // If both longs are small, use float multiplication
1015
+ if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
1016
+ return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
1017
+
1018
+ // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
1019
+ // We can skip products that would overflow.
1020
+
1021
+ var a48 = this.high >>> 16;
1022
+ var a32 = this.high & 0xFFFF;
1023
+ var a16 = this.low >>> 16;
1024
+ var a00 = this.low & 0xFFFF;
1025
+
1026
+ var b48 = multiplier.high >>> 16;
1027
+ var b32 = multiplier.high & 0xFFFF;
1028
+ var b16 = multiplier.low >>> 16;
1029
+ var b00 = multiplier.low & 0xFFFF;
1030
+
1031
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
1032
+ c00 += a00 * b00;
1033
+ c16 += c00 >>> 16;
1034
+ c00 &= 0xFFFF;
1035
+ c16 += a16 * b00;
1036
+ c32 += c16 >>> 16;
1037
+ c16 &= 0xFFFF;
1038
+ c16 += a00 * b16;
1039
+ c32 += c16 >>> 16;
1040
+ c16 &= 0xFFFF;
1041
+ c32 += a32 * b00;
1042
+ c48 += c32 >>> 16;
1043
+ c32 &= 0xFFFF;
1044
+ c32 += a16 * b16;
1045
+ c48 += c32 >>> 16;
1046
+ c32 &= 0xFFFF;
1047
+ c32 += a00 * b32;
1048
+ c48 += c32 >>> 16;
1049
+ c32 &= 0xFFFF;
1050
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
1051
+ c48 &= 0xFFFF;
1052
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
1053
+ };
1054
+
1055
+ /**
1056
+ * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
1057
+ * @function
1058
+ * @param {!Long|number|string} multiplier Multiplier
1059
+ * @returns {!Long} Product
1060
+ */
1061
+ LongPrototype.mul = LongPrototype.multiply;
1062
+
1063
+ /**
1064
+ * Returns this Long divided by the specified. The result is signed if this Long is signed or
1065
+ * unsigned if this Long is unsigned.
1066
+ * @this {!Long}
1067
+ * @param {!Long|number|string} divisor Divisor
1068
+ * @returns {!Long} Quotient
1069
+ */
1070
+ LongPrototype.divide = function divide(divisor) {
1071
+ if (!isLong(divisor))
1072
+ divisor = fromValue(divisor);
1073
+ if (divisor.isZero())
1074
+ throw Error('division by zero');
1075
+
1076
+ // use wasm support if present
1077
+ if (wasm) {
1078
+ // guard against signed division overflow: the largest
1079
+ // negative number / -1 would be 1 larger than the largest
1080
+ // positive number, due to two's complement.
1081
+ if (!this.unsigned &&
1082
+ this.high === -0x80000000 &&
1083
+ divisor.low === -1 && divisor.high === -1) {
1084
+ // be consistent with non-wasm code path
1085
+ return this;
1086
+ }
1087
+ var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(
1088
+ this.low,
1089
+ this.high,
1090
+ divisor.low,
1091
+ divisor.high
1092
+ );
1093
+ return fromBits(low, wasm["get_high"](), this.unsigned);
1094
+ }
1095
+
1096
+ if (this.isZero())
1097
+ return this.unsigned ? UZERO : ZERO;
1098
+ var approx, rem, res;
1099
+ if (!this.unsigned) {
1100
+ // This section is only relevant for signed longs and is derived from the
1101
+ // closure library as a whole.
1102
+ if (this.eq(MIN_VALUE)) {
1103
+ if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
1104
+ return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
1105
+ else if (divisor.eq(MIN_VALUE))
1106
+ return ONE;
1107
+ else {
1108
+ // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
1109
+ var halfThis = this.shr(1);
1110
+ approx = halfThis.div(divisor).shl(1);
1111
+ if (approx.eq(ZERO)) {
1112
+ return divisor.isNegative() ? ONE : NEG_ONE;
1113
+ } else {
1114
+ rem = this.sub(divisor.mul(approx));
1115
+ res = approx.add(rem.div(divisor));
1116
+ return res;
1117
+ }
1118
+ }
1119
+ } else if (divisor.eq(MIN_VALUE))
1120
+ return this.unsigned ? UZERO : ZERO;
1121
+ if (this.isNegative()) {
1122
+ if (divisor.isNegative())
1123
+ return this.neg().div(divisor.neg());
1124
+ return this.neg().div(divisor).neg();
1125
+ } else if (divisor.isNegative())
1126
+ return this.div(divisor.neg()).neg();
1127
+ res = ZERO;
1128
+ } else {
1129
+ // The algorithm below has not been made for unsigned longs. It's therefore
1130
+ // required to take special care of the MSB prior to running it.
1131
+ if (!divisor.unsigned)
1132
+ divisor = divisor.toUnsigned();
1133
+ if (divisor.gt(this))
1134
+ return UZERO;
1135
+ if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
1136
+ return UONE;
1137
+ res = UZERO;
1138
+ }
1139
+
1140
+ // Repeat the following until the remainder is less than other: find a
1141
+ // floating-point that approximates remainder / other *from below*, add this
1142
+ // into the result, and subtract it from the remainder. It is critical that
1143
+ // the approximate value is less than or equal to the real value so that the
1144
+ // remainder never becomes negative.
1145
+ rem = this;
1146
+ while (rem.gte(divisor)) {
1147
+ // Approximate the result of division. This may be a little greater or
1148
+ // smaller than the actual value.
1149
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
1150
+
1151
+ // We will tweak the approximate result by changing it in the 48-th digit or
1152
+ // the smallest non-fractional digit, whichever is larger.
1153
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2),
1154
+ delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
1155
+
1156
+ // Decrease the approximation until it is smaller than the remainder. Note
1157
+ // that if it is too large, the product overflows and is negative.
1158
+ approxRes = fromNumber(approx),
1159
+ approxRem = approxRes.mul(divisor);
1160
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
1161
+ approx -= delta;
1162
+ approxRes = fromNumber(approx, this.unsigned);
1163
+ approxRem = approxRes.mul(divisor);
1164
+ }
1165
+
1166
+ // We know the answer can't be zero... and actually, zero would cause
1167
+ // infinite recursion since we would make no progress.
1168
+ if (approxRes.isZero())
1169
+ approxRes = ONE;
1170
+
1171
+ res = res.add(approxRes);
1172
+ rem = rem.sub(approxRem);
1173
+ }
1174
+ return res;
1175
+ };
1176
+
1177
+ /**
1178
+ * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
1179
+ * @function
1180
+ * @param {!Long|number|string} divisor Divisor
1181
+ * @returns {!Long} Quotient
1182
+ */
1183
+ LongPrototype.div = LongPrototype.divide;
1184
+
1185
+ /**
1186
+ * Returns this Long modulo the specified.
1187
+ * @this {!Long}
1188
+ * @param {!Long|number|string} divisor Divisor
1189
+ * @returns {!Long} Remainder
1190
+ */
1191
+ LongPrototype.modulo = function modulo(divisor) {
1192
+ if (!isLong(divisor))
1193
+ divisor = fromValue(divisor);
1194
+
1195
+ // use wasm support if present
1196
+ if (wasm) {
1197
+ var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(
1198
+ this.low,
1199
+ this.high,
1200
+ divisor.low,
1201
+ divisor.high
1202
+ );
1203
+ return fromBits(low, wasm["get_high"](), this.unsigned);
1204
+ }
1205
+
1206
+ return this.sub(this.div(divisor).mul(divisor));
1207
+ };
1208
+
1209
+ /**
1210
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
1211
+ * @function
1212
+ * @param {!Long|number|string} divisor Divisor
1213
+ * @returns {!Long} Remainder
1214
+ */
1215
+ LongPrototype.mod = LongPrototype.modulo;
1216
+
1217
+ /**
1218
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
1219
+ * @function
1220
+ * @param {!Long|number|string} divisor Divisor
1221
+ * @returns {!Long} Remainder
1222
+ */
1223
+ LongPrototype.rem = LongPrototype.modulo;
1224
+
1225
+ /**
1226
+ * Returns the bitwise NOT of this Long.
1227
+ * @this {!Long}
1228
+ * @returns {!Long}
1229
+ */
1230
+ LongPrototype.not = function not() {
1231
+ return fromBits(~this.low, ~this.high, this.unsigned);
1232
+ };
1233
+
1234
+ /**
1235
+ * Returns count leading zeros of this Long.
1236
+ * @this {!Long}
1237
+ * @returns {!number}
1238
+ */
1239
+ LongPrototype.countLeadingZeros = function countLeadingZeros() {
1240
+ return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
1241
+ };
1242
+
1243
+ /**
1244
+ * Returns count leading zeros. This is an alias of {@link Long#countLeadingZeros}.
1245
+ * @function
1246
+ * @param {!Long}
1247
+ * @returns {!number}
1248
+ */
1249
+ LongPrototype.clz = LongPrototype.countLeadingZeros;
1250
+
1251
+ /**
1252
+ * Returns count trailing zeros of this Long.
1253
+ * @this {!Long}
1254
+ * @returns {!number}
1255
+ */
1256
+ LongPrototype.countTrailingZeros = function countTrailingZeros() {
1257
+ return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
1258
+ };
1259
+
1260
+ /**
1261
+ * Returns count trailing zeros. This is an alias of {@link Long#countTrailingZeros}.
1262
+ * @function
1263
+ * @param {!Long}
1264
+ * @returns {!number}
1265
+ */
1266
+ LongPrototype.ctz = LongPrototype.countTrailingZeros;
1267
+
1268
+ /**
1269
+ * Returns the bitwise AND of this Long and the specified.
1270
+ * @this {!Long}
1271
+ * @param {!Long|number|string} other Other Long
1272
+ * @returns {!Long}
1273
+ */
1274
+ LongPrototype.and = function and(other) {
1275
+ if (!isLong(other))
1276
+ other = fromValue(other);
1277
+ return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
1278
+ };
1279
+
1280
+ /**
1281
+ * Returns the bitwise OR of this Long and the specified.
1282
+ * @this {!Long}
1283
+ * @param {!Long|number|string} other Other Long
1284
+ * @returns {!Long}
1285
+ */
1286
+ LongPrototype.or = function or(other) {
1287
+ if (!isLong(other))
1288
+ other = fromValue(other);
1289
+ return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
1290
+ };
1291
+
1292
+ /**
1293
+ * Returns the bitwise XOR of this Long and the given one.
1294
+ * @this {!Long}
1295
+ * @param {!Long|number|string} other Other Long
1296
+ * @returns {!Long}
1297
+ */
1298
+ LongPrototype.xor = function xor(other) {
1299
+ if (!isLong(other))
1300
+ other = fromValue(other);
1301
+ return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
1302
+ };
1303
+
1304
+ /**
1305
+ * Returns this Long with bits shifted to the left by the given amount.
1306
+ * @this {!Long}
1307
+ * @param {number|!Long} numBits Number of bits
1308
+ * @returns {!Long} Shifted Long
1309
+ */
1310
+ LongPrototype.shiftLeft = function shiftLeft(numBits) {
1311
+ if (isLong(numBits))
1312
+ numBits = numBits.toInt();
1313
+ if ((numBits &= 63) === 0)
1314
+ return this;
1315
+ else if (numBits < 32)
1316
+ return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
1317
+ else
1318
+ return fromBits(0, this.low << (numBits - 32), this.unsigned);
1319
+ };
1320
+
1321
+ /**
1322
+ * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
1323
+ * @function
1324
+ * @param {number|!Long} numBits Number of bits
1325
+ * @returns {!Long} Shifted Long
1326
+ */
1327
+ LongPrototype.shl = LongPrototype.shiftLeft;
1328
+
1329
+ /**
1330
+ * Returns this Long with bits arithmetically shifted to the right by the given amount.
1331
+ * @this {!Long}
1332
+ * @param {number|!Long} numBits Number of bits
1333
+ * @returns {!Long} Shifted Long
1334
+ */
1335
+ LongPrototype.shiftRight = function shiftRight(numBits) {
1336
+ if (isLong(numBits))
1337
+ numBits = numBits.toInt();
1338
+ if ((numBits &= 63) === 0)
1339
+ return this;
1340
+ else if (numBits < 32)
1341
+ return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
1342
+ else
1343
+ return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
1344
+ };
1345
+
1346
+ /**
1347
+ * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
1348
+ * @function
1349
+ * @param {number|!Long} numBits Number of bits
1350
+ * @returns {!Long} Shifted Long
1351
+ */
1352
+ LongPrototype.shr = LongPrototype.shiftRight;
1353
+
1354
+ /**
1355
+ * Returns this Long with bits logically shifted to the right by the given amount.
1356
+ * @this {!Long}
1357
+ * @param {number|!Long} numBits Number of bits
1358
+ * @returns {!Long} Shifted Long
1359
+ */
1360
+ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
1361
+ if (isLong(numBits)) numBits = numBits.toInt();
1362
+ if ((numBits &= 63) === 0) return this;
1363
+ if (numBits < 32) return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >>> numBits, this.unsigned);
1364
+ if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
1365
+ return fromBits(this.high >>> (numBits - 32), 0, this.unsigned);
1366
+ };
1367
+
1368
+ /**
1369
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
1370
+ * @function
1371
+ * @param {number|!Long} numBits Number of bits
1372
+ * @returns {!Long} Shifted Long
1373
+ */
1374
+ LongPrototype.shru = LongPrototype.shiftRightUnsigned;
1375
+
1376
+ /**
1377
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
1378
+ * @function
1379
+ * @param {number|!Long} numBits Number of bits
1380
+ * @returns {!Long} Shifted Long
1381
+ */
1382
+ LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
1383
+
1384
+ /**
1385
+ * Returns this Long with bits rotated to the left by the given amount.
1386
+ * @this {!Long}
1387
+ * @param {number|!Long} numBits Number of bits
1388
+ * @returns {!Long} Rotated Long
1389
+ */
1390
+ LongPrototype.rotateLeft = function rotateLeft(numBits) {
1391
+ var b;
1392
+ if (isLong(numBits)) numBits = numBits.toInt();
1393
+ if ((numBits &= 63) === 0) return this;
1394
+ if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
1395
+ if (numBits < 32) {
1396
+ b = (32 - numBits);
1397
+ return fromBits(((this.low << numBits) | (this.high >>> b)), ((this.high << numBits) | (this.low >>> b)), this.unsigned);
1398
+ }
1399
+ numBits -= 32;
1400
+ b = (32 - numBits);
1401
+ return fromBits(((this.high << numBits) | (this.low >>> b)), ((this.low << numBits) | (this.high >>> b)), this.unsigned);
1402
+ };
1403
+ /**
1404
+ * Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}.
1405
+ * @function
1406
+ * @param {number|!Long} numBits Number of bits
1407
+ * @returns {!Long} Rotated Long
1408
+ */
1409
+ LongPrototype.rotl = LongPrototype.rotateLeft;
1410
+
1411
+ /**
1412
+ * Returns this Long with bits rotated to the right by the given amount.
1413
+ * @this {!Long}
1414
+ * @param {number|!Long} numBits Number of bits
1415
+ * @returns {!Long} Rotated Long
1416
+ */
1417
+ LongPrototype.rotateRight = function rotateRight(numBits) {
1418
+ var b;
1419
+ if (isLong(numBits)) numBits = numBits.toInt();
1420
+ if ((numBits &= 63) === 0) return this;
1421
+ if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
1422
+ if (numBits < 32) {
1423
+ b = (32 - numBits);
1424
+ return fromBits(((this.high << b) | (this.low >>> numBits)), ((this.low << b) | (this.high >>> numBits)), this.unsigned);
1425
+ }
1426
+ numBits -= 32;
1427
+ b = (32 - numBits);
1428
+ return fromBits(((this.low << b) | (this.high >>> numBits)), ((this.high << b) | (this.low >>> numBits)), this.unsigned);
1429
+ };
1430
+ /**
1431
+ * Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}.
1432
+ * @function
1433
+ * @param {number|!Long} numBits Number of bits
1434
+ * @returns {!Long} Rotated Long
1435
+ */
1436
+ LongPrototype.rotr = LongPrototype.rotateRight;
1437
+
1438
+ /**
1439
+ * Converts this Long to signed.
1440
+ * @this {!Long}
1441
+ * @returns {!Long} Signed long
1442
+ */
1443
+ LongPrototype.toSigned = function toSigned() {
1444
+ if (!this.unsigned)
1445
+ return this;
1446
+ return fromBits(this.low, this.high, false);
1447
+ };
1448
+
1449
+ /**
1450
+ * Converts this Long to unsigned.
1451
+ * @this {!Long}
1452
+ * @returns {!Long} Unsigned long
1453
+ */
1454
+ LongPrototype.toUnsigned = function toUnsigned() {
1455
+ if (this.unsigned)
1456
+ return this;
1457
+ return fromBits(this.low, this.high, true);
1458
+ };
1459
+
1460
+ /**
1461
+ * Converts this Long to its byte representation.
1462
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
1463
+ * @this {!Long}
1464
+ * @returns {!Array.<number>} Byte representation
1465
+ */
1466
+ LongPrototype.toBytes = function toBytes(le) {
1467
+ return le ? this.toBytesLE() : this.toBytesBE();
1468
+ };
1469
+
1470
+ /**
1471
+ * Converts this Long to its little endian byte representation.
1472
+ * @this {!Long}
1473
+ * @returns {!Array.<number>} Little endian byte representation
1474
+ */
1475
+ LongPrototype.toBytesLE = function toBytesLE() {
1476
+ var hi = this.high,
1477
+ lo = this.low;
1478
+ return [
1479
+ lo & 0xff,
1480
+ lo >>> 8 & 0xff,
1481
+ lo >>> 16 & 0xff,
1482
+ lo >>> 24,
1483
+ hi & 0xff,
1484
+ hi >>> 8 & 0xff,
1485
+ hi >>> 16 & 0xff,
1486
+ hi >>> 24
1487
+ ];
1488
+ };
1489
+
1490
+ /**
1491
+ * Converts this Long to its big endian byte representation.
1492
+ * @this {!Long}
1493
+ * @returns {!Array.<number>} Big endian byte representation
1494
+ */
1495
+ LongPrototype.toBytesBE = function toBytesBE() {
1496
+ var hi = this.high,
1497
+ lo = this.low;
1498
+ return [
1499
+ hi >>> 24,
1500
+ hi >>> 16 & 0xff,
1501
+ hi >>> 8 & 0xff,
1502
+ hi & 0xff,
1503
+ lo >>> 24,
1504
+ lo >>> 16 & 0xff,
1505
+ lo >>> 8 & 0xff,
1506
+ lo & 0xff
1507
+ ];
1508
+ };
1509
+
1510
+ /**
1511
+ * Creates a Long from its byte representation.
1512
+ * @param {!Array.<number>} bytes Byte representation
1513
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1514
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
1515
+ * @returns {Long} The corresponding Long value
1516
+ */
1517
+ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
1518
+ return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
1519
+ };
1520
+
1521
+ /**
1522
+ * Creates a Long from its little endian byte representation.
1523
+ * @param {!Array.<number>} bytes Little endian byte representation
1524
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1525
+ * @returns {Long} The corresponding Long value
1526
+ */
1527
+ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
1528
+ return new Long(
1529
+ bytes[0] |
1530
+ bytes[1] << 8 |
1531
+ bytes[2] << 16 |
1532
+ bytes[3] << 24,
1533
+ bytes[4] |
1534
+ bytes[5] << 8 |
1535
+ bytes[6] << 16 |
1536
+ bytes[7] << 24,
1537
+ unsigned
1538
+ );
1539
+ };
1540
+
1541
+ /**
1542
+ * Creates a Long from its big endian byte representation.
1543
+ * @param {!Array.<number>} bytes Big endian byte representation
1544
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1545
+ * @returns {Long} The corresponding Long value
1546
+ */
1547
+ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
1548
+ return new Long(
1549
+ bytes[4] << 24 |
1550
+ bytes[5] << 16 |
1551
+ bytes[6] << 8 |
1552
+ bytes[7],
1553
+ bytes[0] << 24 |
1554
+ bytes[1] << 16 |
1555
+ bytes[2] << 8 |
1556
+ bytes[3],
1557
+ unsigned
1558
+ );
1419
1559
  };
1420
1560
 
1561
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
1562
+
1421
1563
  var indexMinimal = {};
1422
1564
 
1423
1565
  var minimal$1 = {};
@@ -5823,8 +5965,8 @@ const ServiceClient = grpcJs.makeGenericClientConstructor(ServiceService, "flagd
5823
5965
  function longToString(long) {
5824
5966
  return long.toString();
5825
5967
  }
5826
- if (minimal.util.Long !== long) {
5827
- minimal.util.Long = long;
5968
+ if (minimal.util.Long !== Long) {
5969
+ minimal.util.Long = Long;
5828
5970
  minimal.configure();
5829
5971
  }
5830
5972
  function isObject$1(value) {