exponential-number 1.3.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,7 +12,7 @@ export declare class ExponentNumber {
|
|
|
12
12
|
multiply(otherNumber: ExponentNumber): ExponentNumber;
|
|
13
13
|
divide(otherNumber: ExponentNumber): ExponentNumber;
|
|
14
14
|
power(power: ExponentNumber): ExponentNumber;
|
|
15
|
-
root(
|
|
15
|
+
root(base: ExponentNumber): ExponentNumber;
|
|
16
16
|
sqrt(): ExponentNumber;
|
|
17
17
|
log(base: ExponentNumber): ExponentNumber;
|
|
18
18
|
log10(): ExponentNumber;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExponentNumber = void 0;
|
|
4
|
-
const util_math_utils_1 = require("../utils/util-math.utils");
|
|
5
4
|
const const_1 = require("../const");
|
|
5
|
+
const util_math_utils_1 = require("../utils/util-math.utils");
|
|
6
6
|
class ExponentNumber {
|
|
7
7
|
constructor(exponentFactor = 0, value = 0) {
|
|
8
8
|
this.exponentFactor = 0;
|
|
@@ -23,11 +23,11 @@ class ExponentNumber {
|
|
|
23
23
|
this.exponentFactor -= 1;
|
|
24
24
|
this.value = Math.pow(10, this.value);
|
|
25
25
|
}
|
|
26
|
-
while (this.exponentFactor < 0 && this.value >
|
|
26
|
+
while (this.exponentFactor < 0 && this.value > 1) {
|
|
27
27
|
this.exponentFactor += 1;
|
|
28
|
-
this.value = Math.
|
|
28
|
+
this.value = Math.log10(this.value);
|
|
29
29
|
}
|
|
30
|
-
if (this.value
|
|
30
|
+
if (Math.abs(this.value) <= Math.pow(10, -const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT)) {
|
|
31
31
|
this.resetValue();
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -58,155 +58,365 @@ class ExponentNumber {
|
|
|
58
58
|
return `${exponentText}${numberText}`;
|
|
59
59
|
}
|
|
60
60
|
plus(otherNumber) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const isOtherValueSmaller = this.isGreaterThanValue(otherNumber);
|
|
62
|
+
const biggerValue = isOtherValueSmaller ? this : otherNumber;
|
|
63
|
+
const smallerValue = isOtherValueSmaller ? otherNumber : this;
|
|
64
|
+
switch (this.exponentFactor) {
|
|
65
|
+
case 0: {
|
|
66
|
+
switch (otherNumber.exponentFactor) {
|
|
67
|
+
case 0: {
|
|
68
|
+
return new ExponentNumber(0, this.value + otherNumber.value);
|
|
69
|
+
}
|
|
70
|
+
case 1: {
|
|
71
|
+
return new ExponentNumber(1, (0, util_math_utils_1.plusExponentOne)(otherNumber.value, Math.log10(this.value)));
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
return new ExponentNumber(otherNumber.exponentFactor, otherNumber.value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
64
77
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
case 1: {
|
|
79
|
+
switch (otherNumber.exponentFactor) {
|
|
80
|
+
case 0: {
|
|
81
|
+
return new ExponentNumber(1, (0, util_math_utils_1.plusExponentOne)(this.value, Math.log10(otherNumber.value)));
|
|
82
|
+
}
|
|
83
|
+
case 1: {
|
|
84
|
+
return new ExponentNumber(1, (0, util_math_utils_1.plusExponentOne)(biggerValue.value, smallerValue.value));
|
|
85
|
+
}
|
|
86
|
+
default: {
|
|
87
|
+
return new ExponentNumber(otherNumber.exponentFactor, otherNumber.value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
70
90
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
default: {
|
|
92
|
+
switch (otherNumber.exponentFactor) {
|
|
93
|
+
case 0: {
|
|
94
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
95
|
+
}
|
|
96
|
+
case 1: {
|
|
97
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
98
|
+
}
|
|
99
|
+
default: {
|
|
100
|
+
return biggerValue;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
74
103
|
}
|
|
75
104
|
}
|
|
76
|
-
this.normalize();
|
|
77
|
-
return this;
|
|
78
105
|
}
|
|
79
106
|
minus(otherNumber) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
107
|
+
const isOtherValueSmaller = this.isGreaterThanValue(otherNumber);
|
|
108
|
+
const biggerValue = isOtherValueSmaller ? this : otherNumber;
|
|
109
|
+
const smallerValue = isOtherValueSmaller ? otherNumber : this;
|
|
110
|
+
switch (this.exponentFactor) {
|
|
111
|
+
case 0: {
|
|
112
|
+
switch (otherNumber.exponentFactor) {
|
|
113
|
+
case 0: {
|
|
114
|
+
return isOtherValueSmaller
|
|
115
|
+
? new ExponentNumber(0, this.value - otherNumber.value)
|
|
116
|
+
: new ExponentNumber(0, 0);
|
|
117
|
+
}
|
|
118
|
+
case 1: {
|
|
119
|
+
return new ExponentNumber(0, 0);
|
|
120
|
+
}
|
|
121
|
+
default: {
|
|
122
|
+
return new ExponentNumber(0, 0);
|
|
123
|
+
}
|
|
84
124
|
}
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
if (this.value === otherNumber.value) {
|
|
88
|
-
this.resetValue();
|
|
89
|
-
return this;
|
|
90
125
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
case 1: {
|
|
127
|
+
switch (otherNumber.exponentFactor) {
|
|
128
|
+
case 0: {
|
|
129
|
+
return new ExponentNumber(1, (0, util_math_utils_1.minusExponentOne)(this.value, Math.log10(otherNumber.value)));
|
|
130
|
+
}
|
|
131
|
+
case 1: {
|
|
132
|
+
return isOtherValueSmaller
|
|
133
|
+
? new ExponentNumber(1, (0, util_math_utils_1.minusExponentOne)(biggerValue.value, smallerValue.value))
|
|
134
|
+
: new ExponentNumber(0, 0);
|
|
135
|
+
}
|
|
136
|
+
default: {
|
|
137
|
+
return new ExponentNumber(0, 0);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
96
140
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
141
|
+
default: {
|
|
142
|
+
switch (otherNumber.exponentFactor) {
|
|
143
|
+
case 0: {
|
|
144
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
145
|
+
}
|
|
146
|
+
case 1: {
|
|
147
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
148
|
+
}
|
|
149
|
+
default: {
|
|
150
|
+
return isOtherValueSmaller
|
|
151
|
+
? new ExponentNumber(this.exponentFactor, this.value)
|
|
152
|
+
: new ExponentNumber(0, 0);
|
|
153
|
+
}
|
|
100
154
|
}
|
|
101
155
|
}
|
|
102
156
|
}
|
|
103
|
-
this.normalize();
|
|
104
|
-
return this;
|
|
105
157
|
}
|
|
106
158
|
multiply(otherNumber) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
159
|
+
const isOtherValueSmaller = this.isGreaterThanValue(otherNumber);
|
|
160
|
+
const biggerValue = isOtherValueSmaller ? this : otherNumber;
|
|
161
|
+
switch (this.exponentFactor) {
|
|
162
|
+
case 0: {
|
|
163
|
+
switch (otherNumber.exponentFactor) {
|
|
164
|
+
case 0: {
|
|
165
|
+
return new ExponentNumber(0, this.value * otherNumber.value);
|
|
166
|
+
}
|
|
167
|
+
case 1: {
|
|
168
|
+
if (this.value <= 0) {
|
|
169
|
+
return new ExponentNumber(0, 0);
|
|
170
|
+
}
|
|
171
|
+
return new ExponentNumber(1, otherNumber.value + Math.log10(this.value));
|
|
172
|
+
}
|
|
173
|
+
default: {
|
|
174
|
+
return new ExponentNumber(otherNumber.exponentFactor, otherNumber.value);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
case 1: {
|
|
179
|
+
switch (otherNumber.exponentFactor) {
|
|
180
|
+
case 0: {
|
|
181
|
+
if (otherNumber.value <= 0) {
|
|
182
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
183
|
+
}
|
|
184
|
+
return new ExponentNumber(1, this.value + Math.log10(otherNumber.value));
|
|
185
|
+
}
|
|
186
|
+
case 1: {
|
|
187
|
+
return new ExponentNumber(1, this.value + otherNumber.value);
|
|
188
|
+
}
|
|
189
|
+
default: {
|
|
190
|
+
return new ExponentNumber(2, new ExponentNumber(0, this.value).plus(new ExponentNumber(otherNumber.exponentFactor - 1, otherNumber.value)).value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
111
193
|
}
|
|
112
|
-
|
|
113
|
-
|
|
194
|
+
default: {
|
|
195
|
+
switch (otherNumber.exponentFactor) {
|
|
196
|
+
case 0: {
|
|
197
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
198
|
+
}
|
|
199
|
+
case 1: {
|
|
200
|
+
return new ExponentNumber(this.exponentFactor, new ExponentNumber(this.exponentFactor - 1, this.value).plus(new ExponentNumber(0, otherNumber.value)).value);
|
|
201
|
+
}
|
|
202
|
+
default: {
|
|
203
|
+
return new ExponentNumber(biggerValue.exponentFactor, new ExponentNumber(this.exponentFactor - 1, this.value).plus(new ExponentNumber(otherNumber.exponentFactor - 1, otherNumber.value)).value);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
114
206
|
}
|
|
115
207
|
}
|
|
116
|
-
else {
|
|
117
|
-
const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
|
|
118
|
-
result.plus(new ExponentNumber(otherNumber.exponentFactor, Math.log10(otherNumber.value)));
|
|
119
|
-
this.exponentFactor = result.exponentFactor + 1;
|
|
120
|
-
this.value = result.value;
|
|
121
|
-
}
|
|
122
|
-
this.normalize();
|
|
123
|
-
return this;
|
|
124
208
|
}
|
|
125
209
|
divide(otherNumber) {
|
|
126
|
-
|
|
127
|
-
|
|
210
|
+
const isOtherValueSmaller = this.isGreaterThanValue(otherNumber);
|
|
211
|
+
if (this.value < 0 || otherNumber.value < 0) {
|
|
212
|
+
return new ExponentNumber(0, 0);
|
|
213
|
+
}
|
|
214
|
+
if (this.isEqual(otherNumber)) {
|
|
215
|
+
return new ExponentNumber(0, 1);
|
|
128
216
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
217
|
+
console.log(this, otherNumber);
|
|
218
|
+
switch (this.exponentFactor) {
|
|
219
|
+
case 0: {
|
|
220
|
+
switch (otherNumber.exponentFactor) {
|
|
221
|
+
case 0: {
|
|
222
|
+
return new ExponentNumber(0, this.value / otherNumber.value);
|
|
223
|
+
}
|
|
224
|
+
case 1: {
|
|
225
|
+
return new ExponentNumber(1, -(0, util_math_utils_1.minusExponentOne)(otherNumber.value, Math.log10(this.value)));
|
|
226
|
+
}
|
|
227
|
+
default: {
|
|
228
|
+
return new ExponentNumber(0, 0);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
132
231
|
}
|
|
133
|
-
|
|
134
|
-
|
|
232
|
+
case 1: {
|
|
233
|
+
switch (otherNumber.exponentFactor) {
|
|
234
|
+
case 0: {
|
|
235
|
+
return new ExponentNumber(1, this.value - Math.log10(otherNumber.value));
|
|
236
|
+
}
|
|
237
|
+
case 1: {
|
|
238
|
+
return new ExponentNumber(0, Math.pow(10, this.value - otherNumber.value));
|
|
239
|
+
}
|
|
240
|
+
default: {
|
|
241
|
+
return new ExponentNumber(0, 0);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
default: {
|
|
246
|
+
switch (otherNumber.exponentFactor) {
|
|
247
|
+
case 0: {
|
|
248
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
249
|
+
}
|
|
250
|
+
case 1: {
|
|
251
|
+
const subtractedNumber = new ExponentNumber(this.exponentFactor - 1, this.value).minus(new ExponentNumber(0, otherNumber.value));
|
|
252
|
+
return new ExponentNumber(subtractedNumber.exponentFactor + 1, subtractedNumber.value);
|
|
253
|
+
}
|
|
254
|
+
default: {
|
|
255
|
+
if (!isOtherValueSmaller) {
|
|
256
|
+
return new ExponentNumber(0, 0);
|
|
257
|
+
}
|
|
258
|
+
const powerMinus = new ExponentNumber(this.exponentFactor - 1, this.value).minus(new ExponentNumber(otherNumber.exponentFactor - 1, otherNumber.value));
|
|
259
|
+
console.log(powerMinus);
|
|
260
|
+
return new ExponentNumber(powerMinus.exponentFactor + 1, powerMinus.value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
135
263
|
}
|
|
136
264
|
}
|
|
137
|
-
else {
|
|
138
|
-
const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
|
|
139
|
-
result.minus(new ExponentNumber(otherNumber.exponentFactor, Math.log10(otherNumber.value)));
|
|
140
|
-
this.exponentFactor = result.exponentFactor + 1;
|
|
141
|
-
this.value = result.value;
|
|
142
|
-
}
|
|
143
|
-
this.normalize();
|
|
144
|
-
return this;
|
|
145
265
|
}
|
|
146
266
|
power(power) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
267
|
+
switch (this.exponentFactor) {
|
|
268
|
+
case 0: {
|
|
269
|
+
switch (power.exponentFactor) {
|
|
270
|
+
case 0: {
|
|
271
|
+
return new ExponentNumber(1, Math.log10(this.value) * power.value);
|
|
272
|
+
}
|
|
273
|
+
case 1: {
|
|
274
|
+
if (this.value < 1) {
|
|
275
|
+
return new ExponentNumber(0, 0);
|
|
276
|
+
}
|
|
277
|
+
const powerMult = new ExponentNumber(0, Math.log10(this.value)).multiply(new ExponentNumber(1, power.value));
|
|
278
|
+
return new ExponentNumber(powerMult.exponentFactor + 1, powerMult.value);
|
|
279
|
+
}
|
|
280
|
+
default: {
|
|
281
|
+
if (this.value < 1) {
|
|
282
|
+
return new ExponentNumber(0, 0);
|
|
283
|
+
}
|
|
284
|
+
return new ExponentNumber(power.exponentFactor + 1, new ExponentNumber(0, Math.log10(this.value)).multiply(new ExponentNumber(power.exponentFactor, power.value)).value);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
150
287
|
}
|
|
151
|
-
|
|
152
|
-
|
|
288
|
+
case 1: {
|
|
289
|
+
switch (power.exponentFactor) {
|
|
290
|
+
case 0: {
|
|
291
|
+
return new ExponentNumber(1, this.value * power.value);
|
|
292
|
+
}
|
|
293
|
+
case 1: {
|
|
294
|
+
return new ExponentNumber(2, new ExponentNumber(0, this.value).multiply(power).value);
|
|
295
|
+
}
|
|
296
|
+
default: {
|
|
297
|
+
return new ExponentNumber(power.exponentFactor + 1, new ExponentNumber(0, this.value).multiply(new ExponentNumber(power.exponentFactor, power.value)).value);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
default: {
|
|
302
|
+
switch (power.exponentFactor) {
|
|
303
|
+
case 0: {
|
|
304
|
+
return new ExponentNumber(this.exponentFactor, new ExponentNumber(this.exponentFactor - 1, this.value).multiply(new ExponentNumber(power.exponentFactor, power.value)).value);
|
|
305
|
+
}
|
|
306
|
+
case 1: {
|
|
307
|
+
return new ExponentNumber(this.exponentFactor, new ExponentNumber(this.exponentFactor - 1, this.value).multiply(new ExponentNumber(power.exponentFactor, power.value)).value);
|
|
308
|
+
}
|
|
309
|
+
default: {
|
|
310
|
+
const powerMult = new ExponentNumber(this.exponentFactor - 1, this.value).multiply(new ExponentNumber(power.exponentFactor, power.value));
|
|
311
|
+
return new ExponentNumber(powerMult.exponentFactor + 1, powerMult.value);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
153
314
|
}
|
|
154
315
|
}
|
|
155
|
-
else {
|
|
156
|
-
const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
|
|
157
|
-
result.multiply(power);
|
|
158
|
-
this.exponentFactor = result.exponentFactor + 1;
|
|
159
|
-
this.value = result.value;
|
|
160
|
-
}
|
|
161
|
-
this.normalize();
|
|
162
|
-
return this;
|
|
163
316
|
}
|
|
164
|
-
root(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
317
|
+
root(base) {
|
|
318
|
+
const isBaseSmaller = this.isGreaterThanValue(base);
|
|
319
|
+
switch (this.exponentFactor) {
|
|
320
|
+
case 0: {
|
|
321
|
+
switch (base.exponentFactor) {
|
|
322
|
+
case 0: {
|
|
323
|
+
return new ExponentNumber(0, Math.pow(this.value, 1 / base.value));
|
|
324
|
+
}
|
|
325
|
+
case 1: {
|
|
326
|
+
if (this.value <= 1) {
|
|
327
|
+
return new ExponentNumber(0, 1);
|
|
328
|
+
}
|
|
329
|
+
return new ExponentNumber(0, new ExponentNumber(0, Math.log10(this.value)).divide(base).value);
|
|
330
|
+
}
|
|
331
|
+
default: {
|
|
332
|
+
return new ExponentNumber(0, 1);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
168
335
|
}
|
|
169
|
-
|
|
170
|
-
|
|
336
|
+
case 1: {
|
|
337
|
+
switch (base.exponentFactor) {
|
|
338
|
+
case 0: {
|
|
339
|
+
if (base.value <= 0) {
|
|
340
|
+
return new ExponentNumber(0, 1);
|
|
341
|
+
}
|
|
342
|
+
return new ExponentNumber(1, new ExponentNumber(0, this.value).divide(base).value);
|
|
343
|
+
}
|
|
344
|
+
case 1: {
|
|
345
|
+
return new ExponentNumber(0, new ExponentNumber(0, this.value).divide(base).value);
|
|
346
|
+
}
|
|
347
|
+
default: {
|
|
348
|
+
return new ExponentNumber(0, 1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
171
351
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
352
|
+
default: {
|
|
353
|
+
switch (base.exponentFactor) {
|
|
354
|
+
case 0: {
|
|
355
|
+
return new ExponentNumber(this.exponentFactor, new ExponentNumber(this.exponentFactor - 1, this.value).divide(base).value);
|
|
356
|
+
}
|
|
357
|
+
case 1: {
|
|
358
|
+
return new ExponentNumber(this.exponentFactor - 1, new ExponentNumber(this.exponentFactor - 1, this.value).divide(base).value);
|
|
359
|
+
}
|
|
360
|
+
default: {
|
|
361
|
+
if (base.isGreaterThanValue(new ExponentNumber(this.exponentFactor - 1, this.value))) {
|
|
362
|
+
return new ExponentNumber(0, 0);
|
|
363
|
+
}
|
|
364
|
+
const powerDivide = new ExponentNumber(this.exponentFactor - 1, this.value).divide(base);
|
|
365
|
+
return new ExponentNumber(powerDivide.exponentFactor + 1, powerDivide.value);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
186
368
|
}
|
|
187
369
|
}
|
|
188
|
-
this.normalize();
|
|
189
|
-
return this;
|
|
190
370
|
}
|
|
191
371
|
sqrt() {
|
|
192
372
|
return this.root(new ExponentNumber(0, 2));
|
|
193
373
|
}
|
|
194
374
|
log(base) {
|
|
195
|
-
if (this.
|
|
196
|
-
|
|
197
|
-
|
|
375
|
+
if (this.value < 0 || base.value < 1) {
|
|
376
|
+
return new ExponentNumber(this.exponentFactor, this.value);
|
|
377
|
+
}
|
|
378
|
+
switch (this.exponentFactor) {
|
|
379
|
+
case 0: {
|
|
380
|
+
switch (base.exponentFactor) {
|
|
381
|
+
case 0: {
|
|
382
|
+
return new ExponentNumber(0, Math.log10(this.value) / Math.log10(base.value));
|
|
383
|
+
}
|
|
384
|
+
case 1: {
|
|
385
|
+
console.log(Math.log10(this.value), base.value);
|
|
386
|
+
return new ExponentNumber(0, Math.log10(this.value) / base.value);
|
|
387
|
+
}
|
|
388
|
+
default: {
|
|
389
|
+
return new ExponentNumber(0, 0);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
198
392
|
}
|
|
199
|
-
|
|
200
|
-
|
|
393
|
+
case 1: {
|
|
394
|
+
switch (base.exponentFactor) {
|
|
395
|
+
case 0: {
|
|
396
|
+
return new ExponentNumber(0, this.value / Math.log10(base.value));
|
|
397
|
+
}
|
|
398
|
+
case 1: {
|
|
399
|
+
return new ExponentNumber(0, this.value / base.value);
|
|
400
|
+
}
|
|
401
|
+
default: {
|
|
402
|
+
return new ExponentNumber(0, this.value).divide(new ExponentNumber(base.exponentFactor - 1, base.value));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
default: {
|
|
407
|
+
switch (base.exponentFactor) {
|
|
408
|
+
case 0: {
|
|
409
|
+
return new ExponentNumber(this.exponentFactor - 1, this.value).divide(new ExponentNumber(0, Math.log10(base.value)));
|
|
410
|
+
}
|
|
411
|
+
case 1: {
|
|
412
|
+
return new ExponentNumber(this.exponentFactor - 1, this.value).divide(new ExponentNumber(0, base.value));
|
|
413
|
+
}
|
|
414
|
+
default: {
|
|
415
|
+
return new ExponentNumber(this.exponentFactor - 1, this.value).divide(new ExponentNumber(base.exponentFactor - 1, base.value));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
201
418
|
}
|
|
202
419
|
}
|
|
203
|
-
else {
|
|
204
|
-
const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
|
|
205
|
-
result.divide(new ExponentNumber(base.exponentFactor, Math.log10(base.value)));
|
|
206
|
-
this.applyNewValues(result);
|
|
207
|
-
}
|
|
208
|
-
this.normalize();
|
|
209
|
-
return this;
|
|
210
420
|
}
|
|
211
421
|
log10() {
|
|
212
422
|
return new ExponentNumber(this.exponentFactor - 1, this.value);
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function plusDifferentExponentLevelNumber(first: ExponentNumber, second: ExponentNumber): ExponentNumber;
|
|
4
|
-
export declare function minusEqualExponentLevelNumber(first: ExponentNumber, second: ExponentNumber): ExponentNumber;
|
|
5
|
-
export declare function minusDifferentExponentLevelNumber(first: ExponentNumber, second: ExponentNumber): ExponentNumber;
|
|
1
|
+
export declare function plusExponentOne(biggerValue: number, smallerValue: number): number;
|
|
2
|
+
export declare function minusExponentOne(biggerValue: number, smallerValue: number): number;
|
|
@@ -1,76 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const exponent_number_class_1 = require("../class/exponent-number.class");
|
|
8
|
-
const const_1 = require("../const");
|
|
9
|
-
function plusEqualExponentLevelNumber(first, second) {
|
|
10
|
-
if (first.exponentFactor !== second.exponentFactor) {
|
|
11
|
-
throw new Error('Expected exponentFactor to be equal');
|
|
12
|
-
}
|
|
13
|
-
if (second.exponentFactor > 1) {
|
|
14
|
-
throw new Error('Expected exponentFactor to be lower or equal than 1');
|
|
15
|
-
}
|
|
16
|
-
if (second.exponentFactor === 1) {
|
|
17
|
-
if (Math.abs(first.value - second.value) > const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT) {
|
|
18
|
-
return first.value - second.value > 0 ? first.copy() : second.copy();
|
|
19
|
-
}
|
|
20
|
-
const biggerValue = Math.max(first.value, second.value);
|
|
21
|
-
const smallerValue = Math.min(first.value, second.value);
|
|
22
|
-
return new exponent_number_class_1.ExponentNumber(1, biggerValue + Math.log10(1 + Math.pow(10, smallerValue - biggerValue)));
|
|
23
|
-
}
|
|
24
|
-
return new exponent_number_class_1.ExponentNumber(0, first.value + second.value);
|
|
3
|
+
exports.plusExponentOne = plusExponentOne;
|
|
4
|
+
exports.minusExponentOne = minusExponentOne;
|
|
5
|
+
function plusExponentOne(biggerValue, smallerValue) {
|
|
6
|
+
return biggerValue + Math.log10(1 + Math.pow(10, smallerValue - biggerValue));
|
|
25
7
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
throw new Error('Expected exponentFactor to be different');
|
|
29
|
-
}
|
|
30
|
-
if (first.exponentFactor > 1 || second.exponentFactor > 1) {
|
|
31
|
-
throw new Error('Expected exponentFactor to be lower or equal than 1');
|
|
32
|
-
}
|
|
33
|
-
const biggerValue = first.exponentFactor > second.exponentFactor ? first : second;
|
|
34
|
-
const smallerValue = first.exponentFactor > second.exponentFactor ? second : first;
|
|
35
|
-
const smallValueExponent = Math.log10(smallerValue.value);
|
|
36
|
-
const exponentDifference = biggerValue.value - smallValueExponent;
|
|
37
|
-
if (exponentDifference > const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT) {
|
|
38
|
-
return biggerValue.copy();
|
|
39
|
-
}
|
|
40
|
-
return new exponent_number_class_1.ExponentNumber(1, biggerValue.value + Math.log10(1 + 1 / Math.pow(10, exponentDifference)));
|
|
41
|
-
}
|
|
42
|
-
function minusEqualExponentLevelNumber(first, second) {
|
|
43
|
-
if (first.exponentFactor !== second.exponentFactor) {
|
|
44
|
-
throw new Error('Expected exponentFactor to be equal');
|
|
45
|
-
}
|
|
46
|
-
if (second.exponentFactor > 1) {
|
|
47
|
-
throw new Error('Expected exponentFactor to be lower or equal than 1');
|
|
48
|
-
}
|
|
49
|
-
if (second.exponentFactor === 1) {
|
|
50
|
-
if (second.value >= first.value) {
|
|
51
|
-
return new exponent_number_class_1.ExponentNumber(0, 0);
|
|
52
|
-
}
|
|
53
|
-
if (first.value - second.value > const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT) {
|
|
54
|
-
return first.value - second.value < 0 ? first.copy() : second.copy();
|
|
55
|
-
}
|
|
56
|
-
return new exponent_number_class_1.ExponentNumber(1, first.value + Math.log10(1 - Math.pow(10, second.value - first.value)));
|
|
57
|
-
}
|
|
58
|
-
return new exponent_number_class_1.ExponentNumber(0, Math.max(first.value - second.value, -const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT));
|
|
59
|
-
}
|
|
60
|
-
function minusDifferentExponentLevelNumber(first, second) {
|
|
61
|
-
if (first.exponentFactor === second.exponentFactor) {
|
|
62
|
-
throw new Error('Expected exponentFactor to be different');
|
|
63
|
-
}
|
|
64
|
-
if (first.exponentFactor > 1 || second.exponentFactor > 1) {
|
|
65
|
-
throw new Error('Expected exponentFactor to be lower or equal than 1');
|
|
66
|
-
}
|
|
67
|
-
if (second.exponentFactor > first.exponentFactor) {
|
|
68
|
-
return new exponent_number_class_1.ExponentNumber(0, 0);
|
|
69
|
-
}
|
|
70
|
-
const smallValueExponent = Math.log10(second.value);
|
|
71
|
-
const exponentDifference = first.value - smallValueExponent;
|
|
72
|
-
if (exponentDifference > const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT) {
|
|
73
|
-
return first.copy();
|
|
74
|
-
}
|
|
75
|
-
return new exponent_number_class_1.ExponentNumber(1, first.value + Math.log10(1 - 1 / Math.pow(10, exponentDifference)));
|
|
8
|
+
function minusExponentOne(biggerValue, smallerValue) {
|
|
9
|
+
return biggerValue + Math.log10(1 - Math.pow(10, smallerValue - biggerValue));
|
|
76
10
|
}
|
package/package.json
CHANGED