mathjs 10.5.0 → 10.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. package/HISTORY.md +12 -0
  2. package/docs/datatypes/matrices.md +17 -0
  3. package/docs/expressions/syntax.md +4 -1
  4. package/docs/reference/functions/fix.md +1 -0
  5. package/docs/reference/functions/floor.md +4 -0
  6. package/docs/reference/functions/resolve.md +2 -2
  7. package/docs/reference/functions/simplifyConstant.md +52 -0
  8. package/lib/browser/math.js +5 -5
  9. package/lib/browser/math.js.map +1 -1
  10. package/lib/cjs/entry/dependenciesAny/dependenciesCeil.generated.js +6 -0
  11. package/lib/cjs/entry/dependenciesAny/dependenciesFix.generated.js +9 -0
  12. package/lib/cjs/entry/dependenciesAny/dependenciesFloor.generated.js +6 -0
  13. package/lib/cjs/entry/dependenciesAny/dependenciesIndexNode.generated.js +0 -3
  14. package/lib/cjs/entry/dependenciesNumber/dependenciesCeil.generated.js +3 -0
  15. package/lib/cjs/entry/dependenciesNumber/dependenciesFix.generated.js +6 -0
  16. package/lib/cjs/entry/dependenciesNumber/dependenciesFloor.generated.js +3 -0
  17. package/lib/cjs/entry/dependenciesNumber/dependenciesIndexNode.generated.js +0 -3
  18. package/lib/cjs/entry/impureFunctionsAny.generated.js +0 -1
  19. package/lib/cjs/entry/impureFunctionsNumber.generated.js +6 -7
  20. package/lib/cjs/entry/pureFunctionsAny.generated.js +10 -3
  21. package/lib/cjs/entry/pureFunctionsNumber.generated.js +21 -15
  22. package/lib/cjs/expression/node/IndexNode.js +26 -61
  23. package/lib/cjs/factoriesNumber.js +29 -24
  24. package/lib/cjs/function/algebra/resolve.js +3 -3
  25. package/lib/cjs/function/arithmetic/ceil.js +75 -39
  26. package/lib/cjs/function/arithmetic/fix.js +54 -16
  27. package/lib/cjs/function/arithmetic/floor.js +79 -37
  28. package/lib/cjs/function/arithmetic/nthRoot.js +1 -3
  29. package/lib/cjs/function/arithmetic/round.js +27 -47
  30. package/lib/cjs/header.js +2 -2
  31. package/lib/cjs/plain/number/arithmetic.js +9 -27
  32. package/lib/cjs/type/matrix/function/sparse.js +6 -0
  33. package/lib/cjs/utils/lruQueue.js +1 -3
  34. package/lib/cjs/utils/object.js +3 -1
  35. package/lib/cjs/version.js +1 -1
  36. package/lib/esm/entry/dependenciesAny/dependenciesCeil.generated.js +4 -0
  37. package/lib/esm/entry/dependenciesAny/dependenciesFix.generated.js +6 -0
  38. package/lib/esm/entry/dependenciesAny/dependenciesFloor.generated.js +4 -0
  39. package/lib/esm/entry/dependenciesAny/dependenciesIndexNode.generated.js +0 -2
  40. package/lib/esm/entry/dependenciesNumber/dependenciesCeil.generated.js +2 -0
  41. package/lib/esm/entry/dependenciesNumber/dependenciesFix.generated.js +4 -0
  42. package/lib/esm/entry/dependenciesNumber/dependenciesFloor.generated.js +2 -0
  43. package/lib/esm/entry/dependenciesNumber/dependenciesIndexNode.generated.js +0 -2
  44. package/lib/esm/entry/impureFunctionsAny.generated.js +0 -1
  45. package/lib/esm/entry/impureFunctionsNumber.generated.js +7 -8
  46. package/lib/esm/entry/pureFunctionsAny.generated.js +10 -3
  47. package/lib/esm/entry/pureFunctionsNumber.generated.js +16 -10
  48. package/lib/esm/expression/node/BlockNode.js +3 -3
  49. package/lib/esm/expression/node/IndexNode.js +22 -59
  50. package/lib/esm/expression/parse.js +5 -5
  51. package/lib/esm/factoriesNumber.js +6 -6
  52. package/lib/esm/function/algebra/decomposition/qr.js +2 -2
  53. package/lib/esm/function/algebra/resolve.js +3 -3
  54. package/lib/esm/function/algebra/solver/utils/solveValidation.js +5 -5
  55. package/lib/esm/function/algebra/sparse/csChol.js +2 -2
  56. package/lib/esm/function/algebra/sparse/csLeaf.js +2 -2
  57. package/lib/esm/function/algebra/sparse/csLu.js +3 -3
  58. package/lib/esm/function/arithmetic/ceil.js +61 -24
  59. package/lib/esm/function/arithmetic/fix.js +51 -13
  60. package/lib/esm/function/arithmetic/floor.js +65 -23
  61. package/lib/esm/function/arithmetic/nthRoot.js +1 -3
  62. package/lib/esm/function/arithmetic/nthRoots.js +1 -1
  63. package/lib/esm/function/arithmetic/round.js +25 -43
  64. package/lib/esm/function/matrix/expm.js +2 -2
  65. package/lib/esm/function/probability/gamma.js +1 -1
  66. package/lib/esm/function/string/bin.js +1 -1
  67. package/lib/esm/function/string/hex.js +1 -1
  68. package/lib/esm/function/string/oct.js +1 -1
  69. package/lib/esm/plain/number/arithmetic.js +9 -17
  70. package/lib/esm/type/complex/Complex.js +2 -2
  71. package/lib/esm/type/matrix/DenseMatrix.js +2 -2
  72. package/lib/esm/type/matrix/FibonacciHeap.js +2 -2
  73. package/lib/esm/type/matrix/SparseMatrix.js +13 -13
  74. package/lib/esm/type/matrix/function/sparse.js +6 -0
  75. package/lib/esm/type/unit/Unit.js +7 -7
  76. package/lib/esm/utils/lruQueue.js +1 -2
  77. package/lib/esm/utils/number.js +3 -3
  78. package/lib/esm/utils/object.js +3 -1
  79. package/lib/esm/version.js +1 -1
  80. package/package.json +14 -3
  81. package/types/index.d.ts +1794 -1372
  82. package/types/index.ts +697 -266
