exponential-number 1.3.5 → 1.3.7

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.
@@ -11,7 +11,7 @@ export declare class ExponentNumber {
11
11
  minus(otherNumber: ExponentNumber): ExponentNumber;
12
12
  multiply(otherNumber: ExponentNumber): ExponentNumber;
13
13
  divide(otherNumber: ExponentNumber): ExponentNumber;
14
- power(otherNumber: ExponentNumber): ExponentNumber;
14
+ power(power: ExponentNumber): ExponentNumber;
15
15
  root(otherNumber: ExponentNumber): ExponentNumber;
16
16
  sqrt(): ExponentNumber;
17
17
  log(base: ExponentNumber): ExponentNumber;
@@ -104,10 +104,21 @@ class ExponentNumber {
104
104
  return this;
105
105
  }
106
106
  multiply(otherNumber) {
107
- const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
108
- result.plus(new ExponentNumber(otherNumber.exponentFactor, Math.log10(otherNumber.value)));
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,32 +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, Math.log10(this.value));
119
- result.minus(new ExponentNumber(otherNumber.exponentFactor, Math.log10(otherNumber.value)));
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
- power(otherNumber) {
126
- const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
127
- result.multiply(otherNumber);
128
- this.exponentFactor = result.exponentFactor + 1;
129
- this.value = result.value;
146
+ power(power) {
147
+ if (this.exponentFactor === 0 && this.value < 1) {
148
+ if (power.exponentFactor > 0) {
149
+ this.resetValue();
150
+ }
151
+ else {
152
+ this.value = Math.pow(this.value, power.value);
153
+ }
154
+ }
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
+ }
130
161
  this.normalize();
131
162
  return this;
132
163
  }
133
164
  root(otherNumber) {
134
- const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value));
135
- if (result.exponentFactor >= 1 &&
136
- (otherNumber.exponentFactor > result.exponentFactor ||
137
- (otherNumber.exponentFactor === result.exponentFactor && otherNumber.value > result.value))) {
138
- this.resetValue();
139
- 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
+ }
140
187
  }
141
- result.divide(otherNumber);
142
- this.exponentFactor = result.exponentFactor + 1;
143
- this.value = result.value;
144
188
  this.normalize();
145
189
  return this;
146
190
  }
@@ -148,9 +192,19 @@ class ExponentNumber {
148
192
  return this.root(new ExponentNumber(0, 2));
149
193
  }
150
194
  log(base) {
151
- const result = new ExponentNumber(this.exponentFactor, Math.log10(this.value + 1));
152
- result.divide(new ExponentNumber(base.exponentFactor, Math.log10(base.value + 1)));
153
- 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
+ }
154
208
  this.normalize();
155
209
  return this;
156
210
  }
package/dist/const.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare const VALUE_EXPONENT_LIMIT = 100;
2
- export declare const VALUE_EXPONENT_DIFFERENCE_LIMIT = 12;
2
+ export declare const VALUE_EXPONENT_DIFFERENCE_LIMIT = 9;
3
3
  export declare const DECIMAL_DIGITS = 5;
4
4
  export declare const EXPONENT_COUNT_LIMIT = 5;
package/dist/const.js CHANGED
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EXPONENT_COUNT_LIMIT = exports.DECIMAL_DIGITS = exports.VALUE_EXPONENT_DIFFERENCE_LIMIT = exports.VALUE_EXPONENT_LIMIT = void 0;
4
4
  exports.VALUE_EXPONENT_LIMIT = 100;
5
- exports.VALUE_EXPONENT_DIFFERENCE_LIMIT = 12;
5
+ exports.VALUE_EXPONENT_DIFFERENCE_LIMIT = 9;
6
6
  exports.DECIMAL_DIGITS = 5;
7
7
  exports.EXPONENT_COUNT_LIMIT = 5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exponential-number",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
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",