exponential-number 1.3.6 → 1.3.8

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.
@@ -84,7 +84,7 @@ class ExponentNumber {
84
84
  }
85
85
  return this;
86
86
  }
87
- if (this.value === otherNumber.value) {
87
+ if (this.value <= otherNumber.value) {
88
88
  this.resetValue();
89
89
  return this;
90
90
  }
@@ -104,10 +104,21 @@ class ExponentNumber {
104
104
  return this;
105
105
  }
106
106
  multiply(otherNumber) {
107
- const result = new ExponentNumber(this.exponentFactor, (0, util_math_utils_1.safeLog10)(this));
108
- result.plus(new ExponentNumber(otherNumber.exponentFactor, (0, util_math_utils_1.safeLog10)(otherNumber)));
109
- this.exponentFactor = result.exponentFactor + 1;
110
- this.value = result.value;
107
+ if (this.exponentFactor === 0 && this.value < 1) {
108
+ if (otherNumber.exponentFactor > 0) {
109
+ this.value = otherNumber.value + Math.log10(this.value);
110
+ this.exponentFactor = otherNumber.exponentFactor;
111
+ }
112
+ else {
113
+ this.value *= otherNumber.value;
114
+ }
115
+ }
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
+ }
111
122
  this.normalize();
112
123
  return this;
113
124
  }
@@ -115,42 +126,65 @@ class ExponentNumber {
115
126
  if (this.exponentFactor === 0 && this.value === 0) {
116
127
  return this;
117
128
  }
118
- const result = new ExponentNumber(this.exponentFactor, (0, util_math_utils_1.safeLog10)(this));
119
- result.minus(new ExponentNumber(otherNumber.exponentFactor, (0, util_math_utils_1.safeLog10)(otherNumber)));
120
- this.exponentFactor = result.exponentFactor + 1;
121
- this.value = result.value;
129
+ if (this.exponentFactor === 0 && this.value < 1) {
130
+ if (otherNumber.exponentFactor > 0) {
131
+ this.resetValue();
132
+ }
133
+ else {
134
+ this.value /= otherNumber.value;
135
+ }
136
+ }
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
+ }
122
143
  this.normalize();
123
144
  return this;
124
145
  }
125
146
  power(power) {
126
147
  if (this.exponentFactor === 0 && this.value < 1) {
127
148
  if (power.exponentFactor > 0) {
128
- this.value = 0;
149
+ this.resetValue();
129
150
  }
130
151
  else {
131
152
  this.value = Math.pow(this.value, power.value);
132
153
  }
133
154
  }
134
155
  else {
135
- const result = new ExponentNumber(this.exponentFactor, (0, util_math_utils_1.safeLog10)(this));
156
+ const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
136
157
  result.multiply(power);
137
158
  this.exponentFactor = result.exponentFactor + 1;
138
159
  this.value = result.value;
139
- this.normalize();
140
160
  }
161
+ this.normalize();
141
162
  return this;
142
163
  }