@@ -1,4 +1,4 @@
1
- import { absNumber, acoshNumber, acosNumber, acothNumber, acotNumber, acschNumber, acscNumber, addNumber, andNumber, asechNumber, asecNumber, asinhNumber, asinNumber, atan2Number, atanhNumber, atanNumber, bitAndNumber, bitNotNumber, bitOrNumber, bitXorNumber, cbrtNumber, ceilNumber, combinationsNumber, coshNumber, cosNumber, cothNumber, cotNumber, cschNumber, cscNumber, cubeNumber, divideNumber, expm1Number, expNumber, fixNumber, floorNumber, gammaNumber, gcdNumber, isIntegerNumber, isNaNNumber, isNegativeNumber, isPositiveNumber, isZeroNumber, lcmNumber, leftShiftNumber, lgammaNumber, log10Number, log1pNumber, log2Number, logNumber, modNumber, multiplyNumber, normNumber, notNumber, orNumber, powNumber, rightArithShiftNumber, rightLogShiftNumber, sechNumber, secNumber, signNumber, sinhNumber, sinNumber, sqrtNumber, squareNumber, subtractNumber, tanhNumber, tanNumber, unaryMinusNumber, unaryPlusNumber, xgcdNumber, xorNumber } from './plain/number/index.js';
1
+ import { absNumber, acoshNumber, acosNumber, acothNumber, acotNumber, acschNumber, acscNumber, addNumber, andNumber, asechNumber, asecNumber, asinhNumber, asinNumber, atan2Number, atanhNumber, atanNumber, bitAndNumber, bitNotNumber, bitOrNumber, bitXorNumber, cbrtNumber, combinationsNumber, coshNumber, cosNumber, cothNumber, cotNumber, cschNumber, cscNumber, cubeNumber, divideNumber, expm1Number, expNumber, gammaNumber, gcdNumber, isIntegerNumber, isNaNNumber, isNegativeNumber, isPositiveNumber, isZeroNumber, lcmNumber, leftShiftNumber, lgammaNumber, log10Number, log1pNumber, log2Number, logNumber, modNumber, multiplyNumber, normNumber, notNumber, nthRootNumber, orNumber, powNumber, rightArithShiftNumber, rightLogShiftNumber, roundNumber, sechNumber, secNumber, signNumber, sinhNumber, sinNumber, sqrtNumber, squareNumber, subtractNumber, tanhNumber, tanNumber, unaryMinusNumber, unaryPlusNumber, xgcdNumber, xorNumber } from './plain/number/index.js';
2
2
  import { factory } from './utils/factory.js';
