powiaina_num.js 0.2.0-alpha.2.8 → 0.2.0-alpha.3

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.
package/README.md CHANGED
@@ -1,72 +1,98 @@
1
- # PowiainaNum.js
2
-
3
- A JavaScript library that handles arithmetic for numbers as large as {10,9e15,1,1,1,2}.
4
-
5
- This reaches level f<sub>ω<sup>3</sup>+1</sub>.
6
-
7
- Internally, it is represented as an sign,layer, small and array. Sign is 1 or -1. It's 10{oper.arrow, oper.expans, oper.megota}, If arrow count or expans count is Infinite, the count replaces from the next operators.
8
-
9
- Some codes snippet from [ExpantaNum.js by Naruyoko](https://github.com/Naruyoko/ExpantaNum.js)
10
-
11
- Functions are as follows `abs, neg, add, sub, mul, div, rec, pow, sqrt, cbrt, root, log10, log, cmp, isFinite, isInfinite, isNaN`(some missing items that have not been fully developed)
12
-
13
- ## Using
14
-
15
- The library exports a class,
16
- Create a PowiainaNum.js object like this:
17
-
18
- ```javascript
19
- import PowiainaNum from "powiaina_num.js"; // static import
20
- const { default: PowiainaNum } = await import("powiaina_num.js") // dynamic import
21
-
22
- let a = new PowiainaNum(); // create PN.js number with NaN
23
- let b = new PowiainaNum(3); // create PN.js number with number 3
24
- let c = new PowiainaNum("1e114514"); // create PN.js number with number 10^114514
25
-
26
- let d = new PowiainaNum(c); // create PN.js number from a PN.js number
27
- ```
28
-
29
- Javascript operators will not work such as `+`, `-`, etc.
30
- You should call the equivalent functions instead.
31
-
32
- ```javascript
33
- let a = new PowiainaNum(114514);
34
- let b = new PowiainaNum(1919810);
35
-
36
- // Calculate a+b:
37
- let c = a.add(b); // 1919810+114514
38
-
39
- // Calculate a-b:
40
- let c = a.sub(b);
41
-
42
- a.mul(b); // a*b
43
- a.div(b); // a/b
44
- a.pow(b); // a^b
45
-
46
- a.log10(); // log10(a)
47
-
48
- // comparing PN.js numbers
49
-
50
- a.lt(b); // a is less than b
51
- a.gt(b); // a is greater than b
52
- a.eq(b); // a is equals to b
53
- ```
54
-
55
- ## Future ideas
56
-
57
- Extend `Operator` to nearly infinite keys to reach level f<sub>ω<sup>ω</sup></sub>
58
-
59
- ```typescript
60
- interface Operator {
61
- /*P3*/ arrow: number;
62
- /*P4*/ expans: number;
63
- /*P5*/ megota: number;
64
- /*P6*/ powiaina: number;
65
- P7: number;
66
- .....
67
-
68
- repeat: number;
69
-
70
- valuereplaced?: -1 | 0 | 1 | 2 | ...
71
- }
72
- ```
1
+ # PowiainaNum.js
2
+
3
+ A JavaScript library that handles arithmetic for numbers as large as {10,9e15,1,1,1,2}.
4
+
5
+ This reaches level f<sub>ω<sup>3</sup>+1</sub>.
6
+
7
+ Internally, it is represented as an sign, array, small, and layer. Sign is 1 or -1. . Layer is a non-negative integer.
8
+
9
+ The operator interface is `interface {arrow: number; expans: number; megota: number; repeat: number;}`, which respents {10, {10, ...{10, X, arrow, expans, megota}..., arrow, expans, megota}, arrow, expans, megota} (repeat means counts of 10's);
10
+
11
+ The array is `Operator[]`
12
+
13
+ when $$f(x) = \{10, 10, 10, 10, 10, x\}$$
14
+ $$g_{a,b,c}(x) = \{10,x,a,b,c\}$$
15
+ $$o_x = \text{last }x\text{th operator of array} $$
16
+ They together respents $s_{ign}\times f^{l_{ayer}} g_{o_1.arrow, o_1.expans, o_1.megota} g_{o_2.arrow, o_2.expans, o_2.megota} ...$
17
+
18
+ If arrow count or expans count is Infinite, the count replaces to the next operators.
19
+
20
+ Some codes snippet from [ExpantaNum.js by Naruyoko](https://github.com/Naruyoko/ExpantaNum.js)
21
+
22
+ Functions are as follows `abs, neg, add, sub, mul, div, rec, pow, pow10, pow_base, sqrt, cbrt, root, log10, log, cmp, rec, gamma, mod, exp, ln, slog, factorial, tetrate_10, isFinite, isInfinite, isNaN, tetrate, lambertw, toString, toJSON, floor, ceil, round, trunc`(some missing items that have not been fully developed)
23
+
24
+ ## Using
25
+
26
+ The library exports a class,
27
+ Create a PowiainaNum.js object like this:
28
+
29
+ ```javascript
30
+ import PowiainaNum from "powiaina_num.js"; // static import
31
+ const { default: PowiainaNum } = await import("powiaina_num.js") // dynamic import
32
+
33
+ let a = new PowiainaNum(); // create PN.js number with NaN
34
+ let b = new PowiainaNum(3); // create PN.js number with number 3
35
+ let c = new PowiainaNum("1e114514"); // create PN.js number with number 10^114514
36
+
37
+ let d = new PowiainaNum(c); // create PN.js number from a PN.js number
38
+
39
+ let e = new PowiainaNum([[0,23.2352],[1,2],[2,6],[3,0],[4,1],[5,4]]); // You can also use a pair number array which from ExpantaNum.js
40
+
41
+ let f = new PowiainaNum("(10^^^)^114514 e1919810") // ExpantaNum.js string form
42
+
43
+ let g = new PowiainaNum("10{!}e1919810") // 10{!} = 10{x}10, x points to e1919810, 10{!} = J in ExpantaNum.js
44
+ let h = new PowiainaNum("10{1,2}ee114514") // {10, ee114514, 1, 2}
45
+ let i = new PowiainaNum("10{1,514,114}ee114514") // {10, ee114514, 1, 514, 114}
46
+ let j = new PowiainaNum("/10{1,514,114}ee114514") // Very small numbers ({10, ee114514, 1, 514, 114})^-1
47
+ let k = new PowiainaNum("(e^114514)1919810") // break_eternity.js (e^x) form
48
+ ```
49
+
50
+ In browser, you can download `dist/PowiainaNum.min.js` or use
51
+ ```html
52
+ <script src="https://unpkg.com/powiaina_num.js@alpha"></script>
53
+ ```
54
+
55
+ Javascript operators will not work such as `+`, `-`, etc.
56
+ You should call the equivalent functions instead.
57
+
58
+ ```javascript
59
+ let a = new PowiainaNum(114514);
60
+ let b = new PowiainaNum(1919810);
61
+
62
+ // Calculate a+b:
63
+ let c = a.add(b); // 1919810+114514
64
+
65
+ // Calculate a-b:
66
+ let c = a.sub(b);
67
+
68
+ a.mul(b); // a*b
69
+ a.div(b); // a/b
70
+ a.pow(b); // a^b
71
+
72
+ a.log10(); // log10(a)
73
+
74
+ // comparing PN.js numbers
75
+
76
+ a.lt(b); // a is less than b
77
+ a.gt(b); // a is greater than b
78
+ a.eq(b); // a is equals to b
79
+ ```
80
+
81
+ ## Future ideas
82
+
83
+ Extend `Operator` to nearly infinite keys to reach level f<sub>ω<sup>ω</sup></sub>
84
+
85
+ ```typescript
86
+ interface Operator {
87
+ /*P3*/ arrow: number;
88
+ /*P4*/ expans: number;
89
+ /*P5*/ megota: number;
90
+ /*P6*/ powiaina: number;
91
+ P7: number;
92
+ .....
93
+
94
+ repeat: number;
95
+
96
+ valuereplaced?: -1 | 0 | 1 | 2 | ...
97
+ }
98
+ ```
@@ -44,7 +44,7 @@ var MSI_LOG10 = 15.954589770191003;
44
44
  var MSI_REC = 1.1102230246251568e-16;
45
45
  var LONG_STRING_MIN_LENGTH = 17;
46
46
  var EXP_E_REC = 1.444667861009766;
47
- var isPowiainaNum = /^[-\+]*(Infinity|NaN|(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;
47
+ var isPowiainaNum = /^(PN)?\/*[-\+]*(Infinity|NaN|(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d*\x20*)*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;
48
48
  function newOperator(r) {
49
49
  var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
50
50
  var e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
@@ -69,6 +69,16 @@ function compareTuples() {
69
69
  }
70
70
  return 0;
71
71
  }
72
+ function replaceETo10(str) {
73
+ // 使用正则表达式匹配 (e^数字) 的模式
74
+ // 正则解释:\(e\^(\d+)\) 匹配 (e^数字),其中 \d+ 匹配一个或多个数字
75
+ return str.replace(/\(e\^(\d+)\)/g, '(10^)^$1 ').replace(/(\d+)\x20*PT/g, '(10^)^$1 ');
76
+ }
77
+ /**
78
+ * 把一个字符串很长的数进行以10为底的对数
79
+ * @param str 被进行的字符串
80
+ * @returns 字符串以10为底的对数;
81
+ */
72
82
  function log10LongString(str) {
73
83
  return Math.log10(Number(str.substring(0, LONG_STRING_MIN_LENGTH))) + (str.length - LONG_STRING_MIN_LENGTH);
74
84
  }
@@ -153,6 +163,32 @@ function f_lambertw(z) {
153
163
  }
154
164
  throw Error("Iteration failed to converge: ".concat(z.toString())); //return Number.NaN;
155
165
  }
166
+ function isTwoLengthArray(x) {
167
+ return x.length == 2;
168
+ }
169
+ function isTwoNumberArray(x) {
170
+ return typeof x[0] === "number" && typeof x[1] === "number";
171
+ }
172
+ function isExpantaNumArray(x) {
173
+ if (!Array.isArray(x)) return false;
174
+ for (var i = 0; i < x.length; i++) {
175
+ var arr = x[i];
176
+ if (!Array.isArray(arr)) return false;
177
+ if (!isTwoLengthArray(arr)) return false;
178
+ if (!isTwoNumberArray(arr)) return false;
179
+ }
180
+ return true;
181
+ }
182
+ function countLeadingZerosAfterDecimal(numStr) {
183
+ var match = numStr.match(/^0\.(0*)[1-9]/);
184
+ return match ? match[1].length : 0;
185
+ }
186
+ /*
187
+ function countLeadingZerosAfterDecimal(numStr) {
188
+ const match = numStr.match(/^0\.(0*)[1-9]/);
189
+ return match ? match[1].length : 0;
190
+ }
191
+ */
156
192
  //from https://github.com/scipy/scipy/blob/8dba340293fe20e62e173bdf2c10ae208286692f/scipy/special/lambertw.pxd
157
193
  // The evaluation can become inaccurate very close to the branch point
158
194
  // at ``-1/e``. In some corner cases, `lambertw` might currently
@@ -238,6 +274,10 @@ var PowiainaNum = /*#__PURE__*/function () {
238
274
  var b = y.abs();
239
275
  return a.eq(b);
240
276
  }()) return PowiainaNum.ZERO.clone();
277
+ // Run pure number calculates in there
278
+ if (x.abs().lt(MSI) && y.abs().lt(MSI)) {
279
+ return PowiainaNum.fromNumber(x.toNumber() + y.toNumber());
280
+ }
241
281
  // calculate anything > e9e15 or <e-9e15, take absval bigger.
242
282
  if (x.abs().lt(PowiainaNum.E_MSI_REC) || x.abs().gt(PowiainaNum.E_MSI) || y.abs().lt(PowiainaNum.E_MSI_REC) || y.abs().gt(PowiainaNum.E_MSI)) {
243
283
  return x.maxabs(y);
@@ -341,6 +381,7 @@ var PowiainaNum = /*#__PURE__*/function () {
341
381
  if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
342
382
  return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
343
383
  }
384
+ if (r.gt(PowiainaNum.TETRATED_MSI)) return r;
344
385
  r.setOperator(((_b = (_a = r.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0) + 1, 1);
345
386
  r.normalize();
346
387
  return r;
@@ -533,6 +574,7 @@ var PowiainaNum = /*#__PURE__*/function () {
533
574
  return _x.log10().neg();
534
575
  }
535
576
  if (this.array.length == 1) return new PowiainaNum(Math.log10(this.array[0].repeat));
577
+ if (this.gte(PowiainaNum.TETRATED_MSI)) return this.clone();
536
578
  var x = this.clone();
537
579
  x.array[1].repeat = x.array[1].repeat - 1;
538
580
  x.normalize();
@@ -673,6 +715,93 @@ var PowiainaNum = /*#__PURE__*/function () {
673
715
  }
674
716
  }
675
717
  }
718
+ }, {
719
+ key: "arrow",
720
+ value: function arrow(arrows2) {
721
+ var t = this.clone();
722
+ var arrows = new PowiainaNum(arrows2);
723
+ if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
724
+ console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
725
+ return function () {
726
+ return PowiainaNum.NaN.clone();
727
+ };
728
+ }
729
+ if (arrows.eq(0)) return function (other) {
730
+ return t.mul(other);
731
+ };
732
+ if (arrows.eq(1)) return function (other) {
733
+ return t.pow(other);
734
+ };
735
+ if (arrows.eq(2)) return function (other) {
736
+ return t.tetrate(other);
737
+ };
738
+ return function (other2) {
739
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
740
+ var other = new PowiainaNum(other2);
741
+ var ctt = PowiainaNum.arrowFuncMap.get("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString()));
742
+ if (ctt) return ctt.clone();
743
+ var res = function () {
744
+ var r;
745
+ if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
746
+ if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
747
+ if (t.eq(PowiainaNum.ZERO)) {
748
+ if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
749
+ return PowiainaNum.NaN.clone();
750
+ }
751
+ if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
752
+ if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
753
+ if (other.eq(PowiainaNum.ONE)) return t.clone();
754
+ if (arrows.gt(PowiainaNum.MSI)) {
755
+ r = arrows.clone();
756
+ r.setOperator(r.getOperator(Infinity) + 1, Infinity);
757
+ return r;
758
+ }
759
+ var arrowsNum = arrows.toNumber();
760
+ if (other.eq(2)) return t.arrow(arrowsNum - 1)(t, depth + 1);
761
+ if (t.max(other).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) return t.max(other);
762
+ if (t.gt(PowiainaNum.arrowMSI(arrowsNum)) || other.gt(MSI)) {
763
+ if (t.gt(PowiainaNum.arrowMSI(arrowsNum))) {
764
+ r = t.clone();
765
+ r.setOperator(r.getOperator(arrowsNum) - 1, arrowsNum);
766
+ r.normalize();
767
+ } else if (t.gt(PowiainaNum.arrowMSI(arrowsNum - 1))) {
768
+ r = new PowiainaNum(t.getOperator(arrowsNum - 1));
769
+ } else {
770
+ r = PowiainaNum.ZERO;
771
+ }
772
+ var j = r.add(other);
773
+ j.setOperator(j.getOperator(arrowsNum) + 1, arrowsNum);
774
+ j.normalize();
775
+ return j;
776
+ }
777
+ if (depth >= PowiainaNum.maxOps + 10) {
778
+ return new PowiainaNum([[0, 10], [arrowsNum, 1]]);
779
+ }
780
+ var y = other.toNumber();
781
+ var f = Math.floor(y);
782
+ var arrows_m1 = arrows.sub(PowiainaNum.ONE);
783
+ r = t.arrow(arrows_m1)(y - f, depth + 1);
784
+ var i = 0;
785
+ for (var m = PowiainaNum.arrowMSI(arrowsNum - 1); f !== 0 && r.lt(m) && i < 100; i++) {
786
+ if (f > 0) {
787
+ r = t.arrow(arrows_m1)(r, depth + 1);
788
+ --f;
789
+ }
790
+ }
791
+ if (i == 100) f = 0;
792
+ r.setOperator(r.getOperator(arrowsNum - 1) + f, arrowsNum - 1);
793
+ r.normalize();
794
+ return r;
795
+ }();
796
+ PowiainaNum.arrowFuncMap.set("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString()), res.clone());
797
+ return res;
798
+ };
799
+ }
800
+ }, {
801
+ key: "chain",
802
+ value: function chain(other, arrows) {
803
+ return this.arrow(arrows)(other);
804
+ }
676
805
  }, {
677
806
  key: "max",
678
807
  value: function max(x) {
@@ -1003,7 +1132,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1003
1132
  renormalize = true;
1004
1133
  }
1005
1134
  while (x.array.length >= 2 && x.array[0].repeat == 1 && x.array[1].repeat) {
1006
- // for any 10{X}10{X} 1, turn into 10{x}10
1135
+ // for any 10{X}10{X} 1, turn into 10{X}10
1007
1136
  // [1, [R=sth, A=sth, E=sth, M=sth]]
1008
1137
  if (x.array[1].repeat > 1) {
1009
1138
  x.array[1].repeat--;
@@ -1013,8 +1142,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1013
1142
  x.array[0].repeat = 10;
1014
1143
  renormalize = true;
1015
1144
  }
1016
- if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1) {
1145
+ if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1 && isFinite(x.array[1].arrow)) {
1017
1146
  // for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
1147
+ // But dont convert when a is infinite
1018
1148
  // [1e9, [R=1, A=2, sth, sth]]
1019
1149
  x.array.splice(1, 1, newOperator(x.array[0].repeat, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
1020
1150
  x.array[0].repeat = 10;
@@ -1030,12 +1160,13 @@ var PowiainaNum = /*#__PURE__*/function () {
1030
1160
  } while (renormalize);
1031
1161
  return this;
1032
1162
  }
1163
+ }, {
1164
+ key: "getOperatorIndex",
1165
+ value:
1033
1166
  /**
1034
1167
  * @returns number will return the index of the operator in array. return as x.5 if it's between the xth and x+1th operators.
1035
1168
  */
1036
- }, {
1037
- key: "getOperatorIndex",
1038
- value: function getOperatorIndex(arrow) {
1169
+ function getOperatorIndex(arrow) {
1039
1170
  var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1040
1171
  var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1041
1172
  if (this.array.length == 1 && arrow == 0) return 0;
@@ -1088,7 +1219,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1088
1219
  return false;
1089
1220
  }
1090
1221
  /**
1091
- * @returns PowiainaNum a PowiainaNum object which deep copied from `this` object.
1222
+ * @returns a PowiainaNum object which deep copied from `this` object.
1092
1223
  */
1093
1224
  }, {
1094
1225
  key: "clone",
@@ -1115,6 +1246,11 @@ var PowiainaNum = /*#__PURE__*/function () {
1115
1246
  this.layer = powlikeObject.layer;
1116
1247
  return this;
1117
1248
  }
1249
+ /**
1250
+ * Convert `this` to Javascript `number`
1251
+ *
1252
+ * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1253
+ */
1118
1254
  }, {
1119
1255
  key: "toNumber",
1120
1256
  value: function toNumber() {
@@ -1124,13 +1260,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1124
1260
  if (this.array.length == 1) return this.array[0].repeat;else if (this.array.length == 2 && this.array[1].arrow == 1 && this.array[1].expans == 1 && this.array[1].megota == 1 && this.array[1].repeat == 1) return Math.pow(10, this.getOperator(0));
1125
1261
  return NaN;
1126
1262
  }
1263
+ /**
1264
+ * Convert `this` to a string
1265
+ */
1127
1266
  }, {
1128
1267
  key: "toString",
1129
1268
  value: function toString() {
1130
1269
  if (this.isNaN()) return "NaN";
1131
1270
  if (this.sign == -1) return "-".concat(this.neg().toString());
1132
1271
  if (this.small) {
1133
- if (this.eq(PowiainaNum.ZERO)) return "0";
1272
+ if (this.isZero()) return "0";
1134
1273
  return "/".concat(this.rec().toString());
1135
1274
  }
1136
1275
  if (this.isInfi()) return "Infinity";
@@ -1146,12 +1285,22 @@ var PowiainaNum = /*#__PURE__*/function () {
1146
1285
  } else if (oper.repeat > 1) {
1147
1286
  calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1148
1287
  } else {
1149
- calc = "".concat(calc, " ");
1288
+ calc = "".concat(calc);
1150
1289
  }
1151
1290
  res += "".concat(calc);
1152
1291
  }
1153
1292
  return res;
1154
1293
  }
1294
+ }, {
1295
+ key: "toJSON",
1296
+ value:
1297
+ /**
1298
+ * Convert `this` to a JSON object
1299
+ * @returns a JSON object
1300
+ */
1301
+ function toJSON() {
1302
+ return "PN" + this.toString();
1303
+ }
1155
1304
  }, {
1156
1305
  key: "arr01",
1157
1306
  get:
@@ -1295,6 +1444,11 @@ var PowiainaNum = /*#__PURE__*/function () {
1295
1444
  value: function isNaN(x) {
1296
1445
  return new PowiainaNum(x).isNaN();
1297
1446
  }
1447
+ }, {
1448
+ key: "arrowMSI",
1449
+ value: function arrowMSI(arrowsNum) {
1450
+ return new PowiainaNum("10".concat(arrowsNum).concat(MSI));
1451
+ }
1298
1452
  }, {
1299
1453
  key: "fromNumber",
1300
1454
  value: function fromNumber(x) {
@@ -1327,14 +1481,52 @@ var PowiainaNum = /*#__PURE__*/function () {
1327
1481
  var _a, _b, _c, _d, _e, _f;
1328
1482
  var x = new PowiainaNum();
1329
1483
  // Judge the string was a number
1330
- // @ts-ignore
1484
+ if (input.startsWith("PN")) input = input.substring(2);
1331
1485
  if (!isNaN(Number(input))) {
1332
- // @ts-ignore
1333
- if (isFinite(Number(input))) {
1486
+ var res = Number(input);
1487
+ var _a2 = false;
1488
+ if (res == 0) {
1489
+ if (/^(0*\.0*e)|(0*\.0*)$/.test(input)) {
1490
+ _a2 = true;
1491
+ }
1492
+ } else {
1493
+ _a2 = true;
1494
+ }
1495
+ if (!_a2) {
1496
+ var m = input.search(/e/);
1497
+ var exponent = input.substring((m == -1 ? input.length : m) + 1);
1498
+ var mantissa = input.substring(0, m == -1 ? undefined : m);
1499
+ var mantissaME = [0, 0];
1500
+ // Handle mantissa to ME
1501
+ mantissaME[1] = Number(exponent ? exponent : "0");
1502
+ // Is regular number gte 1:
1503
+ if (Number(mantissa) >= 1) {
1504
+ // check The mantissa is very long?
1505
+ var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
1506
+ var log10int = Math.floor(log10mant) - 1;
1507
+ var log10float = log10mant - log10int;
1508
+ mantissaME[0] = Math.pow(10, log10float);
1509
+ mantissaME[1] += log10float;
1510
+ } else {
1511
+ // If not , count how many zeros until reached non-zero numbers
1512
+ var zeros = countLeadingZerosAfterDecimal(mantissa);
1513
+ mantissa = mantissa.substring(mantissa.search(/[1-9]/));
1514
+ mantissa = mantissa.charAt(0) + "." + mantissa.substring(1);
1515
+ zeros += 1;
1516
+ mantissaME[0] = Number(mantissa);
1517
+ mantissaME[1] += -zeros;
1518
+ }
1519
+ // We'll get [a, b] which respents a*10^b;
1520
+ // actually b < 0; So we can ^-1
1521
+ // /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
1522
+ return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
1523
+ }
1524
+ if (isFinite(res) && _a2) {
1334
1525
  x.resetFromObject(PowiainaNum.fromNumber(Number(input)));
1335
1526
  return x;
1336
1527
  }
1337
1528
  }
1529
+ input = replaceETo10(input);
1338
1530
  if (!isPowiainaNum.test(input)) {
1339
1531
  throw powiainaNumError + "malformed input: " + input;
1340
1532
  }
@@ -1482,19 +1674,35 @@ var PowiainaNum = /*#__PURE__*/function () {
1482
1674
  value: function fromObject(powlikeObject) {
1483
1675
  var obj = new PowiainaNum();
1484
1676
  obj.array = [];
1485
- for (var i = 0; i < powlikeObject.array.length; i++) {
1486
- obj.array[i] = {
1487
- arrow: powlikeObject.array[i].arrow,
1488
- expans: powlikeObject.array[i].expans,
1489
- megota: powlikeObject.array[i].megota,
1490
- repeat: powlikeObject.array[i].repeat,
1491
- valuereplaced: powlikeObject.array[i].valuereplaced
1492
- };
1677
+ if (isExpantaNumArray(powlikeObject)) {
1678
+ for (var i = 0; i < powlikeObject.length; i++) {
1679
+ obj.array[i] = {
1680
+ arrow: powlikeObject[i][0],
1681
+ expans: 1,
1682
+ megota: 1,
1683
+ repeat: powlikeObject[i][1]
1684
+ };
1685
+ }
1686
+ obj.small = false;
1687
+ obj.sign = 1;
1688
+ obj.layer = 0;
1689
+ obj.normalize();
1690
+ return obj;
1691
+ } else {
1692
+ for (var _i3 = 0; _i3 < powlikeObject.array.length; _i3++) {
1693
+ obj.array[_i3] = {
1694
+ arrow: powlikeObject.array[_i3].arrow,
1695
+ expans: powlikeObject.array[_i3].expans,
1696
+ megota: powlikeObject.array[_i3].megota,
1697
+ repeat: powlikeObject.array[_i3].repeat,
1698
+ valuereplaced: powlikeObject.array[_i3].valuereplaced
1699
+ };
1700
+ }
1701
+ obj.small = powlikeObject.small;
1702
+ obj.sign = powlikeObject.sign;
1703
+ obj.layer = powlikeObject.layer;
1704
+ return obj;
1493
1705
  }
1494
- obj.small = powlikeObject.small;
1495
- obj.sign = powlikeObject.sign;
1496
- obj.layer = powlikeObject.layer;
1497
- return obj;
1498
1706
  }
1499
1707
  }]);
1500
1708
  }();
@@ -1616,5 +1824,6 @@ PowiainaNum.NaN = new PowiainaNum({
1616
1824
  sign: 0
1617
1825
  });
1618
1826
  PowiainaNum.maxOps = 100;
1827
+ PowiainaNum.arrowFuncMap = new Map();
1619
1828
 
1620
1829
  module.exports = PowiainaNum;