source: trip-planner-front/node_modules/@angular/compiler/src/i18n/big_integer.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 22.4 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8(function (factory) {
9 if (typeof module === "object" && typeof module.exports === "object") {
10 var v = factory(require, exports);
11 if (v !== undefined) module.exports = v;
12 }
13 else if (typeof define === "function" && define.amd) {
14 define("@angular/compiler/src/i18n/big_integer", ["require", "exports"], factory);
15 }
16})(function (require, exports) {
17 "use strict";
18 Object.defineProperty(exports, "__esModule", { value: true });
19 exports.BigIntExponentiation = exports.BigIntForMultiplication = exports.BigInteger = void 0;
20 /**
21 * Represents a big integer using a buffer of its individual digits, with the least significant
22 * digit stored at the beginning of the array (little endian).
23 *
24 * For performance reasons, each instance is mutable. The addition operation can be done in-place
25 * to reduce memory pressure of allocation for the digits array.
26 */
27 var BigInteger = /** @class */ (function () {
28 /**
29 * Creates a big integer using its individual digits in little endian storage.
30 */
31 function BigInteger(digits) {
32 this.digits = digits;
33 }
34 BigInteger.zero = function () {
35 return new BigInteger([0]);
36 };
37 BigInteger.one = function () {
38 return new BigInteger([1]);
39 };
40 /**
41 * Creates a clone of this instance.
42 */
43 BigInteger.prototype.clone = function () {
44 return new BigInteger(this.digits.slice());
45 };
46 /**
47 * Returns a new big integer with the sum of `this` and `other` as its value. This does not mutate
48 * `this` but instead returns a new instance, unlike `addToSelf`.
49 */
50 BigInteger.prototype.add = function (other) {
51 var result = this.clone();
52 result.addToSelf(other);
53 return result;
54 };
55 /**
56 * Adds `other` to the instance itself, thereby mutating its value.
57 */
58 BigInteger.prototype.addToSelf = function (other) {
59 var maxNrOfDigits = Math.max(this.digits.length, other.digits.length);
60 var carry = 0;
61 for (var i = 0; i < maxNrOfDigits; i++) {
62 var digitSum = carry;
63 if (i < this.digits.length) {
64 digitSum += this.digits[i];
65 }
66 if (i < other.digits.length) {
67 digitSum += other.digits[i];
68 }
69 if (digitSum >= 10) {
70 this.digits[i] = digitSum - 10;
71 carry = 1;
72 }
73 else {
74 this.digits[i] = digitSum;
75 carry = 0;
76 }
77 }
78 // Apply a remaining carry if needed.
79 if (carry > 0) {
80 this.digits[maxNrOfDigits] = 1;
81 }
82 };
83 /**
84 * Builds the decimal string representation of the big integer. As this is stored in
85 * little endian, the digits are concatenated in reverse order.
86 */
87 BigInteger.prototype.toString = function () {
88 var res = '';
89 for (var i = this.digits.length - 1; i >= 0; i--) {
90 res += this.digits[i];
91 }
92 return res;
93 };
94 return BigInteger;
95 }());
96 exports.BigInteger = BigInteger;
97 /**
98 * Represents a big integer which is optimized for multiplication operations, as its power-of-twos
99 * are memoized. See `multiplyBy()` for details on the multiplication algorithm.
100 */
101 var BigIntForMultiplication = /** @class */ (function () {
102 function BigIntForMultiplication(value) {
103 this.powerOfTwos = [value];
104 }
105 /**
106 * Returns the big integer itself.
107 */
108 BigIntForMultiplication.prototype.getValue = function () {
109 return this.powerOfTwos[0];
110 };
111 /**
112 * Computes the value for `num * b`, where `num` is a JS number and `b` is a big integer. The
113 * value for `b` is represented by a storage model that is optimized for this computation.
114 *
115 * This operation is implemented in N(log2(num)) by continuous halving of the number, where the
116 * least-significant bit (LSB) is tested in each iteration. If the bit is set, the bit's index is
117 * used as exponent into the power-of-two multiplication of `b`.
118 *
119 * As an example, consider the multiplication num=42, b=1337. In binary 42 is 0b00101010 and the
120 * algorithm unrolls into the following iterations:
121 *
122 * Iteration | num | LSB | b * 2^iter | Add? | product
123 * -----------|------------|------|------------|------|--------
124 * 0 | 0b00101010 | 0 | 1337 | No | 0
125 * 1 | 0b00010101 | 1 | 2674 | Yes | 2674
126 * 2 | 0b00001010 | 0 | 5348 | No | 2674
127 * 3 | 0b00000101 | 1 | 10696 | Yes | 13370
128 * 4 | 0b00000010 | 0 | 21392 | No | 13370
129 * 5 | 0b00000001 | 1 | 42784 | Yes | 56154
130 * 6 | 0b00000000 | 0 | 85568 | No | 56154
131 *
132 * The computed product of 56154 is indeed the correct result.
133 *
134 * The `BigIntForMultiplication` representation for a big integer provides memoized access to the
135 * power-of-two values to reduce the workload in computing those values.
136 */
137 BigIntForMultiplication.prototype.multiplyBy = function (num) {
138 var product = BigInteger.zero();
139 this.multiplyByAndAddTo(num, product);
140 return product;
141 };
142 /**
143 * See `multiplyBy()` for details. This function allows for the computed product to be added
144 * directly to the provided result big integer.
145 */
146 BigIntForMultiplication.prototype.multiplyByAndAddTo = function (num, result) {
147 for (var exponent = 0; num !== 0; num = num >>> 1, exponent++) {
148 if (num & 1) {
149 var value = this.getMultipliedByPowerOfTwo(exponent);
150 result.addToSelf(value);
151 }
152 }
153 };
154 /**
155 * Computes and memoizes the big integer value for `this.number * 2^exponent`.
156 */
157 BigIntForMultiplication.prototype.getMultipliedByPowerOfTwo = function (exponent) {
158 // Compute the powers up until the requested exponent, where each value is computed from its
159 // predecessor. This is simple as `this.number * 2^(exponent - 1)` only has to be doubled (i.e.
160 // added to itself) to reach `this.number * 2^exponent`.
161 for (var i = this.powerOfTwos.length; i <= exponent; i++) {
162 var previousPower = this.powerOfTwos[i - 1];
163 this.powerOfTwos[i] = previousPower.add(previousPower);
164 }
165 return this.powerOfTwos[exponent];
166 };
167 return BigIntForMultiplication;
168 }());
169 exports.BigIntForMultiplication = BigIntForMultiplication;
170 /**
171 * Represents an exponentiation operation for the provided base, of which exponents are computed and
172 * memoized. The results are represented by a `BigIntForMultiplication` which is tailored for
173 * multiplication operations by memoizing the power-of-twos. This effectively results in a matrix
174 * representation that is lazily computed upon request.
175 */
176 var BigIntExponentiation = /** @class */ (function () {
177 function BigIntExponentiation(base) {
178 this.base = base;
179 this.exponents = [new BigIntForMultiplication(BigInteger.one())];
180 }
181 /**
182 * Compute the value for `this.base^exponent`, resulting in a big integer that is optimized for
183 * further multiplication operations.
184 */
185 BigIntExponentiation.prototype.toThePowerOf = function (exponent) {
186 // Compute the results up until the requested exponent, where every value is computed from its
187 // predecessor. This is because `this.base^(exponent - 1)` only has to be multiplied by `base`
188 // to reach `this.base^exponent`.
189 for (var i = this.exponents.length; i <= exponent; i++) {
190 var value = this.exponents[i - 1].multiplyBy(this.base);
191 this.exponents[i] = new BigIntForMultiplication(value);
192 }
193 return this.exponents[exponent];
194 };
195 return BigIntExponentiation;
196 }());
197 exports.BigIntExponentiation = BigIntExponentiation;
198});
199//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmlnX2ludGVnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb21waWxlci9zcmMvaTE4bi9iaWdfaW50ZWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7SUFFSDs7Ozs7O09BTUc7SUFDSDtRQVNFOztXQUVHO1FBQ0gsb0JBQXFDLE1BQWdCO1lBQWhCLFdBQU0sR0FBTixNQUFNLENBQVU7UUFBRyxDQUFDO1FBWGxELGVBQUksR0FBWDtZQUNFLE9BQU8sSUFBSSxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzdCLENBQUM7UUFFTSxjQUFHLEdBQVY7WUFDRSxPQUFPLElBQUksVUFBVSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUM3QixDQUFDO1FBT0Q7O1dBRUc7UUFDSCwwQkFBSyxHQUFMO1lBQ0UsT0FBTyxJQUFJLFVBQVUsQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUM7UUFDN0MsQ0FBQztRQUVEOzs7V0FHRztRQUNILHdCQUFHLEdBQUgsVUFBSSxLQUFpQjtZQUNuQixJQUFNLE1BQU0sR0FBRyxJ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