3
3
  import { noIndex, noMatrix, noSubset } from './utils/noop.js'; // ----------------------------------------------------------------------------
4
4
  // classes and functions
@@ -24,12 +24,12 @@ export var createUnaryPlus = /* #__PURE__ */createNumberFactory('unaryPlus', una
24
24
  export var createAbs = /* #__PURE__ */createNumberFactory('abs', absNumber);
25
25
  export var createAddScalar = /* #__PURE__ */createNumberFactory('addScalar', addNumber);
26
26
  export var createCbrt = /* #__PURE__ */createNumberFactory('cbrt', cbrtNumber);
27
- export var createCeil = /* #__PURE__ */createNumberFactory('ceil', ceilNumber);
27
+ export { createCeilNumber as createCeil } from './function/arithmetic/ceil.js';
28
28
  export var createCube = /* #__PURE__ */createNumberFactory('cube', cubeNumber);
29
29
  export var createExp = /* #__PURE__ */createNumberFactory('exp', expNumber);
30
30
  export var createExpm1 = /* #__PURE__ */createNumberFactory('expm1', expm1Number);
31
- export var createFix = /* #__PURE__ */createNumberFactory('fix', fixNumber);
32
- export var createFloor = /* #__PURE__ */createNumberFactory('floor', floorNumber);
31
+ export { createFixNumber as createFix } from './function/arithmetic/fix.js';
32
+ export { createFloorNumber as createFloor } from './function/arithmetic/floor.js';
33
33
  export var createGcd = /* #__PURE__ */createNumberFactory('gcd', gcdNumber);
34
34
  export var createLcm = /* #__PURE__ */createNumberFactory('lcm', lcmNumber);
35
35
  export var createLog10 = /* #__PURE__ */createNumberFactory('log10', log10Number);
@@ -37,7 +37,7 @@ export var createLog2 = /* #__PURE__ */createNumberFactory('log2', log2Number);
37
37
  export var createMod = /* #__PURE__ */createNumberFactory('mod', modNumber);
38
38
  export var createMultiplyScalar = /* #__PURE__ */createNumberFactory('multiplyScalar', multiplyNumber);
39
39
  export var createMultiply = /* #__PURE__ */createNumberFactory('multiply', multiplyNumber);
40
- export { createNthRootNumber as createNthRoot } from './function/arithmetic/nthRoot.js';
40
+ export var createNthRoot = /* #__PURE__ */createNumberOptionalSecondArgFactory('nthRoot', nthRootNumber);
41
41
  export var createSign = /* #__PURE__ */createNumberFactory('sign', signNumber);
42
42
  export var createSqrt = /* #__PURE__ */createNumberFactory('sqrt', sqrtNumber);
43
43
  export var createSquare = /* #__PURE__ */createNumberFactory('square', squareNumber);
@@ -45,7 +45,7 @@ export var createSubtract = /* #__PURE__ */createNumberFactory('subtract', subtr
45
45
  export var createXgcd = /* #__PURE__ */createNumberFactory('xgcd', xgcdNumber);
46
46
  export var createDivideScalar = /* #__PURE__ */createNumberFactory('divideScalar', divideNumber);
47
47
  export var createPow = /* #__PURE__ */createNumberFactory('pow', powNumber);
48
- export { createRoundNumber as createRound } from './function/arithmetic/round.js';
48
+ export var createRound = /* #__PURE__ */createNumberOptionalSecondArgFactory('round', roundNumber);
49
49
  export var createLog = /* #__PURE__ */createNumberOptionalSecondArgFactory('log', logNumber);
50
50
  export var createLog1p = /* #__PURE__ */createNumberFactory('log1p', log1pNumber);
51
51
  export var createAdd = /* #__PURE__ */createNumberFactory('add', addNumber);
@@ -204,8 +204,8 @@ export var createQr = /* #__PURE__ */factory(name, dependencies, _ref => {
204
204
 
205
205
 
206
206
  return {
207
- Q: Q,
208
- R: R,
207
+ Q,
208
+ R,
209
209
  toString: function toString() {
210
210
  return 'Q: ' + this.Q.toString() + '\nR: ' + this.R.toString();
211
211
  }
@@ -29,11 +29,11 @@ export var createResolve = /* #__PURE__ */factory(name, dependencies, _ref => {
29
29
  *
30
30
  * simplify, evaluate
31
31
  *
32
- * @param {Node} node
33
- * The expression tree to be simplified
32
+ * @param {Node | Node[]} node
33
+ * The expression tree (or trees) to be simplified
34
34
  * @param {Object} scope
35
35
  * Scope specifying variables to be resolved
36
- * @return {Node} Returns `node` with variables recursively substituted.
36
+ * @return {Node | Node[]} Returns `node` with variables recursively substituted.
37
37
  * @throws {ReferenceError}
38
38
  * If there is a cyclic dependency among the variables in `scope`,
39
39
  * resolution is impossible and a ReferenceError is thrown.
@@ -45,7 +45,7 @@ export function createSolveValidation(_ref) {
45
45
  }
46
46
 
47
47
  return new DenseMatrix({
48
- data: data,
48
+ data,
49
49
  size: [rows, 1],
50
50
  datatype: b._datatype
51
51
  });
@@ -66,7 +66,7 @@ export function createSolveValidation(_ref) {
66
66
  }
67
67
 
68
68
  return new DenseMatrix({
69
- data: data,
69
+ data,
70
70
  size: [rows, 1],
71
71
  datatype: b._datatype
72
72
  });
@@ -90,7 +90,7 @@ export function createSolveValidation(_ref) {
90
90
  }
91
91
 
92
92
  return new DenseMatrix({
93
- data: data,
93
+ data,
94
94
  size: [rows, 1],
95
95
  datatype: b._datatype
96
96
  });
@@ -113,7 +113,7 @@ export function createSolveValidation(_ref) {
113
113
  }
114
114
 
115
115
  return new DenseMatrix({
116
- data: data,
116
+ data,
117
117
  size: [rows, 1]
118
118
  });
119
119
  }
@@ -128,7 +128,7 @@ export function createSolveValidation(_ref) {
128
128
  }
129
129
 
130
130
  return new DenseMatrix({
131
- data: data,
131
+ data,
132
132
  size: [rows, 1]
133
133
  });
134
134
  }
@@ -161,8 +161,8 @@ export var createCsChol = /* #__PURE__ */factory(name, dependencies, _ref => {
161
161
 
162
162
 
163
163
  return {
164
- L: L,
165
- P: P
164
+ L,
165
+ P
166
166
  };
167
167
  };
168
168
  });
@@ -50,7 +50,7 @@ export function csLeaf(i, j, w, first, maxfirst, prevleaf, ancestor) {
50
50
  }
51
51
 
52
52
  return {
53
- jleaf: jleaf,
54
- q: q
53
+ jleaf,
54
+ q
55
55
  };
56
56
  }
@@ -190,9 +190,9 @@ export var createCsLu = /* #__PURE__ */factory(name, dependencies, _ref => {
190
190
  uindex.splice(unz, uindex.length - unz); // return LU factor
191
191
 
192
192
  return {
193
- L: L,
194
- U: U,
195
- pinv: pinv
193
+ L,
194
+ U,
195
+ pinv
196
196
  };
197
197
  };
198
198
  });
@@ -3,26 +3,63 @@ import { factory } from '../../utils/factory.js';
3
3
  import { deepMap } from '../../utils/collection.js';
4
4
  import { nearlyEqual } from '../../utils/number.js';
5
5
  import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
6
- import { ceilNumber } from '../../plain/number/index.js';
7
6
  import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js';
7
+ import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
8
8
  import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
9
9
  var name = 'ceil';
10
- var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
11
- export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref => {
10
+ var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
11
+ export var createCeilNumber = /* #__PURE__ */factory(name, ['typed', 'config', 'round'], _ref => {
12
+ var {
13
+ typed,
14
+ config,
15
+ round
16
+ } = _ref;
17
+ return typed(name, {
18
+ number: function number(x) {
19
+ if (nearlyEqual(x, round(x), config.epsilon)) {
20
+ return round(x);
21
+ } else {
22
+ return Math.ceil(x);
23
+ }
24
+ },
25
+ 'number, number': function numberNumber(x, n) {
26
+ if (nearlyEqual(x, round(x, n), config.epsilon)) {
27
+ return round(x, n);
28
+ } else {
29
+ var [number, exponent] = "".concat(x, "e").split('e');
30
+ var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
31
+ [number, exponent] = "".concat(result, "e").split('e');
32
+ return Number("".concat(number, "e").concat(Number(exponent) - n));
33
+ }
34
+ }
35
+ });
36
+ });
37
+ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref2 => {
12
38
  var {
13
39
  typed,
14
40
  config,
15
41
  round,
16
42
  matrix,
17
- equalScalar
18
- } = _ref;
43
+ equalScalar,
44
+ zeros,
45
+ DenseMatrix
46
+ } = _ref2;
19
47
  var algorithm11 = createAlgorithm11({
20
48
  typed,
21
49
  equalScalar
22
50
  });
51
+ var algorithm12 = createAlgorithm12({
52
+ typed,
53
+ DenseMatrix
54
+ });
23
55
  var algorithm14 = createAlgorithm14({
24
56
  typed
25
57
  });
58
+ var ceilNumber = createCeilNumber({
59
+ typed,
60
+ config,
61
+ round
62
+ });
26
63
  /**
27
64
  * Round a value towards plus infinity
28
65
  * If `x` is complex, both real and imaginary part are rounded towards plus infinity.
@@ -62,29 +99,17 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref => {
62
99
  */
63
100
 
64
101
  return typed('ceil', {
65
- number: function number(x) {
66
- if (nearlyEqual(x, round(x), config.epsilon)) {
67
- return round(x);
68
- } else {
69
- return ceilNumber(x);
70
- }
71
- },
72
- 'number, number': function numberNumber(x, n) {
73
- if (nearlyEqual(x, round(x, n), config.epsilon)) {
74
- return round(x, n);
75
- } else {
76
- var [number, exponent] = "".concat(x, "e").split('e');
77
- var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
78
- [number, exponent] = "".concat(result, "e").split('e');
79
- return Number("".concat(number, "e").concat(Number(exponent) - n));
80
- }
81
- },
102
+ number: ceilNumber.signatures.number,
103
+ 'number,number': ceilNumber.signatures['number,number'],
82
104
  Complex: function Complex(x) {
83
105
  return x.ceil();
84
106
  },
85
107
  'Complex, number': function ComplexNumber(x, n) {
86
108
  return x.ceil(n);
87
109
  },
110
+ 'Complex, BigNumber': function ComplexBigNumber(x, n) {
111
+ return x.ceil(n.toNumber());
112
+ },
88
113
  BigNumber: function BigNumber(x) {
89
114
  if (bigNearlyEqual(x, round(x), config.epsilon)) {
90
115
  return round(x);
@@ -105,11 +130,14 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref => {
105
130
  'Fraction, number': function FractionNumber(x, n) {
106
131
  return x.ceil(n);
107
132
  },
133
+ 'Fraction, BigNumber': function FractionBigNumber(x, n) {
134
+ return x.ceil(n.toNumber());
135
+ },
108
136
  'Array | Matrix': function ArrayMatrix(x) {
109
137
  // deep map collection, skip zeros since ceil(0) = 0
110
138
  return deepMap(x, this, true);
111
139
  },
112
- 'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
140
+ 'Array, number | BigNumber': function ArrayNumberBigNumber(x, n) {
113
141
  // deep map collection, skip zeros since ceil(0) = 0
114
142
  return deepMap(x, i => this(i, n), true);
115
143
  },
@@ -119,9 +147,18 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref => {
119
147
  'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
120
148
  return algorithm14(x, y, this, false);
121
149
  },
122
- 'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
150
+ 'number | Complex | Fraction | BigNumber, Array': function numberComplexFractionBigNumberArray(x, y) {
123
151
  // use matrix implementation
124
152
  return algorithm14(matrix(y), x, this, true).valueOf();
153
+ },
154
+ 'number | Complex | Fraction | BigNumber, Matrix': function numberComplexFractionBigNumberMatrix(x, y) {
155
+ if (equalScalar(x, 0)) return zeros(y.size(), y.storage());
156
+
157
+ if (y.storage() === 'dense') {
158
+ return algorithm14(y, x, this, true);
159
+ }
160
+
161
+ return algorithm12(y, x, this, true);
125
162
  }
126
163
  });
127
164
  });
@@ -1,19 +1,47 @@
1
1
  import { factory } from '../../utils/factory.js';
2
2
  import { deepMap } from '../../utils/collection.js';
3
+ import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
3
4
  import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
4
5
  var name = 'fix';
5
- var dependencies = ['typed', 'Complex', 'matrix', 'ceil', 'floor'];
6
- export var createFix = /* #__PURE__ */factory(name, dependencies, _ref => {
6
+ var dependencies = ['typed', 'Complex', 'matrix', 'ceil', 'floor', 'equalScalar', 'zeros', 'DenseMatrix'];
7
+ export var createFixNumber = /* #__PURE__ */factory(name, ['typed', 'ceil', 'floor'], _ref => {
7
8
  var {
8
9
  typed,
9
- Complex: _Complex,
10
- matrix,
11
10
  ceil,
12
11
  floor
13
12
  } = _ref;
13
+ return typed(name, {
14
+ number: function number(x) {
15
+ return x > 0 ? floor(x) : ceil(x);
16
+ },
17
+ 'number, number': function numberNumber(x, n) {
18
+ return x > 0 ? floor(x, n) : ceil(x, n);
19
+ }
20
+ });
21
+ });
22
+ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref2 => {
23
+ var {
24
+ typed,
25
+ Complex: _Complex,
26
+ matrix,
27
+ ceil,
28
+ floor,
29
+ equalScalar,
30
+ zeros,
31
+ DenseMatrix
32
+ } = _ref2;
33
+ var algorithm12 = createAlgorithm12({
34
+ typed,
35
+ DenseMatrix
36
+ });
14
37
  var algorithm14 = createAlgorithm14({
15
38
  typed
16
39
  });
40
+ var fixNumber = createFixNumber({
41
+ typed,
42
+ ceil,
43
+ floor
44
+ });
17
45
  /**
18
46
  * Round a value towards zero.
19
47
  * For matrices, the function is evaluated element wise.
@@ -21,6 +49,7 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref => {
21
49
  * Syntax:
22
50
  *
23
51
  * math.fix(x)
52
+ * math.fix(x,n)
24
53
  *
25
54
  * Examples:
26
55
  *
@@ -51,16 +80,16 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref => {
51
80
  */
52
81
 
53
82
  return typed('fix', {
54
- number: function number(x) {
55
- return x > 0 ? floor(x) : ceil(x);
56
- },
57
- 'number, number | BigNumber': function numberNumberBigNumber(x, n) {
58
- return x > 0 ? floor(x, n) : ceil(x, n);
59
- },
83
+ number: fixNumber.signatures.number,
84
+ 'number, number | BigNumber': fixNumber.signatures['number,number'],
60
85
  Complex: function Complex(x) {
61
86
  return new _Complex(x.re > 0 ? Math.floor(x.re) : Math.ceil(x.re), x.im > 0 ? Math.floor(x.im) : Math.ceil(x.im));
62
87
  },
63
- 'Complex, number | BigNumber': function ComplexNumberBigNumber(x, n) {
88
+ 'Complex, number': function ComplexNumber(x, n) {
89
+ return new _Complex(x.re > 0 ? floor(x.re, n) : ceil(x.re, n), x.im > 0 ? floor(x.im, n) : ceil(x.im, n));
90
+ },
91
+ 'Complex, BigNumber': function ComplexBigNumber(x, bn) {
92
+ var n = bn.toNumber();
64
93
  return new _Complex(x.re > 0 ? floor(x.re, n) : ceil(x.re, n), x.im > 0 ? floor(x.im, n) : ceil(x.im, n));
65
94
  },
66
95
  BigNumber: function BigNumber(x) {
@@ -73,7 +102,7 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref => {
73
102
  return x.s < 0 ? x.ceil() : x.floor();
74
103
  },
75
104
  'Fraction, number | BigNumber': function FractionNumberBigNumber(x, n) {
76
- return x.s < 0 ? x.ceil(n) : x.floor(n);
105
+ return x.s < 0 ? ceil(x, n) : floor(x, n);
77
106
  },
78
107
  'Array | Matrix': function ArrayMatrix(x) {
79
108
  // deep map collection, skip zeros since fix(0) = 0
@@ -83,9 +112,18 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref => {
83
112
  // deep map collection, skip zeros since fix(0) = 0
84
113
  return deepMap(x, i => this(i, n), true);
85
114
  },
86
- 'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
115
+ 'number | Complex | Fraction | BigNumber, Array': function numberComplexFractionBigNumberArray(x, y) {
87
116
  // use matrix implementation
88
117
  return algorithm14(matrix(y), x, this, true).valueOf();
118
+ },
119
+ 'number | Complex | Fraction | BigNumber, Matrix': function numberComplexFractionBigNumberMatrix(x, y) {
120
+ if (equalScalar(x, 0)) return zeros(y.size(), y.storage());
121
+
122
+ if (y.storage() === 'dense') {
123
+ return algorithm14(y, x, this, true);
124
+ }
125
+
126
+ return algorithm12(y, x, this, true);
89
127
  }
90
128
  });
91
129
  });
@@ -4,24 +4,62 @@ import { deepMap } from '../../utils/collection.js';
4
4
  import { nearlyEqual } from '../../utils/number.js';
5
5
  import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
6
6
  import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js';
7
+ import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
7
8
  import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
8
9
  var name = 'floor';
9
- var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
10
- export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref => {
10
+ var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
11
+ export var createFloorNumber = /* #__PURE__ */factory(name, ['typed', 'config', 'round'], _ref => {
12
+ var {
13
+ typed,
14
+ config,
15
+ round
16
+ } = _ref;
17
+ return typed(name, {
18
+ number: function number(x) {
19
+ if (nearlyEqual(x, round(x), config.epsilon)) {
20
+ return round(x);
21
+ } else {
22
+ return Math.floor(x);
23
+ }
24
+ },
25
+ 'number, number': function numberNumber(x, n) {
26
+ if (nearlyEqual(x, round(x, n), config.epsilon)) {
27
+ return round(x, n);
28
+ } else {
29
+ var [number, exponent] = "".concat(x, "e").split('e');
30
+ var result = Math.floor(Number("".concat(number, "e").concat(Number(exponent) + n)));
31
+ [number, exponent] = "".concat(result, "e").split('e');
32
+ return Number("".concat(number, "e").concat(Number(exponent) - n));
33
+ }
34
+ }
35
+ });
36
+ });
37
+ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref2 => {
11
38
  var {
12
39
  typed,
13
40
  config,
14
41
  round,
15
42
  matrix,
16
- equalScalar
17
- } = _ref;
43
+ equalScalar,
44
+ zeros,
45
+ DenseMatrix
46
+ } = _ref2;
18
47
  var algorithm11 = createAlgorithm11({
19
48
  typed,
20
49
  equalScalar
21
50
  });
51
+ var algorithm12 = createAlgorithm12({
52
+ typed,
53
+ DenseMatrix
54
+ });
22
55
  var algorithm14 = createAlgorithm14({
23
56
  typed
24
57
  });
58
+ var floorNumber = createFloorNumber({
59
+ typed,
60
+ config,
61
+ round
62
+ });
25
63
  /**
26
64
  * Round a value towards minus infinity.
27
65
  * For matrices, the function is evaluated element wise.
@@ -50,6 +88,10 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref => {
50
88
  * math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
51
89
  * math.floor([3.21, 3.82, -4.71], 1) // returns Array [3.2, 3.8, -4.8]
52
90
  *
91
+ * math.floor(math.tau, [2, 3]) // returns Array [6.28, 6.283]
92
+ *
93
+ * // Note that floor(array, array) currently not implemented.
94
+ *
53
95
  * See also:
54
96
  *
55
97
  * ceil, fix, round
@@ -60,29 +102,17 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref => {
60
102
  */
61
103
 
62
104
  return typed('floor', {
63
- number: function number(x) {
64
- if (nearlyEqual(x, round(x), config.epsilon)) {
65
- return round(x);
66
- } else {
67
- return Math.floor(x);
68
- }
69
- },
70
- 'number, number': function numberNumber(x, n) {
71
- if (nearlyEqual(x, round(x, n), config.epsilon)) {
72
- return round(x, n);
73
- } else {
74
- var [number, exponent] = "".concat(x, "e").split('e');
75
- var result = Math.floor(Number("".concat(number, "e").concat(Number(exponent) + n)));
76
- [number, exponent] = "".concat(result, "e").split('e');
77
- return Number("".concat(number, "e").concat(Number(exponent) - n));
78
- }
79
- },
105
+ number: floorNumber.signatures.number,
106
+ 'number,number': floorNumber.signatures['number,number'],
80
107
  Complex: function Complex(x) {
81
108
  return x.floor();
82
109
  },
83
110
  'Complex, number': function ComplexNumber(x, n) {
84
111
  return x.floor(n);
85
112
  },
113
+ 'Complex, BigNumber': function ComplexBigNumber(x, n) {
114
+ return x.floor(n.toNumber());
115
+ },
86
116
  BigNumber: function BigNumber(x) {
87
117
  if (bigNearlyEqual(x, round(x), config.epsilon)) {
88
118
  return round(x);
@@ -103,11 +133,14 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref => {
103
133
  'Fraction, number': function FractionNumber(x, n) {
104
134
  return x.floor(n);
105
135
  },
136
+ 'Fraction, BigNumber': function FractionBigNumber(x, n) {
137
+ return x.floor(n.toNumber());
138
+ },
106
139
  'Array | Matrix': function ArrayMatrix(x) {
107
140
  // deep map collection, skip zeros since floor(0) = 0
108
141
  return deepMap(x, this, true);
109
142
  },
110
- 'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
143
+ 'Array, number | BigNumber': function ArrayNumberBigNumber(x, n) {
111
144
  // deep map collection, skip zeros since ceil(0) = 0
112
145
  return deepMap(x, i => this(i, n), true);
113
146
  },
@@ -117,9 +150,18 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref => {
117
150
  'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
118
151
  return algorithm14(x, y, this, false);
119
152
  },
120
- 'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
153
+ 'number | Complex | Fraction | BigNumber, Array': function numberComplexFractionBigNumberArray(x, y) {
121
154
  // use matrix implementation
122
155
  return algorithm14(matrix(y), x, this, true).valueOf();
156
+ },
157
+ 'number | Complex | Fraction | BigNumber, Matrix': function numberComplexFractionBigNumberMatrix(x, y) {
158
+ if (equalScalar(x, 0)) return zeros(y.size(), y.storage());
159
+
160
+ if (y.storage() === 'dense') {
161
+ return algorithm14(y, x, this, true);
162
+ }
163
+
164
+ return algorithm12(y, x, this, true);
123
165
  }
124
166
  });
125
167
  });
@@ -68,9 +68,7 @@ export var createNthRoot = /* #__PURE__ */factory(name, dependencies, _ref => {
68
68
 
69
69
  var complexErr = '' + 'Complex number not supported in function nthRoot. ' + 'Use nthRoots instead.';
70
70
  return typed(name, {
71
- number: function number(x) {
72
- return nthRootNumber(x, 2);
73
- },
71
+ number: nthRootNumber,
74
72
  'number, number': nthRootNumber,
75
73
  BigNumber: function BigNumber(x) {
76
74
  return _bigNthRoot(x, new _BigNumber(2));
@@ -67,7 +67,7 @@ export var createNthRoots = /* #__PURE__ */factory(name, dependencies, _ref => {
67
67
  }
68
68
 
69
69
  roots.push(new Complex({
70
- r: r,
70
+ r,
71
71
  phi: (arg + 2 * Math.PI * k) / root
72
72
  }));
73
73
  }