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

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
@@ -19,7 +19,7 @@ If arrow count or expans count is Infinite, the count replaces to the next opera
19
19
 
20
20
  Some codes snippet from [ExpantaNum.js by Naruyoko](https://github.com/Naruyoko/ExpantaNum.js)
21
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)
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, clampMax, clampMin`(some missing items that have not been fully developed)
23
23
 
24
24
  ## Using
25
25
 
@@ -1,5 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ function _arrayLikeToArray(r, a) {
4
+ (null == a || a > r.length) && (a = r.length);
5
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
+ return n;
7
+ }
8
+ function _arrayWithoutHoles(r) {
9
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
10
+ }
3
11
  function _classCallCheck(a, n) {
4
12
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
5
13
  }
@@ -14,6 +22,15 @@ function _createClass(e, r, t) {
14
22
  writable: !1
15
23
  }), e;
16
24
  }
25
+ function _iterableToArray(r) {
26
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
27
+ }
28
+ function _nonIterableSpread() {
29
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
30
+ }
31
+ function _toConsumableArray(r) {
32
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
33
+ }
17
34
  function _toPrimitive(t, r) {
18
35
  if ("object" != typeof t || !t) return t;
19
36
  var e = t[Symbol.toPrimitive];
@@ -37,6 +54,13 @@ function _typeof(o) {
37
54
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
38
55
  }, _typeof(o);
39
56
  }
57
+ function _unsupportedIterableToArray(r, a) {
58
+ if (r) {
59
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
60
+ var t = {}.toString.call(r).slice(8, -1);
61
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
62
+ }
63
+ }
40
64
 
41
65
  var powiainaNumError = "[PowiainaNum 0.2 error]";
42
66
  var MSI = 9007199254740991;
@@ -228,8 +252,13 @@ function d_lambertw(z) {
228
252
  throw Error("Iteration failed to converge: ".concat(z.toString())); //return Decimal.dNaN;
229
253
  }
230
254
  var PowiainaNum = /*#__PURE__*/function () {
255
+ /**
256
+ * Constructor of PowiainaNum class,
257
+ * If no arguments, return `PowiainaNum.NaN`.
258
+ */
231
259
  function PowiainaNum(arg1) {
232
260
  _classCallCheck(this, PowiainaNum);
261
+ this.a = Number.MAX_SAFE_INTEGER;
233
262
  this.array = [{
234
263
  arrow: 0,
235
264
  expans: 1,
@@ -364,7 +393,11 @@ var PowiainaNum = /*#__PURE__*/function () {
364
393
  }
365
394
  }, {
366
395
  key: "pow10",
367
- value: function pow10() {
396
+ value:
397
+ /**
398
+ * @returns 10 to the power of `this`
399
+ */
400
+ function pow10() {
368
401
  var _a, _b;
369
402
  var r = this.clone();
370
403
  // inf & nan check
@@ -802,29 +835,51 @@ var PowiainaNum = /*#__PURE__*/function () {
802
835
  value: function chain(other, arrows) {
803
836
  return this.arrow(arrows)(other);
804
837
  }
838
+ /**
839
+ * Select the largest number of arguments.
840
+ */
805
841
  }, {
806
842
  key: "max",
807
- value: function max(x) {
808
- var other = new PowiainaNum(x);
809
- return this.lt(other) ? other.clone() : this.clone();
843
+ value: function max() {
844
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
845
+ args[_key2] = arguments[_key2];
846
+ }
847
+ return PowiainaNum.max.apply(PowiainaNum, [this].concat(args));
810
848
  }
811
849
  }, {
812
850
  key: "min",
813
- value: function min(x) {
814
- var other = new PowiainaNum(x);
815
- return this.gte(other) ? other.clone() : this.clone();
851
+ value: function min() {
852
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
853
+ args[_key3] = arguments[_key3];
854
+ }
855
+ return PowiainaNum.min.apply(PowiainaNum, [this].concat(args));
816
856
  }
857
+ /**
858
+ * Compare what PowiainaNum's absolute value is max
859
+ * @param args
860
+ * @returns absolute value max number's absolute value
861
+ */
817
862
  }, {
818
863
  key: "maxabs",
819
- value: function maxabs(x) {
820
- var other = new PowiainaNum(x).abs();
821
- return this.abs().lt(other) ? other.clone() : this.clone();
864
+ value: function maxabs() {
865
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
866
+ args[_key4] = arguments[_key4];
867
+ }
868
+ var other = args.map(function (x) {
869
+ return new PowiainaNum(x).abs();
870
+ });
871
+ return PowiainaNum.max.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
822
872
  }
823
873
  }, {
824
874
  key: "minabs",
825
- value: function minabs(x) {
826
- var other = new PowiainaNum(x).abs();
827
- return this.abs().gt(other) ? other.clone() : this.clone();
875
+ value: function minabs() {
876
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
877
+ args[_key5] = arguments[_key5];
878
+ }
879
+ var other = args.map(function (x) {
880
+ return new PowiainaNum(x).abs();
881
+ });
882
+ return PowiainaNum.min.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
828
883
  }
829
884
  }, {
830
885
  key: "cmpabs",
@@ -1120,7 +1175,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1120
1175
  this.setOperator(Math.pow(10, this.getOperator(0)), 0);
1121
1176
  renormalize = true;
1122
1177
  }
1123
- if (this.getOperator(0) > MSI) {
1178
+ if (this.getOperator(0) > MSI && !isFinite(this.getOperator(0))) {
1124
1179
  this.setOperator(this.getOperator(1) + 1, 1);
1125
1180
  this.setOperator(Math.log10(this.getOperator(0)), 0);
1126
1181
  renormalize = true;
@@ -1305,7 +1360,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1305
1360
  key: "arr01",
1306
1361
  get:
1307
1362
  /**
1308
- * A property arary value for version 0.1.x PowiainaNum.
1363
+ * A property array value for version 0.1.x PowiainaNum.
1309
1364
  */
1310
1365
  function get() {
1311
1366
  var res = [0];
@@ -1439,6 +1494,64 @@ var PowiainaNum = /*#__PURE__*/function () {
1439
1494
  // 2--3, 1e10-<e1e10, 10^10^10^0->1
1440
1495
  return PowiainaNum.NaN.clone();*/
1441
1496
  }
1497
+ }, {
1498
+ key: "max",
1499
+ value: function max() {
1500
+ var max = PowiainaNum.NEGATIVE_INFINITY;
1501
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1502
+ args[_key6] = arguments[_key6];
1503
+ }
1504
+ for (var i = 0; i < args.length; i++) {
1505
+ if (max.lt(args[i])) {
1506
+ max = new PowiainaNum(args[i]).clone();
1507
+ }
1508
+ }
1509
+ return max;
1510
+ }
1511
+ /**
1512
+ * Select the smallest number of arguments.
1513
+ */
1514
+ }, {
1515
+ key: "min",
1516
+ value: function min() {
1517
+ var max = PowiainaNum.POSITIVE_INFINITY;
1518
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
1519
+ args[_key7] = arguments[_key7];
1520
+ }
1521
+ for (var i = 0; i < args.length; i++) {
1522
+ if (max.gt(args[i])) {
1523
+ max = new PowiainaNum(args[i]).clone();
1524
+ }
1525
+ }
1526
+ return max;
1527
+ }
1528
+ /**
1529
+ * Restrict a number be not lower than a number
1530
+ *
1531
+ * It's also an alias of `PowiainaNum.max`.
1532
+ * @returns restricted number
1533
+ */
1534
+ }, {
1535
+ key: "clampMin",
1536
+ value: function clampMin() {
1537
+ return PowiainaNum.max.apply(PowiainaNum, arguments);
1538
+ }
1539
+ /**
1540
+ * Restrict a number be not higher than a number
1541
+ *
1542
+ * It's also an alias of `PowiainaNum.min`.
1543
+ * @returns restricted number
1544
+ */
1545
+ }, {
1546
+ key: "clampMax",
1547
+ value: function clampMax() {
1548
+ return PowiainaNum.min.apply(PowiainaNum, arguments);
1549
+ }
1550
+ }, {
1551
+ key: "sign",
1552
+ value: function sign(a) {
1553
+ return new PowiainaNum(a).sign;
1554
+ }
1442
1555
  }, {
1443
1556
  key: "isNaN",
1444
1557
  value: function isNaN(x) {
@@ -1706,6 +1819,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1706
1819
  }
1707
1820
  }]);
1708
1821
  }();
1822
+ /**
1823
+ * Zero
1824
+ */
1709
1825
  PowiainaNum.ZERO = new PowiainaNum({
1710
1826
  array: [{
1711
1827
  arrow: 0,
@@ -1717,6 +1833,9 @@ PowiainaNum.ZERO = new PowiainaNum({
1717
1833
  layer: 0,
1718
1834
  sign: 0
1719
1835
  });
1836
+ /**
1837
+ * One
1838
+ */
1720
1839
  PowiainaNum.ONE = new PowiainaNum({
1721
1840
  array: [{
1722
1841
  arrow: 0,
@@ -1728,12 +1847,22 @@ PowiainaNum.ONE = new PowiainaNum({
1728
1847
  layer: 0,
1729
1848
  sign: 1
1730
1849
  });
1850
+ /**
1851
+ * The value of the largest integer n such that n and n + 1 are both
1852
+ * exactly representable as a Number value = 9007199254740991 = 2^53 − 1.
1853
+ */
1731
1854
  PowiainaNum.MSI = new PowiainaNum(MSI);
1855
+ /**
1856
+ * MSI's reciprocate value, = 1/9007199254740991.
1857
+ */
1732
1858
  PowiainaNum.MSI_REC = function () {
1733
1859
  var obj = new PowiainaNum(MSI);
1734
1860
  obj.small = true;
1735
1861
  return obj;
1736
1862
  }();
1863
+ /**
1864
+ * 10^(MSI) = 10^9007199254740991.
1865
+ */
1737
1866
  PowiainaNum.E_MSI = new PowiainaNum({
1738
1867
  array: [{
1739
1868
  arrow: 0,
@@ -1750,6 +1879,9 @@ PowiainaNum.E_MSI = new PowiainaNum({
1750
1879
  layer: 0,
1751
1880
  sign: 1
1752
1881
  });
1882
+ /**
1883
+ * 10^(MSI) 's reciprocate value, = 10^-9007199254740991.
1884
+ */
1753
1885
  PowiainaNum.E_MSI_REC = new PowiainaNum({
1754
1886
  array: [{
1755
1887
  arrow: 0,
@@ -1766,51 +1898,69 @@ PowiainaNum.E_MSI_REC = new PowiainaNum({
1766
1898
  layer: 0,
1767
1899
  sign: 1
1768
1900
  });
1901
+ /**
1902
+ * Tetrated MSI, = 10↑↑9007199254740991.
1903
+ */
1769
1904
  PowiainaNum.TETRATED_MSI = new PowiainaNum({
1770
1905
  array: [{
1771
1906
  arrow: 0,
1772
1907
  expans: 1,
1773
1908
  megota: 1,
1774
- repeat: MSI
1909
+ repeat: 1e10
1775
1910
  }, {
1776
1911
  arrow: 1,
1777
1912
  expans: 1,
1778
1913
  megota: 1,
1779
- repeat: MSI
1914
+ repeat: MSI - 2
1780
1915
  }],
1781
1916
  small: false,
1782
1917
  layer: 0,
1783
1918
  sign: 1
1784
1919
  });
1920
+ /**
1921
+ * Pentated MSI, = 10↑↑↑9007199254740991.
1922
+ */
1785
1923
  PowiainaNum.PENTATED_MSI = new PowiainaNum({
1786
1924
  array: [{
1787
1925
  arrow: 0,
1788
1926
  expans: 1,
1789
1927
  megota: 1,
1790
- repeat: MSI
1791
- }, {
1792
- arrow: 1,
1793
- expans: 1,
1794
- megota: 1,
1795
- repeat: MSI
1928
+ repeat: 10
1796
1929
  }, {
1797
1930
  arrow: 2,
1798
1931
  expans: 1,
1799
1932
  megota: 1,
1800
- repeat: MSI
1933
+ repeat: MSI - 1
1801
1934
  }],
1802
1935
  small: false,
1803
1936
  layer: 0,
1804
1937
  sign: 1
1805
1938
  });
1939
+ /**
1940
+ * Tritri, = 3↑↑↑3 = power tower with height 7625597484987 base 3.
1941
+ */
1806
1942
  PowiainaNum.TRITRI = new PowiainaNum({
1807
1943
  small: false,
1808
1944
  layer: 0,
1809
1945
  sign: 1,
1810
1946
  array: [newOperator(3638334640023.7783, 0, 1, 1), newOperator(7625587484984, 1, 1, 1)]
1811
1947
  });
1948
+ /**
1949
+ * The Graham's Number, = G^64(4)
1950
+ *
1951
+ * = 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{
1952
+ * 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3↑↑↑↑3
1953
+ * }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
1954
+ * }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
1955
+ */
1812
1956
  PowiainaNum.GRAHAMS_NUMBER = new PowiainaNum("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783");
1957
+ /**
1958
+ * Positive Infinity.
1959
+ */
1813
1960
  PowiainaNum.POSITIVE_INFINITY = new PowiainaNum(Infinity);
1961
+ /**
1962
+ * Negative Infinity.
1963
+ */
1814
1964
  PowiainaNum.NEGATIVE_INFINITY = new PowiainaNum(-Infinity);
1815
1965
  PowiainaNum.NaN = new PowiainaNum({
1816
1966
  array: [{
@@ -1823,6 +1973,40 @@ PowiainaNum.NaN = new PowiainaNum({
1823
1973
  layer: 0,
1824
1974
  sign: 0
1825
1975
  });
1976
+ /**
1977
+ * The mathematical constant e. This is Euler's number, the base of natural logarithms.
1978
+ */
1979
+ PowiainaNum.E = new PowiainaNum(Math.E);
1980
+ /**
1981
+ * The natural logarithm of 2 = ln(2).
1982
+ */
1983
+ PowiainaNum.LN2 = new PowiainaNum(Math.LN2);
1984
+ /**
1985
+ * The natural logarithm of 10.
1986
+ */
1987
+ PowiainaNum.LN10 = new PowiainaNum(Math.LN10);
1988
+ /**
1989
+ * The base-2 logarithm of e = log_2(e).
1990
+ */
1991
+ PowiainaNum.LOG2E = new PowiainaNum(Math.LOG2E);
1992
+ /**
1993
+ * The base-10 logarithm of e = log_10(e).
1994
+ */
1995
+ PowiainaNum.LOG10E = new PowiainaNum(Math.LOG10E);
1996
+ /**
1997
+ * Pi(). This is the ratio of the circumference of a circle to its diameter.
1998
+ */
1999
+ PowiainaNum.PI = new PowiainaNum(Math.PI);
2000
+ /**
2001
+ * The square root of 0.5, or, equivalently, one divided by the square root of 2.
2002
+ *
2003
+ * = (√2)/2 = √(0.5)
2004
+ */
2005
+ PowiainaNum.SQRT1_2 = new PowiainaNum(Math.SQRT1_2);
2006
+ /**
2007
+ * The square root of 2 = √2.
2008
+ */
2009
+ PowiainaNum.SQRT2 = new PowiainaNum(Math.SQRT2);
1826
2010
  PowiainaNum.maxOps = 100;
1827
2011
  PowiainaNum.arrowFuncMap = new Map();
1828
2012