compostjs 0.0.11 → 0.0.12

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