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