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

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,6 +252,10 @@ 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);
233
261
  this.array = [{
@@ -364,7 +392,11 @@ var PowiainaNum = /*#__PURE__*/function () {
364
392
  }
365
393
  }, {
366
394
  key: "pow10",
367
- value: function pow10() {
395
+ value:
396
+ /**
397
+ * @returns 10 to the power of `this`
398
+ */
399
+ function pow10() {
368
400
  var _a, _b;
369
401
  var r = this.clone();
370
402
  // inf & nan check
@@ -694,7 +726,7 @@ var PowiainaNum = /*#__PURE__*/function () {
694
726
  } else if (principal) {
695
727
  if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
696
728
  return PowiainaNum.fromNumber(f_lambertw(this.toNumber()));
697
- } else if (this.layer === 0) {
729
+ } else if (this.lt(MSI)) {
698
730
  return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0)));
699
731
  } else if (this.lt("eee15")) {
700
732
  return d_lambertw(this);
@@ -802,29 +834,51 @@ var PowiainaNum = /*#__PURE__*/function () {
802
834
  value: function chain(other, arrows) {
803
835
  return this.arrow(arrows)(other);
804
836
  }
837
+ /**
838
+ * Select the largest number of arguments.
839
+ */
805
840
  }, {
806
841
  key: "max",
807
- value: function max(x) {
808
- var other = new PowiainaNum(x);
809
- return this.lt(other) ? other.clone() : this.clone();
842
+ value: function max() {
843
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
844
+ args[_key2] = arguments[_key2];
845
+ }
846
+ return PowiainaNum.max.apply(PowiainaNum, [this].concat(args));
810
847
  }
811
848
  }, {
812
849
  key: "min",
813
- value: function min(x) {
814
- var other = new PowiainaNum(x);
815
- return this.gte(other) ? other.clone() : this.clone();
850
+ value: function min() {
851
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
852
+ args[_key3] = arguments[_key3];
853
+ }
854
+ return PowiainaNum.min.apply(PowiainaNum, [this].concat(args));
816
855
  }
856
+ /**
857
+ * Compare what PowiainaNum's absolute value is max
858
+ * @param args
859
+ * @returns absolute value max number's absolute value
860
+ */
817
861
  }, {
818
862
  key: "maxabs",
819
- value: function maxabs(x) {
820
- var other = new PowiainaNum(x).abs();
821
- return this.abs().lt(other) ? other.clone() : this.clone();
863
+ value: function maxabs() {
864
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
865
+ args[_key4] = arguments[_key4];
866
+ }
867
+ var other = args.map(function (x) {
868
+ return new PowiainaNum(x).abs();
869
+ });
870
+ return PowiainaNum.max.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
822
871
  }
823
872
  }, {
824
873
  key: "minabs",
825
- value: function minabs(x) {
826
- var other = new PowiainaNum(x).abs();
827
- return this.abs().gt(other) ? other.clone() : this.clone();
874
+ value: function minabs() {
875
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
876
+ args[_key5] = arguments[_key5];
877
+ }
878
+ var other = args.map(function (x) {
879
+ return new PowiainaNum(x).abs();
880
+ });
881
+ return PowiainaNum.min.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
828
882
  }
829
883
  }, {
830
884
  key: "cmpabs",
@@ -1120,7 +1174,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1120
1174
  this.setOperator(Math.pow(10, this.getOperator(0)), 0);
1121
1175
  renormalize = true;
1122
1176
  }
1123
- if (this.getOperator(0) > MSI) {
1177
+ if (this.getOperator(0) > MSI && !isFinite(this.getOperator(0))) {
1124
1178
  this.setOperator(this.getOperator(1) + 1, 1);
1125
1179
  this.setOperator(Math.log10(this.getOperator(0)), 0);
1126
1180
  renormalize = true;
@@ -1305,7 +1359,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1305
1359
  key: "arr01",
1306
1360
  get:
1307
1361
  /**
1308
- * A property arary value for version 0.1.x PowiainaNum.
1362
+ * A property array value for version 0.1.x PowiainaNum.
1309
1363
  */
1310
1364
  function get() {
1311
1365
  var res = [0];
@@ -1439,6 +1493,64 @@ var PowiainaNum = /*#__PURE__*/function () {
1439
1493
  // 2--3, 1e10-<e1e10, 10^10^10^0->1
1440
1494
  return PowiainaNum.NaN.clone();*/
1441
1495
  }
1496
+ }, {
1497
+ key: "max",
1498
+ value: function max() {
1499
+ var max = PowiainaNum.NEGATIVE_INFINITY;
1500
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1501
+ args[_key6] = arguments[_key6];
1502
+ }
1503
+ for (var i = 0; i < args.length; i++) {
1504
+ if (max.lt(args[i])) {
1505
+ max = new PowiainaNum(args[i]).clone();
1506
+ }
1507
+ }
1508
+ return max;
1509
+ }
1510
+ /**
1511
+ * Select the smallest number of arguments.
1512
+ */
1513
+ }, {
1514
+ key: "min",
1515
+ value: function min() {
1516
+ var max = PowiainaNum.POSITIVE_INFINITY;
1517
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
1518
+ args[_key7] = arguments[_key7];
1519
+ }
1520
+ for (var i = 0; i < args.length; i++) {
1521
+ if (max.gt(args[i])) {
1522
+ max = new PowiainaNum(args[i]).clone();
1523
+ }
1524
+ }
1525
+ return max;
1526
+ }
1527
+ /**
1528
+ * Restrict a number be not lower than a number
1529
+ *
1530
+ * It's also an alias of `PowiainaNum.max`.
1531
+ * @returns restricted number
1532
+ */
1533
+ }, {
1534
+ key: "clampMin",
1535
+ value: function clampMin() {
1536
+ return PowiainaNum.max.apply(PowiainaNum, arguments);
1537
+ }
1538
+ /**
1539
+ * Restrict a number be not higher than a number
1540
+ *
1541
+ * It's also an alias of `PowiainaNum.min`.
1542
+ * @returns restricted number
1543
+ */
1544
+ }, {
1545
+ key: "clampMax",
1546
+ value: function clampMax() {
1547
+ return PowiainaNum.min.apply(PowiainaNum, arguments);
1548
+ }
1549
+ }, {
1550
+ key: "sign",
1551
+ value: function sign(a) {
1552
+ return new PowiainaNum(a).sign;
1553
+ }
1442
1554
  }, {
1443
1555
  key: "isNaN",
1444
1556
  value: function isNaN(x) {
@@ -1706,6 +1818,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1706
1818
  }
1707
1819
  }]);
