clojurific 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +3 -2
  2. package/cljf/launcher.js +15 -8
  3. package/package.json +2 -2
  4. package/compiler/deps.edn +0 -9
  5. package/compiler/src/main/cljs/cljs/analyzer/passes/and_or.cljc +0 -118
  6. package/compiler/src/main/cljs/cljs/analyzer/passes/lite.cljc +0 -32
  7. package/compiler/src/main/cljs/cljs/analyzer/passes.cljc +0 -32
  8. package/compiler/src/main/cljs/cljs/bootstrap_nodejs.js +0 -154
  9. package/compiler/src/main/cljs/cljs/core/specs/alpha.cljc +0 -272
  10. package/compiler/src/main/cljs/cljs/core/specs/alpha.cljs +0 -10
  11. package/compiler/src/main/cljs/cljs/core.cljs +0 -13194
  12. package/compiler/src/main/cljs/cljs/esm/goog/array.js +0 -61
  13. package/compiler/src/main/cljs/cljs/esm/goog/math.js +0 -1846
  14. package/compiler/src/main/cljs/cljs/esm/goog/object.js +0 -80
  15. package/compiler/src/main/cljs/cljs/esm/goog/string.js +0 -192
  16. package/compiler/src/main/cljs/cljs/esm/goog/userAgent/product.js +0 -10
  17. package/compiler/src/main/cljs/cljs/esm/goog.js +0 -90
  18. package/compiler/src/main/cljs/cljs/esm/karma.cljs +0 -103
  19. package/compiler/src/main/cljs/cljs/esm/lazy.clj +0 -51
  20. package/compiler/src/main/cljs/cljs/esm/lazy.cljs +0 -49
  21. package/compiler/src/main/cljs/cljs/esm/node_test.cljs +0 -21
  22. package/compiler/src/main/cljs/cljs/esm/repl_runtime.cljs +0 -353
  23. package/compiler/src/main/cljs/cljs/externs.js +0 -27
  24. package/compiler/src/main/cljs/cljs/imul.js +0 -11
  25. package/compiler/src/main/cljs/cljs/js.clj +0 -24
  26. package/compiler/src/main/cljs/cljs/js.cljs +0 -1432
  27. package/compiler/src/main/cljs/cljs/loader.cljs +0 -107
  28. package/compiler/src/main/cljs/cljs/main.clj +0 -67
  29. package/compiler/src/main/cljs/cljs/math.cljs +0 -869
  30. package/compiler/src/main/cljs/cljs/module_deps.js +0 -250
  31. package/compiler/src/main/cljs/cljs/nodejs.cljs +0 -27
  32. package/compiler/src/main/cljs/cljs/nodejs_externs.js +0 -3
  33. package/compiler/src/main/cljs/cljs/nodejscli.cljs +0 -22
  34. package/compiler/src/main/cljs/cljs/pprint.cljc +0 -167
  35. package/compiler/src/main/cljs/cljs/pprint.cljs +0 -3325
  36. package/compiler/src/main/cljs/cljs/proxy/impl.cljs +0 -32
  37. package/compiler/src/main/cljs/cljs/proxy.cljs +0 -184
  38. package/compiler/src/main/cljs/cljs/reader.clj +0 -18
  39. package/compiler/src/main/cljs/cljs/reader.cljs +0 -214
  40. package/compiler/src/main/cljs/cljs/repl.cljs +0 -206
  41. package/compiler/src/main/cljs/cljs/source_map/base64.cljs +0 -25
  42. package/compiler/src/main/cljs/cljs/source_map/base64_vlq.cljs +0 -102
  43. package/compiler/src/main/cljs/cljs/source_map.cljs +0 -305
  44. package/compiler/src/main/cljs/cljs/spec/alpha.cljc +0 -564
  45. package/compiler/src/main/cljs/cljs/spec/alpha.cljs +0 -1510
  46. package/compiler/src/main/cljs/cljs/spec/gen/alpha.cljc +0 -68
  47. package/compiler/src/main/cljs/cljs/spec/gen/alpha.cljs +0 -183
  48. package/compiler/src/main/cljs/cljs/spec/test/alpha.cljc +0 -329
  49. package/compiler/src/main/cljs/cljs/spec/test/alpha.cljs +0 -380
  50. package/compiler/src/main/cljs/cljs/stacktrace.cljc +0 -578
  51. package/compiler/src/main/cljs/cljs/test.cljc +0 -458
  52. package/compiler/src/main/cljs/cljs/test.cljs +0 -606
  53. package/compiler/src/main/cljs/clojure/browser/dom.cljs +0 -152
  54. package/compiler/src/main/cljs/clojure/browser/event.cljs +0 -101
  55. package/compiler/src/main/cljs/clojure/browser/net.cljs +0 -181
  56. package/compiler/src/main/cljs/clojure/browser/repl/preload.cljs +0 -13
  57. package/compiler/src/main/cljs/clojure/browser/repl.cljs +0 -283
  58. package/compiler/src/main/cljs/clojure/core/protocols.cljs +0 -29
  59. package/compiler/src/main/cljs/clojure/core/reducers.cljs +0 -312
  60. package/compiler/src/main/cljs/clojure/data.cljs +0 -162
  61. package/compiler/src/main/cljs/clojure/datafy.cljs +0 -63
  62. package/compiler/src/main/cljs/clojure/edn.cljs +0 -55
  63. package/compiler/src/main/cljs/clojure/reflect.cljs +0 -57
  64. package/compiler/src/main/cljs/clojure/set.cljs +0 -165
  65. package/compiler/src/main/cljs/clojure/string.cljs +0 -290
  66. package/compiler/src/main/cljs/clojure/walk.cljs +0 -98
  67. package/compiler/src/main/cljs/clojure/zip.cljs +0 -291
  68. package/compiler/src/main/cljs/process/env.cljs +0 -12
  69. package/compiler/src/main/cljs/shadow/resource.clj +0 -60
  70. package/compiler/src/main/cljs/shadow/resource.cljs +0 -10
  71. package/compiler/src/main/clojure/cljs/analyzer/api.cljc +0 -299
  72. package/compiler/src/main/clojure/cljs/analyzer/impl/namespaces.cljc +0 -68
  73. package/compiler/src/main/clojure/cljs/analyzer/impl.cljc +0 -59
  74. package/compiler/src/main/clojure/cljs/analyzer/macros.clj +0 -57
  75. package/compiler/src/main/clojure/cljs/analyzer/utils.clj +0 -36
  76. package/compiler/src/main/clojure/cljs/analyzer.cljc +0 -5292
  77. package/compiler/src/main/clojure/cljs/build/api.clj +0 -309
  78. package/compiler/src/main/clojure/cljs/cli.clj +0 -812
  79. package/compiler/src/main/clojure/cljs/closure.clj +0 -3440
  80. package/compiler/src/main/clojure/cljs/compiler/api.clj +0 -101
  81. package/compiler/src/main/clojure/cljs/compiler/macros.clj +0 -16
  82. package/compiler/src/main/clojure/cljs/compiler.cljc +0 -2748
  83. package/compiler/src/main/clojure/cljs/core/macros.clj +0 -43
  84. package/compiler/src/main/clojure/cljs/core/server.clj +0 -167
  85. package/compiler/src/main/clojure/cljs/core.cljc +0 -3719
  86. package/compiler/src/main/clojure/cljs/env/macros.clj +0 -37
  87. package/compiler/src/main/clojure/cljs/env.cljc +0 -102
  88. package/compiler/src/main/clojure/cljs/esm/repl/nrepl.clj +0 -151
  89. package/compiler/src/main/clojure/cljs/esm/repl.clj +0 -878
  90. package/compiler/src/main/clojure/cljs/esm.clj +0 -987
  91. package/compiler/src/main/clojure/cljs/externs/default.edn +0 -1549
  92. package/compiler/src/main/clojure/cljs/externs.clj +0 -479
  93. package/compiler/src/main/clojure/cljs/foreign/node.clj +0 -207
  94. package/compiler/src/main/clojure/cljs/instant.clj +0 -54
  95. package/compiler/src/main/clojure/cljs/js_deps.cljc +0 -412
  96. package/compiler/src/main/clojure/cljs/module_graph.cljc +0 -402
  97. package/compiler/src/main/clojure/cljs/repl/bootstrap.clj +0 -53
  98. package/compiler/src/main/clojure/cljs/repl/browser.clj +0 -540
  99. package/compiler/src/main/clojure/cljs/repl/node.clj +0 -253
  100. package/compiler/src/main/clojure/cljs/repl/node_repl.js +0 -114
  101. package/compiler/src/main/clojure/cljs/repl/reflect.clj +0 -85
  102. package/compiler/src/main/clojure/cljs/repl/server.clj +0 -236
  103. package/compiler/src/main/clojure/cljs/repl.cljc +0 -1615
  104. package/compiler/src/main/clojure/cljs/server/browser.clj +0 -54
  105. package/compiler/src/main/clojure/cljs/server/node.clj +0 -54
  106. package/compiler/src/main/clojure/cljs/source_map/base64.clj +0 -28
  107. package/compiler/src/main/clojure/cljs/source_map/base64_vlq.clj +0 -104
  108. package/compiler/src/main/clojure/cljs/source_map.clj +0 -369
  109. package/compiler/src/main/clojure/cljs/support.cljc +0 -18
  110. package/compiler/src/main/clojure/cljs/tagged_literals.cljc +0 -93
  111. package/compiler/src/main/clojure/cljs/util.cljc +0 -420
  112. package/compiler/src/main/clojure/cljs/vendor/bridge.clj +0 -42
  113. package/compiler/src/main/clojure/cljs/vendor/clojure/data/json.clj +0 -809
  114. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/default_data_readers.clj +0 -303
  115. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/edn.clj +0 -440
  116. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/commons.clj +0 -131
  117. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/errors.clj +0 -214
  118. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/inspect.clj +0 -91
  119. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/utils.clj +0 -127
  120. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/reader_types.clj +0 -431
  121. package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader.clj +0 -1035
  122. package/compiler/src/main/clojure/cljs/vendor/cognitect/transit.clj +0 -479
  123. /package/{compiler/no-clojurescript → no-clojurescript}/deps.edn +0 -0