143
164
  root(otherNumber) {
144
- const result = new ExponentNumber(this.exponentFactor, (0, util_math_utils_1.safeLog10)(this));
145
- if (result.exponentFactor >= 1 &&
146
- (otherNumber.exponentFactor > result.exponentFactor ||
147
- (otherNumber.exponentFactor === result.exponentFactor && otherNumber.value > result.value))) {
148
- this.resetValue();
149
- return this;
165
+ if (this.exponentFactor === 0 && this.value < 1) {
166
+ if (otherNumber.exponentFactor > 0) {
167
+ this.value = 1;
168
+ }
169
+ else {
170
+ this.value = Math.pow(this.value, 1 / otherNumber.value);
171
+ }
172
+ }
173
+ else {
174
+ const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
175
+ if (result.exponentFactor >= 1 &&
176
+ (otherNumber.exponentFactor > result.exponentFactor ||
177
+ (otherNumber.exponentFactor === result.exponentFactor &&
178
+ otherNumber.value > result.value))) {
179
+ this.resetValue();
180
+ }
181
+ else {
182
+ result.divide(otherNumber);
183
+ this.exponentFactor = result.exponentFactor + 1;
184
+ this.value = result.value;
185
+ this.normalize();
186
+ }
150
187
  }
151
- result.divide(otherNumber);
152
- this.exponentFactor = result.exponentFactor + 1;
153
- this.value = result.value;
154
188
  this.normalize();
155
189
  return this;
156
190
  }
@@ -158,9 +192,19 @@ class ExponentNumber {
158
192
  return this.root(new ExponentNumber(0, 2));
159
193
  }
160
194
  log(base) {
161
- const result = new ExponentNumber(this.exponentFactor, (0, util_math_utils_1.safeLog10)(this));
162
- result.divide(new ExponentNumber(base.exponentFactor, (0, util_math_utils_1.safeLog10)(base)));
163
- this.applyNewValues(result);
195
+ if (this.exponentFactor === 0 && this.value < 1) {
196
+ if (base.exponentFactor > 0) {
197
+ this.resetValue();
198
+ }
199
+ else {
200
+ this.value = Math.log(this.value) / Math.log(base.value);
201
+ }
202
+ }
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
+ }
164
208
  this.normalize();
165
209
  return this;
166
210
  }
@@ -3,4 +3,3 @@ export declare function plusEqualExponentLevelNumber(first: ExponentNumber, seco
3
3
  export declare function plusDifferentExponentLevelNumber(first: ExponentNumber, second: ExponentNumber): ExponentNumber;
4
4
  export declare function minusEqualExponentLevelNumber(first: ExponentNumber, second: ExponentNumber): ExponentNumber;
5
5
  export declare function minusDifferentExponentLevelNumber(first: ExponentNumber, second: ExponentNumber): ExponentNumber;
6
- export declare function safeLog10(value: ExponentNumber): number;
@@ -4,7 +4,6 @@ exports.plusEqualExponentLevelNumber = plusEqualExponentLevelNumber;
4
4
  exports.plusDifferentExponentLevelNumber = plusDifferentExponentLevelNumber;
5
5
  exports.minusEqualExponentLevelNumber = minusEqualExponentLevelNumber;
6
6
  exports.minusDifferentExponentLevelNumber = minusDifferentExponentLevelNumber;
7
- exports.safeLog10 = safeLog10;
8
7
  const exponent_number_class_1 = require("../class/exponent-number.class");
9
8
  const const_1 = require("../const");
10
9
  function plusEqualExponentLevelNumber(first, second) {
@@ -52,7 +51,7 @@ function minusEqualExponentLevelNumber(first, second) {
52
51
  return new exponent_number_class_1.ExponentNumber(0, 0);
53
52
  }
54
53
  if (first.value - second.value > const_1.VALUE_EXPONENT_DIFFERENCE_LIMIT) {
55
- return first.value - second.value < 0 ? first.copy() : second.copy();
54
+ return first.copy();
56
55
  }
57
56
  return new exponent_number_class_1.ExponentNumber(1, first.value + Math.log10(1 - Math.pow(10, second.value - first.value)));
58
57
  }
@@ -75,6 +74,3 @@ function minusDifferentExponentLevelNumber(first, second) {
75
74
  }
76
75
  return new exponent_number_class_1.ExponentNumber(1, first.value + Math.log10(1 - 1 / Math.pow(10, exponentDifference)));
77
76
  }
78
- function safeLog10(value) {
79
- return Math.log10(value.value + (value.exponentFactor > 0 ? 0 : 1));
80
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exponential-number",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Small package with class to work with big numbers. This class allows to work with 1e...(1.8e308)...e1e100",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "build": "tsc",
17
17
  "test": "jest --config=jest.config.js test.ts",
18
- "update": "npm login && npm run build && npm publish"
18
+ "update": "npm run build && npm publish"
19
19
  },
20
20
  "keywords": [
21
21
  "typescript",