1708
1820
  }();
1821
+ /**
1822
+ * Zero
1823
+ */
1709
1824
  PowiainaNum.ZERO = new PowiainaNum({
1710
1825
  array: [{
1711
1826
  arrow: 0,
@@ -1717,6 +1832,9 @@ PowiainaNum.ZERO = new PowiainaNum({
1717
1832
  layer: 0,
1718
1833
  sign: 0
1719
1834
  });
1835
+ /**
1836
+ * One
1837
+ */
1720
1838
  PowiainaNum.ONE = new PowiainaNum({
1721
1839
  array: [{
1722
1840
  arrow: 0,
@@ -1728,12 +1846,22 @@ PowiainaNum.ONE = new PowiainaNum({
1728
1846
  layer: 0,
1729
1847
  sign: 1
1730
1848
  });
1849
+ /**
1850
+ * The value of the largest integer n such that n and n + 1 are both
1851
+ * exactly representable as a Number value = 9007199254740991 = 2^53 − 1.
1852
+ */
1731
1853
  PowiainaNum.MSI = new PowiainaNum(MSI);
1854
+ /**
1855
+ * MSI's reciprocate value, = 1/9007199254740991.
1856
+ */
1732
1857
  PowiainaNum.MSI_REC = function () {
1733
1858
  var obj = new PowiainaNum(MSI);
1734
1859
  obj.small = true;
1735
1860
  return obj;
1736
1861
  }();
1862
+ /**
1863
+ * 10^(MSI) = 10^9007199254740991.
1864
+ */
1737
1865
  PowiainaNum.E_MSI = new PowiainaNum({
1738
1866
  array: [{
1739
1867
  arrow: 0,
@@ -1750,6 +1878,9 @@ PowiainaNum.E_MSI = new PowiainaNum({
1750
1878
  layer: 0,
1751
1879
  sign: 1
1752
1880
  });
1881
+ /**
1882
+ * 10^(MSI) 's reciprocate value, = 10^-9007199254740991.
1883
+ */
1753
1884
  PowiainaNum.E_MSI_REC = new PowiainaNum({
1754
1885
  array: [{
1755
1886
  arrow: 0,
@@ -1766,51 +1897,69 @@ PowiainaNum.E_MSI_REC = new PowiainaNum({
1766
1897
  layer: 0,
1767
1898
  sign: 1
1768
1899
  });
1900
+ /**
1901
+ * Tetrated MSI, = 10↑↑9007199254740991.
1902
+ */
1769
1903
  PowiainaNum.TETRATED_MSI = new PowiainaNum({
1770
1904
  array: [{
1771
1905
  arrow: 0,
1772
1906
  expans: 1,
1773
1907
  megota: 1,
1774
- repeat: MSI
1908
+ repeat: 1e10
1775
1909
  }, {
1776
1910
  arrow: 1,
1777
1911
  expans: 1,
1778
1912
  megota: 1,
1779
- repeat: MSI
1913
+ repeat: MSI - 2
1780
1914
  }],
1781
1915
  small: false,
1782
1916
  layer: 0,
1783
1917
  sign: 1
1784
1918
  });
1919
+ /**
1920
+ * Pentated MSI, = 10↑↑↑9007199254740991.
1921
+ */
1785
1922
  PowiainaNum.PENTATED_MSI = new PowiainaNum({
1786
1923
  array: [{
1787
1924
  arrow: 0,
1788
1925
  expans: 1,
1789
1926
  megota: 1,
1790
- repeat: MSI
1791
- }, {
1792
- arrow: 1,
1793
- expans: 1,
1794
- megota: 1,
1795
- repeat: MSI
1927
+ repeat: 10
1796
1928
  }, {
1797
1929
  arrow: 2,
1798
1930
  expans: 1,
1799
1931
  megota: 1,
1800
- repeat: MSI
1932
+ repeat: MSI - 1
1801
1933
  }],
1802
1934
  small: false,
1803
1935
  layer: 0,
1804
1936
  sign: 1
1805
1937
  });
1938
+ /**
1939
+ * Tritri, = 3↑↑↑3 = power tower with height 7625597484987 base 3.
1940
+ */
1806
1941
  PowiainaNum.TRITRI = new PowiainaNum({
1807
1942
  small: false,
1808
1943
  layer: 0,
1809
1944
  sign: 1,
1810
1945
  array: [newOperator(3638334640023.7783, 0, 1, 1), newOperator(7625587484984, 1, 1, 1)]
1811
1946
  });
1947
+ /**
1948
+ * The Graham's Number, = G^64(4)
1949
+ *
1950
+ * = 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{
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↑↑↑↑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
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
1954
+ */
1812
1955
  PowiainaNum.GRAHAMS_NUMBER = new PowiainaNum("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783");
1956
+ /**
1957
+ * Positive Infinity.
1958
+ */
1813
1959
  PowiainaNum.POSITIVE_INFINITY = new PowiainaNum(Infinity);
1960
+ /**
1961
+ * Negative Infinity.
1962
+ */
1814
1963
  PowiainaNum.NEGATIVE_INFINITY = new PowiainaNum(-Infinity);
1815
1964
  PowiainaNum.NaN = new PowiainaNum({
1816
1965
  array: [{
@@ -1823,6 +1972,40 @@ PowiainaNum.NaN = new PowiainaNum({
1823
1972
  layer: 0,
1824
1973
  sign: 0
1825
1974
  });
1975
+ /**
1976
+ * The mathematical constant e. This is Euler's number, the base of natural logarithms.
1977
+ */
1978
+ PowiainaNum.E = new PowiainaNum(Math.E);
1979
+ /**
1980
+ * The natural logarithm of 2 = ln(2).
1981
+ */
1982
+ PowiainaNum.LN2 = new PowiainaNum(Math.LN2);
1983
+ /**
1984
+ * The natural logarithm of 10.
1985
+ */
1986
+ PowiainaNum.LN10 = new PowiainaNum(Math.LN10);
1987
+ /**
1988
+ * The base-2 logarithm of e = log_2(e).
1989
+ */
1990
+ PowiainaNum.LOG2E = new PowiainaNum(Math.LOG2E);
1991
+ /**
1992
+ * The base-10 logarithm of e = log_10(e).
1993
+ */
1994
+ PowiainaNum.LOG10E = new PowiainaNum(Math.LOG10E);
1995
+ /**
1996
+ * Pi(). This is the ratio of the circumference of a circle to its diameter.
1997
+ */
1998
+ PowiainaNum.PI = new PowiainaNum(Math.PI);
1999
+ /**
2000
+ * The square root of 0.5, or, equivalently, one divided by the square root of 2.
2001
+ *
2002
+ * = (√2)/2 = √(0.5)
2003
+ */
2004
+ PowiainaNum.SQRT1_2 = new PowiainaNum(Math.SQRT1_2);
2005
+ /**
2006
+ * The square root of 2 = √2.
2007
+ */
2008
+ PowiainaNum.SQRT2 = new PowiainaNum(Math.SQRT2);
1826
2009
  PowiainaNum.maxOps = 100;
1827
2010
  PowiainaNum.arrowFuncMap = new Map();
1828
2011