@@ -1,1846 +0,0 @@
1
-
2
- // goog.math.Long and goog.math.Integer as an ES module, mechanically converted
3
- // from the Closure Library sources for :module-format :esm.
4
-
5
- function assert(condition, message) {
6
- if (!condition) throw new Error('Assertion failed: ' + message);
7
- }
8
-
9
- function reflectCache(cacheObj, key, valueFn, opt_keyFn) {
10
- const storedKey = opt_keyFn ? opt_keyFn(key) : key;
11
- if (Object.prototype.hasOwnProperty.call(cacheObj, storedKey)) {
12
- return cacheObj[storedKey];
13
- }
14
- return (cacheObj[storedKey] = valueFn(key));
15
- }
16
- /**
17
- * @license
18
- * Copyright The Closure Library Authors.
19
- * SPDX-License-Identifier: Apache-2.0
20
- */
21
-
22
- /**
23
- * @fileoverview Defines a Long class for representing a 64-bit two's-complement
24
- * integer value, which faithfully simulates the behavior of a Java "long". This
25
- * implementation is derived from LongLib in GWT.
26
- */
27
-
28
-
29
-
30
- /**
31
- * Represents a 64-bit two's-complement integer, given its low and high 32-bit
32
- * values as *signed* integers. See the from* functions below for more
33
- * convenient ways of constructing Longs.
34
- *
35
- * The internal representation of a long is the two given signed, 32-bit values.
36
- * We use 32-bit pieces because these are the size of integers on which
37
- * JavaScript performs bit-operations. For operations like addition and
38
- * multiplication, we split each number into 16-bit pieces, which can easily be
39
- * multiplied within JavaScript's floating-point representation without overflow
40
- * or change in sign.
41
- *
42
- * In the algorithms below, we frequently reduce the negative case to the
43
- * positive case by negating the input(s) and then post-processing the result.
44
- * Note that we must ALWAYS check specially whether those values are MIN_VALUE
45
- * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
46
- * a positive number, it overflows back into a negative). Not handling this
47
- * case would often result in infinite recursion.
48
- * @final
49
- */
50
- class Long {
51
- /**
52
- * @param {number} low The low (signed) 32 bits of the long.
53
- * @param {number} high The high (signed) 32 bits of the long.
54
- */
55
- constructor(low, high) {
56
- /**
57
- * @const {number}
58
- * @private
59
- */
60
- this.low_ = low | 0; // force into 32 signed bits.
61
-
62
- /**
63
- * @const {number}
64
- * @private
65
- */
66
- this.high_ = high | 0; // force into 32 signed bits.
67
- }
68
-
69
- /** @return {number} The value, assuming it is a 32-bit integer. */
70
- toInt() {
71
- return this.low_;
72
- }
73
-
74
- /**
75
- * @return {number} The closest floating-point representation to this value.
76
- */
77
- toNumber() {
78
- return this.high_ * TWO_PWR_32_DBL_ + this.getLowBitsUnsigned();
79
- }
80
-
81
- /**
82
- * @return {boolean} if can be exactly represented using number (i.e.
83
- * abs(value) < 2^53).
84
- */
85
- isSafeInteger() {
86
- var top11Bits = this.high_ >> 21;
87
- // If top11Bits are all 0s, then the number is between [0, 2^53-1]
88
- return top11Bits == 0
89
- // If top11Bits are all 1s, then the number is between [-1, -2^53]
90
- || (top11Bits == -1
91
- // and exclude -2^53
92
- && !(this.low_ == 0 && this.high_ == (0xffe00000 | 0)));
93
- }
94
-
95
- /**
96
- * @param {number=} opt_radix The radix in which the text should be written.
97
- * @return {string} The textual representation of this value.
98
- * @override
99
- */
100
- toString(opt_radix) {
101
- var radix = opt_radix || 10;
102
- if (radix < 2 || 36 < radix) {
103
- throw new Error('radix out of range: ' + radix);
104
- }
105
-
106
- // We can avoid very expensive division based code path for some common
107
- // cases.
108
- if (this.isSafeInteger()) {
109
- var asNumber = this.toNumber();
110
- // Shortcutting for radix 10 (common case) to avoid boxing via toString:
111
- // https://jsperf.com/tostring-vs-vs-if
112
- return radix == 10 ? ('' + asNumber) : asNumber.toString(radix);
113
- }
114
-
115
- // We need to split 64bit integer into: `a * radix**safeDigits + b` where
116
- // neither `a` nor `b` exceeds 53 bits, meaning that safeDigits can be any
117
- // number in a range: [(63 - 53) / log2(radix); 53 / log2(radix)].
118
-
119
- // Other options that need to be benchmarked:
120
- // 11..16 - (radix >> 2);
121
- // 10..13 - (radix >> 3);
122
- // 10..11 - (radix >> 4);
123
- var safeDigits = 14 - (radix >> 2);
124
-
125
- var radixPowSafeDigits = Math.pow(radix, safeDigits);
126
- var radixToPower =
127
- Long.fromBits(radixPowSafeDigits, radixPowSafeDigits / TWO_PWR_32_DBL_);
128
-
129
- var remDiv = this.div(radixToPower);
130
- var val = Math.abs(this.subtract(remDiv.multiply(radixToPower)).toNumber());
131
- var digits = radix == 10 ? ('' + val) : val.toString(radix);
132
-
133
- if (digits.length < safeDigits) {
134
- // Up to 13 leading 0s we might need to insert as the greatest safeDigits
135
- // value is 14 (for radix 2).
136
- digits = '0000000000000'.slice(digits.length - safeDigits) + digits;
137
- }
138
-
139
- val = remDiv.toNumber();
140
- return (radix == 10 ? val : val.toString(radix)) + digits;
141
- }
142
-
143
- /**
144
- * @param {number=} opt_radix The radix in which the text should be written.
145
- * @return {string} The unsigned textual representation of this value.
146
- */
147
- toUnsignedString(opt_radix) {
148
- // If the sign bit isn't even set just use the normal flow
149
- if (this.high_ >= 0) {
150
- return this.toString(opt_radix);
151
- }
152
-
153
- var radix = opt_radix || 10;
154
- if (radix < 2 || 36 < radix) {
155
- throw new Error('radix out of range: ' + radix);
156
- }
157
- // Use fromInt() to get the 64-bit representation of the radix as the entire
158
- // radix range should be cached.
159
- var longRadix = Long.fromInt(radix);
160
- // Divide as unsigned 64-bit numbers.
161
- var quotient = this.shiftRightUnsigned(1).div(longRadix).shiftLeft(1);
162
- var remainder = this.subtract(quotient.multiply(longRadix));
163
- // Check if we need to sign adjust the quotient.
164
- if (remainder.greaterThanOrEqual(longRadix)) {
165
- quotient = quotient.add(Long.getOne());
166
- remainder = this.subtract(quotient.multiply(longRadix));
167
- }
168
- return quotient.toString(radix) + remainder.toString(radix);
169
- }
170
-
171
- /** @return {number} The high 32-bits as a signed value. */
172
- getHighBits() {
173
- return this.high_;
174
- }
175
-
176
- /** @return {number} The low 32-bits as a signed value. */
177
- getLowBits() {
178
- return this.low_;
179
- }
180
-
181
- /** @return {number} The low 32-bits as an unsigned value. */
182
- getLowBitsUnsigned() {
183
- // The right shifting fixes negative values in the case when
184
- // intval >= 2^31; for more details see
185
- // https://github.com/google/closure-library/pull/498
186
- return this.low_ >>> 0;
187
- }
188
-
189
- /**
190
- * @return {number} Returns the number of bits needed to represent the
191
- * absolute value of this Long.
192
- */
193
- getNumBitsAbs() {
194
- if (this.isNegative()) {
195
- if (this.equals(Long.getMinValue())) {
196
- return 64;
197
- } else {
198
- return this.negate().getNumBitsAbs();
199
- }
200
- } else {
201
- var val = this.high_ != 0 ? this.high_ : this.low_;
202
- for (var bit = 31; bit > 0; bit--) {
203
- if ((val & (1 << bit)) != 0) {
204
- break;
205
- }
206
- }
207
- return this.high_ != 0 ? bit + 33 : bit + 1;
208
- }
209
- }
210
-
211
- /** @return {boolean} Whether this value is zero. */
212
- isZero() {
213
- // Check low part first as there is high chance it's not 0.
214
- return this.low_ == 0 && this.high_ == 0;
215
- }
216
-
217
- /** @return {boolean} Whether this value is negative. */
218
- isNegative() {
219
- return this.high_ < 0;
220
- }
221
-
222
- /** @return {boolean} Whether this value is odd. */
223
- isOdd() {
224
- return (this.low_ & 1) == 1;
225
- }
226
-
227
- /**
228
- * Returns a hash code for this long object that similar java.lang.Long one.
229
- *
230
- * @return {number} 32 bit hash code for this object.
231
- */
232
- hashCode() {
233
- return this.getLowBits() ^ this.getHighBits();
234
- }
235
-
236
- /**
237
- * @param {?Long} other Long to compare against.
238
- * @return {boolean} Whether this Long equals the other.
239
- */
240
- equals(other) {
241
- // Compare low parts first as there is higher chance they are different.
242
- return (this.low_ == other.low_) && (this.high_ == other.high_);
243
- }
244
-
245
- /**
246
- * @param {?Long} other Long to compare against.
247
- * @return {boolean} Whether this Long does not equal the other.
248
- */
249
- notEquals(other) {
250
- return !this.equals(other);
251
- }
252
-
253
- /**
254
- * @param {?Long} other Long to compare against.
255
- * @return {boolean} Whether this Long is less than the other.
256
- */
257
- lessThan(other) {
258
- return this.compare(other) < 0;
259
- }
260
-
261
- /**
262
- * @param {?Long} other Long to compare against.
263
- * @return {boolean} Whether this Long is less than or equal to the other.
264
- */
265
- lessThanOrEqual(other) {
266
- return this.compare(other) <= 0;
267
- }
268
-
269
- /**
270
- * @param {?Long} other Long to compare against.
271
- * @return {boolean} Whether this Long is greater than the other.
272
- */
273
- greaterThan(other) {
274
- return this.compare(other) > 0;
275
- }
276
-
277
- /**
278
- * @param {?Long} other Long to compare against.
279
- * @return {boolean} Whether this Long is greater than or equal to the other.
280
- */
281
- greaterThanOrEqual(other) {
282
- return this.compare(other) >= 0;
283
- }
284
-
285
- /**
286
- * Compares this Long with the given one.
287
- * @param {?Long} other Long to compare against.
288
- * @return {number} 0 if they are the same, 1 if the this is greater, and -1
289
- * if the given one is greater.
290
- */
291
- compare(other) {
292
- if (this.high_ == other.high_) {
293
- if (this.low_ == other.low_) {
294
- return 0;
295
- }
296
- return this.getLowBitsUnsigned() > other.getLowBitsUnsigned() ? 1 : -1;
297
- }
298
- return this.high_ > other.high_ ? 1 : -1;
299
- }
300
-
301
- /** @return {!Long} The negation of this value. */
302
- negate() {
303
- var negLow = (~this.low_ + 1) | 0;
304
- var overflowFromLow = !negLow;
305
- var negHigh = (~this.high_ + overflowFromLow) | 0;
306
- return Long.fromBits(negLow, negHigh);
307
- }
308
-
309
- /**
310
- * Returns the sum of this and the given Long.
311
- * @param {?Long} other Long to add to this one.
312
- * @return {!Long} The sum of this and the given Long.
313
- */
314
- add(other) {
315
- // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
316
-
317
- var a48 = this.high_ >>> 16;
318
- var a32 = this.high_ & 0xFFFF;
319
- var a16 = this.low_ >>> 16;
320
- var a00 = this.low_ & 0xFFFF;
321
-
322
- var b48 = other.high_ >>> 16;
323
- var b32 = other.high_ & 0xFFFF;
324
- var b16 = other.low_ >>> 16;
325
- var b00 = other.low_ & 0xFFFF;
326
-
327
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
328
- c00 += a00 + b00;
329
- c16 += c00 >>> 16;
330
- c00 &= 0xFFFF;
331
- c16 += a16 + b16;
332
- c32 += c16 >>> 16;
333
- c16 &= 0xFFFF;
334
- c32 += a32 + b32;
335
- c48 += c32 >>> 16;
336
- c32 &= 0xFFFF;
337
- c48 += a48 + b48;
338
- c48 &= 0xFFFF;
339
- return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
340
- }
341
-
342
- /**
343
- * Returns the difference of this and the given Long.
344
- * @param {?Long} other Long to subtract from this.
345
- * @return {!Long} The difference of this and the given Long.
346
- */
347
- subtract(other) {
348
- return this.add(other.negate());
349
- }
350
-
351
- /**
352
- * Returns the product of this and the given long.
353
- * @param {?Long} other Long to multiply with this.
354
- * @return {!Long} The product of this and the other.
355
- */
356
- multiply(other) {
357
- if (this.isZero()) {
358
- return this;
359
- }
360
- if (other.isZero()) {
361
- return other;
362
- }
363
-
364
- // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
365
- // We can skip products that would overflow.
366
-
367
- var a48 = this.high_ >>> 16;
368
- var a32 = this.high_ & 0xFFFF;
369
- var a16 = this.low_ >>> 16;
370
- var a00 = this.low_ & 0xFFFF;
371
-
372
- var b48 = other.high_ >>> 16;
373
- var b32 = other.high_ & 0xFFFF;
374
- var b16 = other.low_ >>> 16;
375
- var b00 = other.low_ & 0xFFFF;
376
-
377
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
378
- c00 += a00 * b00;
379
- c16 += c00 >>> 16;
380
- c00 &= 0xFFFF;
381
- c16 += a16 * b00;
382
- c32 += c16 >>> 16;
383
- c16 &= 0xFFFF;
384
- c16 += a00 * b16;
385
- c32 += c16 >>> 16;
386
- c16 &= 0xFFFF;
387
- c32 += a32 * b00;
388
- c48 += c32 >>> 16;
389
- c32 &= 0xFFFF;
390
- c32 += a16 * b16;
391
- c48 += c32 >>> 16;
392
- c32 &= 0xFFFF;
393
- c32 += a00 * b32;
394
- c48 += c32 >>> 16;
395
- c32 &= 0xFFFF;
396
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
397
- c48 &= 0xFFFF;
398
- return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
399
- }
400
-
401
- /**
402
- * Returns this Long divided by the given one.
403
- * @param {?Long} other Long by which to divide.
404
- * @return {!Long} This Long divided by the given one.
405
- */
406
- div(other) {
407
- if (other.isZero()) {
408
- throw new Error('division by zero');
409
- }
410
- if (this.isNegative()) {
411
- if (this.equals(Long.getMinValue())) {
412
- if (other.equals(Long.getOne()) || other.equals(Long.getNegOne())) {
413
- return Long.getMinValue(); // recall -MIN_VALUE == MIN_VALUE
414
- }
415
- if (other.equals(Long.getMinValue())) {
416
- return Long.getOne();
417
- }
418
- // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
419
- var halfThis = this.shiftRight(1);
420
- var approx = halfThis.div(other).shiftLeft(1);
421
- if (approx.equals(Long.getZero())) {
422
- return other.isNegative() ? Long.getOne() : Long.getNegOne();
423
- }
424
- var rem = this.subtract(other.multiply(approx));
425
- var result = approx.add(rem.div(other));
426
- return result;
427
- }
428
- if (other.isNegative()) {
429
- return this.negate().div(other.negate());
430
- }
431
- return this.negate().div(other).negate();
432
- }
433
- if (this.isZero()) {
434
- return Long.getZero();
435
- }
436
- if (other.isNegative()) {
437
- if (other.equals(Long.getMinValue())) {
438
- return Long.getZero();
439
- }
440
- return this.div(other.negate()).negate();
441
- }
442
-
443
- // Repeat the following until the remainder is less than other: find a
444
- // floating-point that approximates remainder / other *from below*, add this
445
- // into the result, and subtract it from the remainder. It is critical that
446
- // the approximate value is less than or equal to the real value so that the
447
- // remainder never becomes negative.
448
- var res = Long.getZero();
449
- var rem = this;
450
- while (rem.greaterThanOrEqual(other)) {
451
- // Approximate the result of division. This may be a little greater or
452
- // smaller than the actual value.
453
- var approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber()));
454
-
455
- // We will tweak the approximate result by changing it in the 48-th digit
456
- // or the smallest non-fractional digit, whichever is larger.
457
- var log2 = Math.ceil(Math.log(approx) / Math.LN2);
458
- var delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48);
459
-
460
- // Decrease the approximation until it is smaller than the remainder. Note
461
- // that if it is too large, the product overflows and is negative.
462
- var approxRes = Long.fromNumber(approx);
463
- var approxRem = approxRes.multiply(other);
464
- while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
465
- approx -= delta;
466
- approxRes = Long.fromNumber(approx);
467
- approxRem = approxRes.multiply(other);
468
- }
469
-
470
- // We know the answer can't be zero... and actually, zero would cause
471
- // infinite recursion since we would make no progress.
472
- if (approxRes.isZero()) {
473
- approxRes = Long.getOne();
474
- }
475
-
476
- res = res.add(approxRes);
477
- rem = rem.subtract(approxRem);
478
- }
479
- return res;
480
- }
481
-
482
- /**
483
- * Returns this Long modulo the given one.
484
- * @param {?Long} other Long by which to mod.
485
- * @return {!Long} This Long modulo the given one.
486
- */
487
- modulo(other) {
488
- return this.subtract(this.div(other).multiply(other));
489
- }
490
-
491
- /** @return {!Long} The bitwise-NOT of this value. */
492
- not() {
493
- return Long.fromBits(~this.low_, ~this.high_);
494
- }
495
-
496
- /**
497
- * Returns the bitwise-AND of this Long and the given one.
498
- * @param {?Long} other The Long with which to AND.
499
- * @return {!Long} The bitwise-AND of this and the other.
500
- */
501
- and(other) {
502
- return Long.fromBits(this.low_ & other.low_, this.high_ & other.high_);
503
- }
504
-
505
- /**
506
- * Returns the bitwise-OR of this Long and the given one.
507
- * @param {?Long} other The Long with which to OR.
508
- * @return {!Long} The bitwise-OR of this and the other.
509
- */
510
- or(other) {
511
- return Long.fromBits(this.low_ | other.low_, this.high_ | other.high_);
512
- }
513
-
514
- /**
515
- * Returns the bitwise-XOR of this Long and the given one.
516
- * @param {?Long} other The Long with which to XOR.
517
- * @return {!Long} The bitwise-XOR of this and the other.
518
- */
519
- xor(other) {
520
- return Long.fromBits(this.low_ ^ other.low_, this.high_ ^ other.high_);
521
- }
522
-
523
- /**
524
- * Returns this Long with bits shifted to the left by the given amount.
525
- * @param {number} numBits The number of bits by which to shift.
526
- * @return {!Long} This shifted to the left by the given amount.
527
- */
528
- shiftLeft(numBits) {
529
- numBits &= 63;
530
- if (numBits == 0) {
531
- return this;
532
- } else {
533
- var low = this.low_;
534
- if (numBits < 32) {
535
- var high = this.high_;
536
- return Long.fromBits(
537
- low << numBits, (high << numBits) | (low >>> (32 - numBits)));
538
- } else {
539
- return Long.fromBits(0, low << (numBits - 32));
540
- }
541
- }
542
- }
543
-
544
- /**
545
- * Returns this Long with bits shifted to the right by the given amount.
546
- * The new leading bits match the current sign bit.
547
- * @param {number} numBits The number of bits by which to shift.
548
- * @return {!Long} This shifted to the right by the given amount.
549
- */
550
- shiftRight(numBits) {
551
- numBits &= 63;
552
- if (numBits == 0) {
553
- return this;
554
- } else {
555
- var high = this.high_;
556
- if (numBits < 32) {
557
- var low = this.low_;
558
- return Long.fromBits(
559
- (low >>> numBits) | (high << (32 - numBits)), high >> numBits);
560
- } else {
561
- return Long.fromBits(high >> (numBits - 32), high >= 0 ? 0 : -1);
562
- }
563
- }
564
- }
565
-
566
- /**
567
- * Returns this Long with bits shifted to the right by the given amount, with
568
- * zeros placed into the new leading bits.
569
- * @param {number} numBits The number of bits by which to shift.
570
- * @return {!Long} This shifted to the right by the given amount,
571
- * with zeros placed into the new leading bits.
572
- */
573
- shiftRightUnsigned(numBits) {
574
- numBits &= 63;
575
- if (numBits == 0) {
576
- return this;
577
- } else {
578
- var high = this.high_;
579
- if (numBits < 32) {
580
- var low = this.low_;
581
- return Long.fromBits(
582
- (low >>> numBits) | (high << (32 - numBits)), high >>> numBits);
583
- } else if (numBits == 32) {
584
- return Long.fromBits(high, 0);
585
- } else {
586
- return Long.fromBits(high >>> (numBits - 32), 0);
587
- }
588
- }
589
- }
590
-
591
- /**
592
- * Returns a Long representing the given (32-bit) integer value.
593
- * @param {number} value The 32-bit integer in question.
594
- * @return {!Long} The corresponding Long value.
595
- */
596
- static fromInt(value) {
597
- var intValue = value | 0;
598
- assert(value === intValue, 'value should be a 32-bit integer');
599
-
600
- if (-128 <= intValue && intValue < 128) {
601
- return getCachedIntValue_(intValue);
602
- } else {
603
- return new Long(intValue, intValue < 0 ? -1 : 0);
604
- }
605
- }
606
-
607
- /**
608
- * Returns a Long representing the given value.
609
- * NaN will be returned as zero. Infinity is converted to max value and
610
- * -Infinity to min value.
611
- * @param {number} value The number in question.
612
- * @return {!Long} The corresponding Long value.
613
- */
614
- static fromNumber(value) {
615
- if (value > 0) {
616
- if (value >= TWO_PWR_63_DBL_) {
617
- return Long.getMaxValue();
618
- }
619
- return new Long(value, value / TWO_PWR_32_DBL_);
620
- } else if (value < 0) {
621
- if (value <= -TWO_PWR_63_DBL_) {
622
- return Long.getMinValue();
623
- }
624
- return new Long(-value, -value / TWO_PWR_32_DBL_).negate();
625
- } else {
626
- // NaN or 0.
627
- return Long.getZero();
628
- }
629
- }
630
-
631
- /**
632
- * Returns a Long representing the 64-bit integer that comes by concatenating
633
- * the given high and low bits. Each is assumed to use 32 bits.
634
- * @param {number} lowBits The low 32-bits.
635
- * @param {number} highBits The high 32-bits.
636
- * @return {!Long} The corresponding Long value.
637
- */
638
- static fromBits(lowBits, highBits) {
639
- return new Long(lowBits, highBits);
640
- }
641
-
642
- /**
643
- * Returns a Long representation of the given string, written using the given
644
- * radix.
645
- * @param {string} str The textual representation of the Long.
646
- * @param {number=} opt_radix The radix in which the text is written.
647
- * @return {!Long} The corresponding Long value.
648
- */
649
- static fromString(str, opt_radix) {
650
- if (str.charAt(0) == '-') {
651
- return Long.fromString(str.substring(1), opt_radix).negate();
652
- }
653
-
654
- // We can avoid very expensive multiply based code path for some common
655
- // cases.
656
- var numberValue = parseInt(str, opt_radix || 10);
657
- if (numberValue <= MAX_SAFE_INTEGER_) {
658
- return new Long(
659
- (numberValue % TWO_PWR_32_DBL_) | 0,
660
- (numberValue / TWO_PWR_32_DBL_) | 0);
661
- }
662
-
663
- if (str.length == 0) {
664
- throw new Error('number format error: empty string');
665
- }
666
- if (str.indexOf('-') >= 0) {
667
- throw new Error('number format error: interior "-" character: ' + str);
668
- }
669
-
670
- var radix = opt_radix || 10;
671
- if (radix < 2 || 36 < radix) {
672
- throw new Error('radix out of range: ' + radix);
673
- }
674
-
675
- // Do several (8) digits each time through the loop, so as to
676
- // minimize the calls to the very expensive emulated multiply.
677
- var radixToPower = Long.fromNumber(Math.pow(radix, 8));
678
-
679
- var result = Long.getZero();
680
- for (var i = 0; i < str.length; i += 8) {
681
- var size = Math.min(8, str.length - i);
682
- var value = parseInt(str.substring(i, i + size), radix);
683
- if (size < 8) {
684
- var power = Long.fromNumber(Math.pow(radix, size));
685
- result = result.multiply(power).add(Long.fromNumber(value));
686
- } else {
687
- result = result.multiply(radixToPower);
688
- result = result.add(Long.fromNumber(value));
689
- }
690
- }
691
- return result;
692
- }
693
-
694
- /**
695
- * Returns the boolean value of whether the input string is within a Long's
696
- * range. Assumes an input string containing only numeric characters with an
697
- * optional preceding '-'.
698
- * @param {string} str The textual representation of the Long.
699
- * @param {number=} opt_radix The radix in which the text is written.
700
- * @return {boolean} Whether the string is within the range of a Long.
701
- */
702
- static isStringInRange(str, opt_radix) {
703
- var radix = opt_radix || 10;
704
- if (radix < 2 || 36 < radix) {
705
- throw new Error('radix out of range: ' + radix);
706
- }
707
-
708
- var extremeValue = (str.charAt(0) == '-') ? MIN_VALUE_FOR_RADIX_[radix] :
709
- MAX_VALUE_FOR_RADIX_[radix];
710
-
711
- if (str.length < extremeValue.length) {
712
- return true;
713
- } else if (str.length == extremeValue.length && str <= extremeValue) {
714
- return true;
715
- } else {
716
- return false;
717
- }
718
- }
719
-
720
- /**
721
- * @return {!Long}
722
- * @public
723
- */
724
- static getZero() {
725
- return ZERO_;
726
- }
727
-
728
- /**
729
- * @return {!Long}
730
- * @public
731
- */
732
- static getOne() {
733
- return ONE_;
734
- }
735
-
736
- /**
737
- * @return {!Long}
738
- * @public
739
- */
740
- static getNegOne() {
741
- return NEG_ONE_;
742
- }
743
-
744
- /**
745
- * @return {!Long}
746
- * @public
747
- */
748
- static getMaxValue() {
749
- return MAX_VALUE_;
750
- }
751
-
752
- /**
753
- * @return {!Long}
754
- * @public
755
- */
756
- static getMinValue() {
757
- return MIN_VALUE_;
758
- }
759
-
760
- /**
761
- * @return {!Long}
762
- * @public
763
- */
764
- static getTwoPwr24() {
765
- return TWO_PWR_24_;
766
- }
767
- }
768
-
769
-
770
- // NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the
771
- // from* methods on which they depend.
772
-
773
-
774
- /**
775
- * A cache of the Long representations of small integer values.
776
- * @type {!Object<number, !Long>}
777
- * @private @const
778
- */
779
- const IntCache_ = {};
780
-
781
-
782
- /**
783
- * Returns a cached long number representing the given (32-bit) integer value.
784
- * @param {number} value The 32-bit integer in question.
785
- * @return {!Long} The corresponding Long value.
786
- * @private
787
- */
788
- function getCachedIntValue_(value) {
789
- return reflectCache(IntCache_, value, function(val) {
790
- return new Long(val, val < 0 ? -1 : 0);
791
- });
792
- }
793
-
794
- /**
795
- * The array of maximum values of a Long in string representation for a given
796
- * radix between 2 and 36, inclusive.
797
- * @private @const {!Array<string>}
798
- */
799
- const MAX_VALUE_FOR_RADIX_ = [
800
- '', '', // unused
801
- '111111111111111111111111111111111111111111111111111111111111111',
802
- // base 2
803
- '2021110011022210012102010021220101220221', // base 3
804
- '13333333333333333333333333333333', // base 4
805
- '1104332401304422434310311212', // base 5
806
- '1540241003031030222122211', // base 6
807
- '22341010611245052052300', // base 7
808
- '777777777777777777777', // base 8
809
- '67404283172107811827', // base 9
810
- '9223372036854775807', // base 10
811
- '1728002635214590697', // base 11
812
- '41a792678515120367', // base 12
813
- '10b269549075433c37', // base 13
814
- '4340724c6c71dc7a7', // base 14
815
- '160e2ad3246366807', // base 15
816
- '7fffffffffffffff', // base 16
817
- '33d3d8307b214008', // base 17
818
- '16agh595df825fa7', // base 18
819
- 'ba643dci0ffeehh', // base 19
820
- '5cbfjia3fh26ja7', // base 20
821
- '2heiciiie82dh97', // base 21
822
- '1adaibb21dckfa7', // base 22
823
- 'i6k448cf4192c2', // base 23
824
- 'acd772jnc9l0l7', // base 24
825
- '64ie1focnn5g77', // base 25
826
- '3igoecjbmca687', // base 26
827
- '27c48l5b37oaop', // base 27
828
- '1bk39f3ah3dmq7', // base 28
829
- 'q1se8f0m04isb', // base 29
830
- 'hajppbc1fc207', // base 30
831
- 'bm03i95hia437', // base 31
832
- '7vvvvvvvvvvvv', // base 32
833
- '5hg4ck9jd4u37', // base 33
834
- '3tdtk1v8j6tpp', // base 34
835
- '2pijmikexrxp7', // base 35
836
- '1y2p0ij32e8e7' // base 36
837
- ];
838
-
839
-
840
- /**
841
- * The array of minimum values of a Long in string representation for a given
842
- * radix between 2 and 36, inclusive.
843
- * @private @const {!Array<string>}
844
- */
845
- const MIN_VALUE_FOR_RADIX_ = [
846
- '', '', // unused
847
- '-1000000000000000000000000000000000000000000000000000000000000000',
848
- // base 2
849
- '-2021110011022210012102010021220101220222', // base 3
850
- '-20000000000000000000000000000000', // base 4
851
- '-1104332401304422434310311213', // base 5
852
- '-1540241003031030222122212', // base 6
853
- '-22341010611245052052301', // base 7
854
- '-1000000000000000000000', // base 8
855
- '-67404283172107811828', // base 9
856
- '-9223372036854775808', // base 10
857
- '-1728002635214590698', // base 11
858
- '-41a792678515120368', // base 12
859
- '-10b269549075433c38', // base 13
860
- '-4340724c6c71dc7a8', // base 14
861
- '-160e2ad3246366808', // base 15
862
- '-8000000000000000', // base 16
863
- '-33d3d8307b214009', // base 17
864
- '-16agh595df825fa8', // base 18
865
- '-ba643dci0ffeehi', // base 19
866
- '-5cbfjia3fh26ja8', // base 20
867
- '-2heiciiie82dh98', // base 21
868
- '-1adaibb21dckfa8', // base 22
869
- '-i6k448cf4192c3', // base 23
870
- '-acd772jnc9l0l8', // base 24
871
- '-64ie1focnn5g78', // base 25
872
- '-3igoecjbmca688', // base 26
873
- '-27c48l5b37oaoq', // base 27
874
- '-1bk39f3ah3dmq8', // base 28
875
- '-q1se8f0m04isc', // base 29
876
- '-hajppbc1fc208', // base 30
877
- '-bm03i95hia438', // base 31
878
- '-8000000000000', // base 32
879
- '-5hg4ck9jd4u38', // base 33
880
- '-3tdtk1v8j6tpq', // base 34
881
- '-2pijmikexrxp8', // base 35
882
- '-1y2p0ij32e8e8' // base 36
883
- ];
884
-
885
- /**
886
- * TODO(goktug): Replace with Number.MAX_SAFE_INTEGER when polyfil is guaranteed
887
- * to be removed.
888
- * @type {number}
889
- * @private @const
890
- */
891
- const MAX_SAFE_INTEGER_ = 0x1fffffffffffff;
892
-
893
- // NOTE: the compiler should inline these constant values below and then remove
894
- // these variables, so there should be no runtime penalty for these.
895
-
896
- /**
897
- * Number used repeated below in calculations. This must appear before the
898
- * first call to any from* function above.
899
- * @const {number}
900
- * @private
901
- */
902
- const TWO_PWR_32_DBL_ = 0x100000000;
903
-
904
-
905
- /**
906
- * @const {number}
907
- * @private
908
- */
909
- const TWO_PWR_63_DBL_ = 0x8000000000000000;
910
-
911
-
912
- /**
913
- * @private @const {!Long}
914
- */
915
- const ZERO_ = Long.fromBits(0, 0);
916
-
917
-
918
- /**
919
- * @private @const {!Long}
920
- */
921
- const ONE_ = Long.fromBits(1, 0);
922
-
923
- /**
924
- * @private @const {!Long}
925
- */
926
- const NEG_ONE_ = Long.fromBits(-1, -1);
927
-
928
- /**
929
- * @private @const {!Long}
930
- */
931
- const MAX_VALUE_ = Long.fromBits(0xFFFFFFFF, 0x7FFFFFFF);
932
-
933
- /**
934
- * @private @const {!Long}
935
- */
936
- const MIN_VALUE_ = Long.fromBits(0, 0x80000000);
937
-
938
- /**
939
- * @private @const {!Long}
940
- */
941
- const TWO_PWR_24_ = Long.fromBits(1 << 24, 0);
942
-
943
- /**
944
- * @license
945
- * Copyright The Closure Library Authors.
946
- * SPDX-License-Identifier: Apache-2.0
947
- */
948
-
949
- /**
950
- * @fileoverview Defines an Integer class for representing (potentially)
951
- * infinite length two's-complement integer values.
952
- *
953
- * For the specific case of 64-bit integers, use goog.math.Long, which is more
954
- * efficient.
955
- */
956
-
957
-
958
-
959
- /**
960
- * Constructs a two's-complement integer an array containing bits of the
961
- * integer in 32-bit (signed) pieces, given in little-endian order (i.e.,
962
- * lowest-order bits in the first piece), and the sign of -1 or 0.
963
- *
964
- * See the from* functions below for other convenient ways of constructing
965
- * Integers.
966
- *
967
- * The internal representation of an integer is an array of 32-bit signed
968
- * pieces, along with a sign (0 or -1) that indicates the contents of all the
969
- * other 32-bit pieces out to infinity. We use 32-bit pieces because these are
970
- * the size of integers on which JavaScript performs bit-operations. For
971
- * operations like addition and multiplication, we split each number into 16-bit
972
- * pieces, which can easily be multiplied within JavaScript's floating-point
973
- * representation without overflow or change in sign.
974
- *
975
- * @struct
976
- * @constructor
977
- * @param {Array<number>} bits Array containing the bits of the number.
978
- * @param {number} sign The sign of the number: -1 for negative and 0 positive.
979
- * @final
980
- */
981
- const Integer = function(bits, sign) {
982
- 'use strict';
983
- /**
984
- * @type {number}
985
- * @private
986
- */
987
- this.sign_ = sign;
988
-
989
- // Note: using a local variable while initializing the array helps the
990
- // compiler understand that assigning to the array is local side-effect and
991
- // that enables the entire constructor to be seen as side-effect free.
992
- var localBits = [];
993
-
994
- // Copy the 32-bit signed integer values passed in. We prune out those at the
995
- // top that equal the sign since they are redundant.
996
- var top = true;
997
-
998
- for (var i = bits.length - 1; i >= 0; i--) {
999
- var val = bits[i] | 0;
1000
- if (!top || val != sign) {
1001
- localBits[i] = val;
1002
- top = false;
1003
- }
1004
- }
1005
-
1006
- /**
1007
- * @type {!Array<number>}
1008
- * @private
1009
- * @const
1010
- */
1011
- this.bits_ = localBits;
1012
- };
1013
-
1014
-
1015
- // NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the
1016
- // from* methods on which they depend.
1017
-
1018
-
1019
- /**
1020
- * A cache of the Integer representations of small integer values.
1021
- * @type {!Object<number, !Integer>}
1022
- * @private
1023
- */
1024
- Integer.IntCache_ = {};
1025
-
1026
-
1027
- /**
1028
- * Returns an Integer representing the given (32-bit) integer value.
1029
- * @param {number} value A 32-bit integer value.
1030
- * @return {!Integer} The corresponding Integer value.
1031
- */
1032
- Integer.fromInt = function(value) {
1033
- 'use strict';
1034
- if (-128 <= value && value < 128) {
1035
- return reflectCache(
1036
- Integer.IntCache_, value, function(val) {
1037
- 'use strict';
1038
- return new Integer([val | 0], val < 0 ? -1 : 0);
1039
- });
1040
- }
1041
- return new Integer([value | 0], value < 0 ? -1 : 0);
1042
- };
1043
-
1044
-
1045
- /**
1046
- * Returns an Integer representing the given value, provided that it is a finite
1047
- * number. Otherwise, zero is returned.
1048
- * @param {number} value The value in question.
1049
- * @return {!Integer} The corresponding Integer value.
1050
- */
1051
- Integer.fromNumber = function(value) {
1052
- 'use strict';
1053
- if (isNaN(value) || !isFinite(value)) {
1054
- return Integer.ZERO;
1055
- } else if (value < 0) {
1056
- return Integer.fromNumber(-value).negate();
1057
- } else {
1058
- var bits = [];
1059
- var pow = 1;
1060
- for (var i = 0; value >= pow; i++) {
1061
- bits[i] = (value / pow) | 0;
1062
- pow *= Integer.TWO_PWR_32_DBL_;
1063
- }
1064
- return new Integer(bits, 0);
1065
- }
1066
- };
1067
-
1068
-
1069
- /**
1070
- * Returns a Integer representing the value that comes by concatenating the
1071
- * given entries, each is assumed to be 32 signed bits, given in little-endian
1072
- * order (lowest order bits in the lowest index), and sign-extending the highest
1073
- * order 32-bit value.
1074
- * @param {Array<number>} bits The bits of the number, in 32-bit signed pieces,
1075
- * in little-endian order.
1076
- * @return {!Integer} The corresponding Integer value.
1077
- */
1078
- Integer.fromBits = function(bits) {
1079
- 'use strict';
1080
- var high = bits[bits.length - 1];
1081
- return new Integer(bits, high & (1 << 31) ? -1 : 0);
1082
- };
1083
-
1084
-
1085
- /**
1086
- * Returns an Integer representation of the given string, written using the
1087
- * given radix.
1088
- * @param {string} str The textual representation of the Integer.
1089
- * @param {number=} opt_radix The radix in which the text is written.
1090
- * @return {!Integer} The corresponding Integer value.
1091
- */
1092
- Integer.fromString = function(str, opt_radix) {
1093
- 'use strict';
1094
- if (str.length == 0) {
1095
- throw new Error('number format error: empty string');
1096
- }
1097
-
1098
- var radix = opt_radix || 10;
1099
- if (radix < 2 || 36 < radix) {
1100
- throw new Error('radix out of range: ' + radix);
1101
- }
1102
-
1103
- if (str.charAt(0) == '-') {
1104
- return Integer.fromString(str.substring(1), radix).negate();
1105
- } else if (str.indexOf('-') >= 0) {
1106
- throw new Error('number format error: interior "-" character');
1107
- }
1108
-
1109
- // Do several (8) digits each time through the loop, so as to
1110
- // minimize the calls to the very expensive emulated div.
1111
- var radixToPower = Integer.fromNumber(Math.pow(radix, 8));
1112
-
1113
- var result = Integer.ZERO;
1114
- for (var i = 0; i < str.length; i += 8) {
1115
- var size = Math.min(8, str.length - i);
1116
- var value = parseInt(str.substring(i, i + size), radix);
1117
- if (size < 8) {
1118
- var power = Integer.fromNumber(Math.pow(radix, size));
1119
- result = result.multiply(power).add(Integer.fromNumber(value));
1120
- } else {
1121
- result = result.multiply(radixToPower);
1122
- result = result.add(Integer.fromNumber(value));
1123
- }
1124
- }
1125
- return result;
1126
- };
1127
-
1128
-
1129
- /**
1130
- * A number used repeatedly in calculations. This must appear before the first
1131
- * call to the from* functions below.
1132
- * @type {number}
1133
- * @private
1134
- */
1135
- Integer.TWO_PWR_32_DBL_ = (1 << 16) * (1 << 16);
1136
-
1137
-
1138
- /** @type {!Integer} */
1139
- Integer.ZERO = Integer.fromInt(0);
1140
-
1141
- /** @type {!Integer} */
1142
- Integer.ONE = Integer.fromInt(1);
1143
-
1144
-
1145
- /**
1146
- * @const
1147
- * @type {!Integer}
1148
- * @private
1149
- */
1150
- Integer.TWO_PWR_24_ = Integer.fromInt(1 << 24);
1151
-
1152
- /**
1153
- * Returns the value, assuming it is a 32-bit integer.
1154
- * @return {number} The corresponding int value.
1155
- */
1156
- Integer.prototype.toInt = function() {
1157
- 'use strict';
1158
- return this.bits_.length > 0 ? this.bits_[0] : this.sign_;
1159
- };
1160
-
1161
-
1162
- /** @return {number} The closest floating-point representation to this value. */
1163
- Integer.prototype.toNumber = function() {
1164
- 'use strict';
1165
- if (this.isNegative()) {
1166
- return -this.negate().toNumber();
1167
- } else {
1168
- var val = 0;
1169
- var pow = 1;
1170
- for (var i = 0; i < this.bits_.length; i++) {
1171
- val += this.getBitsUnsigned(i) * pow;
1172
- pow *= Integer.TWO_PWR_32_DBL_;
1173
- }
1174
- return val;
1175
- }
1176
- };
1177
-
1178
-
1179
- /**
1180
- * @param {number=} opt_radix The radix in which the text should be written.
1181
- * @return {string} The textual representation of this value.
1182
- * @override
1183
- */
1184
- Integer.prototype.toString = function(opt_radix) {
1185
- 'use strict';
1186
- var radix = opt_radix || 10;
1187
- if (radix < 2 || 36 < radix) {
1188
- throw new Error('radix out of range: ' + radix);
1189
- }
1190
-
1191
- if (this.isZero()) {
1192
- return '0';
1193
- } else if (this.isNegative()) {
1194
- return '-' + this.negate().toString(radix);
1195
- }
1196
-
1197
- // Do several (6) digits each time through the loop, so as to
1198
- // minimize the calls to the very expensive emulated div.
1199
- var radixToPower = Integer.fromNumber(Math.pow(radix, 6));
1200
-
1201
- var rem = this;
1202
- var result = '';
1203
- while (true) {
1204
- var remDiv = rem.divide(radixToPower);
1205
- // The right shifting fixes negative values in the case when
1206
- // intval >= 2^31; for more details see
1207
- // https://github.com/google/closure-library/pull/498
1208
- var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt() >>> 0;
1209
- var digits = intval.toString(radix);
1210
-
1211
- rem = remDiv;
1212
- if (rem.isZero()) {
1213
- return digits + result;
1214
- } else {
1215
- while (digits.length < 6) {
1216
- digits = '0' + digits;
1217
- }
1218
- result = '' + digits + result;
1219
- }
1220
- }
1221
- };
1222
-
1223
-
1224
- /**
1225
- * Returns the index-th 32-bit (signed) piece of the Integer according to
1226
- * little-endian order (i.e., index 0 contains the smallest bits).
1227
- * @param {number} index The index in question.
1228
- * @return {number} The requested 32-bits as a signed number.
1229
- */
1230
- Integer.prototype.getBits = function(index) {
1231
- 'use strict';
1232
- if (index < 0) {
1233
- return 0; // Allowing this simplifies bit shifting operations below...
1234
- } else if (index < this.bits_.length) {
1235
- return this.bits_[index];
1236
- } else {
1237
- return this.sign_;
1238
- }
1239
- };
1240
-
1241
-
1242
- /**
1243
- * Returns the index-th 32-bit piece as an unsigned number.
1244
- * @param {number} index The index in question.
1245
- * @return {number} The requested 32-bits as an unsigned number.
1246
- */
1247
- Integer.prototype.getBitsUnsigned = function(index) {
1248
- 'use strict';
1249
- var val = this.getBits(index);
1250
- return val >= 0 ? val : Integer.TWO_PWR_32_DBL_ + val;
1251
- };
1252
-
1253
-
1254
- /** @return {number} The sign bit of this number, -1 or 0. */
1255
- Integer.prototype.getSign = function() {
1256
- 'use strict';
1257
- return this.sign_;
1258
- };
1259
-
1260
-
1261
- /** @return {boolean} Whether this value is zero. */
1262
- Integer.prototype.isZero = function() {
1263
- 'use strict';
1264
- if (this.sign_ != 0) {
1265
- return false;
1266
- }
1267
- for (var i = 0; i < this.bits_.length; i++) {
1268
- if (this.bits_[i] != 0) {
1269
- return false;
1270
- }
1271
- }
1272
- return true;
1273
- };
1274
-
1275
-
1276
- /** @return {boolean} Whether this value is negative. */
1277
- Integer.prototype.isNegative = function() {
1278
- 'use strict';
1279
- return this.sign_ == -1;
1280
- };
1281
-
1282
-
1283
- /** @return {boolean} Whether this value is odd. */
1284
- Integer.prototype.isOdd = function() {
1285
- 'use strict';
1286
- return (this.bits_.length == 0) && (this.sign_ == -1) ||
1287
- (this.bits_.length > 0) && ((this.bits_[0] & 1) != 0);
1288
- };
1289
-
1290
-
1291
- /**
1292
- * @param {Integer} other Integer to compare against.
1293
- * @return {boolean} Whether this Integer equals the other.
1294
- */
1295
- Integer.prototype.equals = function(other) {
1296
- 'use strict';
1297
- if (this.sign_ != other.sign_) {
1298
- return false;
1299
- }
1300
- var len = Math.max(this.bits_.length, other.bits_.length);
1301
- for (var i = 0; i < len; i++) {
1302
- if (this.getBits(i) != other.getBits(i)) {
1303
- return false;
1304
- }
1305
- }
1306
- return true;
1307
- };
1308
-
1309
-
1310
- /**
1311
- * @param {Integer} other Integer to compare against.
1312
- * @return {boolean} Whether this Integer does not equal the other.
1313
- */
1314
- Integer.prototype.notEquals = function(other) {
1315
- 'use strict';
1316
- return !this.equals(other);
1317
- };
1318
-
1319
-
1320
- /**
1321
- * @param {Integer} other Integer to compare against.
1322
- * @return {boolean} Whether this Integer is greater than the other.
1323
- */
1324
- Integer.prototype.greaterThan = function(other) {
1325
- 'use strict';
1326
- return this.compare(other) > 0;
1327
- };
1328
-
1329
-
1330
- /**
1331
- * @param {Integer} other Integer to compare against.
1332
- * @return {boolean} Whether this Integer is greater than or equal to the other.
1333
- */
1334
- Integer.prototype.greaterThanOrEqual = function(other) {
1335
- 'use strict';
1336
- return this.compare(other) >= 0;
1337
- };
1338
-
1339
-
1340
- /**
1341
- * @param {Integer} other Integer to compare against.
1342
- * @return {boolean} Whether this Integer is less than the other.
1343
- */
1344
- Integer.prototype.lessThan = function(other) {
1345
- 'use strict';
1346
- return this.compare(other) < 0;
1347
- };
1348
-
1349
-
1350
- /**
1351
- * @param {Integer} other Integer to compare against.
1352
- * @return {boolean} Whether this Integer is less than or equal to the other.
1353
- */
1354
- Integer.prototype.lessThanOrEqual = function(other) {
1355
- 'use strict';
1356
- return this.compare(other) <= 0;
1357
- };
1358
-
1359
-
1360
- /**
1361
- * Compares this Integer with the given one.
1362
- * @param {Integer} other Integer to compare against.
1363
- * @return {number} 0 if they are the same, 1 if the this is greater, and -1
1364
- * if the given one is greater.
1365
- */
1366
- Integer.prototype.compare = function(other) {
1367
- 'use strict';
1368
- var diff = this.subtract(other);
1369
- if (diff.isNegative()) {
1370
- return -1;
1371
- } else if (diff.isZero()) {
1372
- return 0;
1373
- } else {
1374
- return +1;
1375
- }
1376
- };
1377
-
1378
-
1379
- /**
1380
- * Returns an integer with only the first numBits bits of this value, sign
1381
- * extended from the final bit.
1382
- * @param {number} numBits The number of bits by which to shift.
1383
- * @return {!Integer} The shorted integer value.
1384
- */
1385
- Integer.prototype.shorten = function(numBits) {
1386
- 'use strict';
1387
- var arr_index = (numBits - 1) >> 5;
1388
- var bit_index = (numBits - 1) % 32;
1389
- var bits = [];
1390
- for (var i = 0; i < arr_index; i++) {
1391
- bits[i] = this.getBits(i);
1392
- }
1393
- var sigBits = bit_index == 31 ? 0xFFFFFFFF : (1 << (bit_index + 1)) - 1;
1394
- var val = this.getBits(arr_index) & sigBits;
1395
- if (val & (1 << bit_index)) {
1396
- val |= 0xFFFFFFFF - sigBits;
1397
- bits[arr_index] = val;
1398
- return new Integer(bits, -1);
1399
- } else {
1400
- bits[arr_index] = val;
1401
- return new Integer(bits, 0);
1402
- }
1403
- };
1404
-
1405
-
1406
- /** @return {!Integer} The negation of this value. */
1407
- Integer.prototype.negate = function() {
1408
- 'use strict';
1409
- return this.not().add(Integer.ONE);
1410
- };
1411
-
1412
-
1413
- /** @return {!Integer} The absolute value of this value. */
1414
- Integer.prototype.abs = function() {
1415
- 'use strict';
1416
- return this.isNegative() ? this.negate() : this;
1417
- };
1418
-
1419
-
1420
- /**
1421
- * Returns the sum of this and the given Integer.
1422
- * @param {Integer} other The Integer to add to this.
1423
- * @return {!Integer} The Integer result.
1424
- */
1425
- Integer.prototype.add = function(other) {
1426
- 'use strict';
1427
- var len = Math.max(this.bits_.length, other.bits_.length);
1428
- var arr = [];
1429
- var carry = 0;
1430
-
1431
- for (var i = 0; i <= len; i++) {
1432
- var a1 = this.getBits(i) >>> 16;
1433
- var a0 = this.getBits(i) & 0xFFFF;
1434
-
1435
- var b1 = other.getBits(i) >>> 16;
1436
- var b0 = other.getBits(i) & 0xFFFF;
1437
-
1438
- var c0 = carry + a0 + b0;
1439
- var c1 = (c0 >>> 16) + a1 + b1;
1440
- carry = c1 >>> 16;
1441
- c0 &= 0xFFFF;
1442
- c1 &= 0xFFFF;
1443
- arr[i] = (c1 << 16) | c0;
1444
- }
1445
- return Integer.fromBits(arr);
1446
- };
1447
-
1448
-
1449
- /**
1450
- * Returns the difference of this and the given Integer.
1451
- * @param {Integer} other The Integer to subtract from this.
1452
- * @return {!Integer} The Integer result.
1453
- */
1454
- Integer.prototype.subtract = function(other) {
1455
- 'use strict';
1456
- return this.add(other.negate());
1457
- };
1458
-
1459
-
1460
- /**
1461
- * Returns the product of this and the given Integer.
1462
- * @param {Integer} other The Integer to multiply against this.
1463
- * @return {!Integer} The product of this and the other.
1464
- */
1465
- Integer.prototype.multiply = function(other) {
1466
- 'use strict';
1467
- if (this.isZero()) {
1468
- return Integer.ZERO;
1469
- } else if (other.isZero()) {
1470
- return Integer.ZERO;
1471
- }
1472
-
1473
- if (this.isNegative()) {
1474
- if (other.isNegative()) {
1475
- return this.negate().multiply(other.negate());
1476
- } else {
1477
- return this.negate().multiply(other).negate();
1478
- }
1479
- } else if (other.isNegative()) {
1480
- return this.multiply(other.negate()).negate();
1481
- }
1482
-
1483
- // If both numbers are small, use float multiplication
1484
- if (this.lessThan(Integer.TWO_PWR_24_) &&
1485
- other.lessThan(Integer.TWO_PWR_24_)) {
1486
- return Integer.fromNumber(this.toNumber() * other.toNumber());
1487
- }
1488
-
1489
- // Fill in an array of 16-bit products.
1490
- var len = this.bits_.length + other.bits_.length;
1491
- var arr = [];
1492
- for (var i = 0; i < 2 * len; i++) {
1493
- arr[i] = 0;
1494
- }
1495
- for (var i = 0; i < this.bits_.length; i++) {
1496
- for (var j = 0; j < other.bits_.length; j++) {
1497
- var a1 = this.getBits(i) >>> 16;
1498
- var a0 = this.getBits(i) & 0xFFFF;
1499
-
1500
- var b1 = other.getBits(j) >>> 16;
1501
- var b0 = other.getBits(j) & 0xFFFF;
1502
-
1503
- arr[2 * i + 2 * j] += a0 * b0;
1504
- Integer.carry16_(arr, 2 * i + 2 * j);
1505
- arr[2 * i + 2 * j + 1] += a1 * b0;
1506
- Integer.carry16_(arr, 2 * i + 2 * j + 1);
1507
- arr[2 * i + 2 * j + 1] += a0 * b1;
1508
- Integer.carry16_(arr, 2 * i + 2 * j + 1);
1509
- arr[2 * i + 2 * j + 2] += a1 * b1;
1510
- Integer.carry16_(arr, 2 * i + 2 * j + 2);
1511
- }
1512
- }
1513
-
1514
- // Combine the 16-bit values into 32-bit values.
1515
- for (var i = 0; i < len; i++) {
1516
- arr[i] = (arr[2 * i + 1] << 16) | arr[2 * i];
1517
- }
1518
- for (var i = len; i < 2 * len; i++) {
1519
- arr[i] = 0;
1520
- }
1521
- return new Integer(arr, 0);
1522
- };
1523
-
1524
-
1525
- /**
1526
- * Carries any overflow from the given index into later entries.
1527
- * @param {Array<number>} bits Array of 16-bit values in little-endian order.
1528
- * @param {number} index The index in question.
1529
- * @private
1530
- */
1531
- Integer.carry16_ = function(bits, index) {
1532
- 'use strict';
1533
- while ((bits[index] & 0xFFFF) != bits[index]) {
1534
- bits[index + 1] += bits[index] >>> 16;
1535
- bits[index] &= 0xFFFF;
1536
- index++;
1537
- }
1538
- };
1539
-
1540
-
1541
- /**
1542
- * Returns "this" Integer divided by the given one. Both "this" and the given
1543
- * Integer MUST be positive.
1544
- *
1545
- * This method is only needed for very large numbers (>10^308),
1546
- * for which the original division algorithm gets into an infinite
1547
- * loop (see https://github.com/google/closure-library/issues/500).
1548
- *
1549
- * The algorithm has some possible performance enhancements (or
1550
- * could be rewritten entirely), it's just an initial solution for
1551
- * the issue linked above.
1552
- *
1553
- * @param {!Integer} other The Integer to divide "this" by.
1554
- * @return {!Integer.DivisionResult}
1555
- * @private
1556
- */
1557
- Integer.prototype.slowDivide_ = function(other) {
1558
- 'use strict';
1559
- if (this.isNegative() || other.isNegative()) {
1560
- throw new Error('slowDivide_ only works with positive integers.');
1561
- }
1562
-
1563
- var twoPower = Integer.ONE;
1564
- var multiple = other;
1565
-
1566
- // First we have to figure out what the highest bit of the result
1567
- // is, so we increase "twoPower" and "multiple" until "multiple"
1568
- // exceeds "this".
1569
- while (multiple.lessThanOrEqual(this)) {
1570
- twoPower = twoPower.shiftLeft(1);
1571
- multiple = multiple.shiftLeft(1);
1572
- }
1573
-
1574
- // Rewind by one power of two, giving us the highest bit of the
1575
- // result.
1576
- var res = twoPower.shiftRight(1);
1577
- var total = multiple.shiftRight(1);
1578
-
1579
- // Now we starting decreasing "multiple" and "twoPower" to find the
1580
- // rest of the bits of the result.
1581
- var total2;
1582
- multiple = multiple.shiftRight(2);
1583
- twoPower = twoPower.shiftRight(2);
1584
- while (!multiple.isZero()) {
1585
- // whenever we can add "multiple" to the total and not exceed
1586
- // "this", that means we've found a 1 bit. Else we've found a 0
1587
- // and don't need to add to the result.
1588
- total2 = total.add(multiple);
1589
- if (total2.lessThanOrEqual(this)) {
1590
- res = res.add(twoPower);
1591
- total = total2;
1592
- }
1593
- multiple = multiple.shiftRight(1);
1594
- twoPower = twoPower.shiftRight(1);
1595
- }
1596
-
1597
-
1598
- // TODO(user): Calculate this more efficiently during the division.
1599
- // This is kind of a waste since it isn't always needed, but it keeps the
1600
- // API smooth. Since this is already a slow path it probably isn't a big deal.
1601
- var remainder = this.subtract(res.multiply(other));
1602
- return new Integer.DivisionResult(res, remainder);
1603
- };
1604
-
1605
-
1606
- /**
1607
- * Returns this Integer divided by the given one.
1608
- * @param {!Integer} other The Integer to divide this by.
1609
- * @return {!Integer} This value divided by the given one.
1610
- */
1611
- Integer.prototype.divide = function(other) {
1612
- 'use strict';
1613
- return this.divideAndRemainder(other).quotient;
1614
- };
1615
-
1616
-
1617
- /**
1618
- * A struct for holding the quotient and remainder of a division.
1619
- *
1620
- * @constructor
1621
- * @final
1622
- * @struct
1623
- *
1624
- * @param {!Integer} quotient
1625
- * @param {!Integer} remainder
1626
- */
1627
- Integer.DivisionResult = function(quotient, remainder) {
1628
- 'use strict';
1629
- /** @const */
1630
- this.quotient = quotient;
1631
-
1632
- /** @const */
1633
- this.remainder = remainder;
1634
- };
1635
-
1636
-
1637
- /**
1638
- * Returns this Integer divided by the given one, as well as the remainder of
1639
- * that division.
1640
- *
1641
- * @param {!Integer} other The Integer to divide this by.
1642
- * @return {!Integer.DivisionResult}
1643
- */
1644
- Integer.prototype.divideAndRemainder = function(other) {
1645
- 'use strict';
1646
- if (other.isZero()) {
1647
- throw new Error('division by zero');
1648
- } else if (this.isZero()) {
1649
- return new Integer.DivisionResult(
1650
- Integer.ZERO, Integer.ZERO);
1651
- }
1652
-
1653
- if (this.isNegative()) {
1654
- // Do the division on the negative of the numerator...
1655
- var result = this.negate().divideAndRemainder(other);
1656
- return new Integer.DivisionResult(
1657
- // ...and flip the sign back after.
1658
- result.quotient.negate(),
1659
- // The remainder must always have the same sign as the numerator.
1660
- result.remainder.negate());
1661
- } else if (other.isNegative()) {
1662
- // Do the division on the negative of the denominator...
1663
- var result = this.divideAndRemainder(other.negate());
1664
- return new Integer.DivisionResult(
1665
- // ...and flip the sign back after.
1666
- result.quotient.negate(),
1667
- // The remainder must always have the same sign as the numerator.
1668
- result.remainder);
1669
- }
1670
-
1671
- // Have to degrade to slowDivide for Very Large Numbers, because
1672
- // they're out of range for the floating-point approximation
1673
- // technique used below.
1674
- if (this.bits_.length > 30) {
1675
- return this.slowDivide_(other);
1676
- }
1677
-
1678
- // Repeat the following until the remainder is less than other: find a
1679
- // floating-point that approximates remainder / other *from below*, add this
1680
- // into the result, and subtract it from the remainder. It is critical that
1681
- // the approximate value is less than or equal to the real value so that the
1682
- // remainder never becomes negative.
1683
- var res = Integer.ZERO;
1684
- var rem = this;
1685
- while (rem.greaterThanOrEqual(other)) {
1686
- // Approximate the result of division. This may be a little greater or
1687
- // smaller than the actual value.
1688
- var approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber()));
1689
-
1690
- // We will tweak the approximate result by changing it in the 48-th digit or
1691
- // the smallest non-fractional digit, whichever is larger.
1692
- var log2 = Math.ceil(Math.log(approx) / Math.LN2);
1693
- var delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48);
1694
-
1695
- // Decrease the approximation until it is smaller than the remainder. Note
1696
- // that if it is too large, the product overflows and is negative.
1697
- var approxRes = Integer.fromNumber(approx);
1698
- var approxRem = approxRes.multiply(other);
1699
- while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
1700
- approx -= delta;
1701
- approxRes = Integer.fromNumber(approx);
1702
- approxRem = approxRes.multiply(other);
1703
- }
1704
-
1705
- // We know the answer can't be zero... and actually, zero would cause
1706
- // infinite recursion since we would make no progress.
1707
- if (approxRes.isZero()) {
1708
- approxRes = Integer.ONE;
1709
- }
1710
-
1711
- res = res.add(approxRes);
1712
- rem = rem.subtract(approxRem);
1713
- }
1714
- return new Integer.DivisionResult(res, rem);
1715
- };
1716
-
1717
-
1718
- /**
1719
- * Returns this Integer modulo the given one.
1720
- * @param {!Integer} other The Integer by which to mod.
1721
- * @return {!Integer} This value modulo the given one.
1722
- */
1723
- Integer.prototype.modulo = function(other) {
1724
- 'use strict';
1725
- return this.divideAndRemainder(other).remainder;
1726
- };
1727
-
1728
-
1729
- /** @return {!Integer} The bitwise-NOT of this value. */
1730
- Integer.prototype.not = function() {
1731
- 'use strict';
1732
- var len = this.bits_.length;
1733
- var arr = [];
1734
- for (var i = 0; i < len; i++) {
1735
- arr[i] = ~this.bits_[i];
1736
- }
1737
- return new Integer(arr, ~this.sign_);
1738
- };
1739
-
1740
-
1741
- /**
1742
- * Returns the bitwise-AND of this Integer and the given one.
1743
- * @param {Integer} other The Integer to AND with this.
1744
- * @return {!Integer} The bitwise-AND of this and the other.
1745
- */
1746
- Integer.prototype.and = function(other) {
1747
- 'use strict';
1748
- var len = Math.max(this.bits_.length, other.bits_.length);
1749
- var arr = [];
1750
- for (var i = 0; i < len; i++) {
1751
- arr[i] = this.getBits(i) & other.getBits(i);
1752
- }
1753
- return new Integer(arr, this.sign_ & other.sign_);
1754
- };
1755
-
1756
-
1757
- /**
1758
- * Returns the bitwise-OR of this Integer and the given one.
1759
- * @param {Integer} other The Integer to OR with this.
1760
- * @return {!Integer} The bitwise-OR of this and the other.
1761
- */
1762
- Integer.prototype.or = function(other) {
1763
- 'use strict';
1764
- var len = Math.max(this.bits_.length, other.bits_.length);
1765
- var arr = [];
1766
- for (var i = 0; i < len; i++) {
1767
- arr[i] = this.getBits(i) | other.getBits(i);
1768
- }
1769
- return new Integer(arr, this.sign_ | other.sign_);
1770
- };
1771
-
1772
-
1773
- /**
1774
- * Returns the bitwise-XOR of this Integer and the given one.
1775
- * @param {Integer} other The Integer to XOR with this.
1776
- * @return {!Integer} The bitwise-XOR of this and the other.
1777
- */
1778
- Integer.prototype.xor = function(other) {
1779
- 'use strict';
1780
- var len = Math.max(this.bits_.length, other.bits_.length);
1781
- var arr = [];
1782
- for (var i = 0; i < len; i++) {
1783
- arr[i] = this.getBits(i) ^ other.getBits(i);
1784
- }
1785
- return new Integer(arr, this.sign_ ^ other.sign_);
1786
- };
1787
-
1788
-
1789
- /**
1790
- * Returns this value with bits shifted to the left by the given amount.
1791
- * @param {number} numBits The number of bits by which to shift.
1792
- * @return {!Integer} This shifted to the left by the given amount.
1793
- */
1794
- Integer.prototype.shiftLeft = function(numBits) {
1795
- 'use strict';
1796
- var arr_delta = numBits >> 5;
1797
- var bit_delta = numBits % 32;
1798
- var len = this.bits_.length + arr_delta + (bit_delta > 0 ? 1 : 0);
1799
- var arr = [];
1800
- for (var i = 0; i < len; i++) {
1801
- if (bit_delta > 0) {
1802
- arr[i] = (this.getBits(i - arr_delta) << bit_delta) |
1803
- (this.getBits(i - arr_delta - 1) >>> (32 - bit_delta));
1804
- } else {
1805
- arr[i] = this.getBits(i - arr_delta);
1806
- }
1807
- }
1808
- return new Integer(arr, this.sign_);
1809
- };
1810
-
1811
-
1812
- /**
1813
- * Returns this value with bits shifted to the right by the given amount.
1814
- * @param {number} numBits The number of bits by which to shift.
1815
- * @return {!Integer} This shifted to the right by the given amount.
1816
- */
1817
- Integer.prototype.shiftRight = function(numBits) {
1818
- 'use strict';
1819
- var arr_delta = numBits >> 5;
1820
- var bit_delta = numBits % 32;
1821
- var len = this.bits_.length - arr_delta;
1822
- var arr = [];
1823
- for (var i = 0; i < len; i++) {
1824
- if (bit_delta > 0) {
1825
- arr[i] = (this.getBits(i + arr_delta) >>> bit_delta) |
1826
- (this.getBits(i + arr_delta + 1) << (32 - bit_delta));
1827
- } else {
1828
- arr[i] = this.getBits(i + arr_delta);
1829
- }
1830
- }
1831
- return new Integer(arr, this.sign_);
1832
- };
1833
-
1834
- // instances of the Closure Library's own classes, when the compatibility layer
1835
- // loaded them, are instances too
1836
- for (const [klass, name] of [[Long, 'Long'], [Integer, 'Integer']]) {
1837
- Object.defineProperty(klass, Symbol.hasInstance, {
1838
- value(x) {
1839
- if (Function.prototype[Symbol.hasInstance].call(klass, x)) return true;
1840
- const real = globalThis.goog && globalThis.goog.math && globalThis.goog.math[name];
1841
- return real && real !== klass ? x instanceof real : false;
1842
- },
1843
- });
1844
- }
1845
-
1846
- export {Long, Integer};