mathjs 10.6.4 → 11.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. package/HISTORY.md +79 -1
  2. package/README.md +1 -1
  3. package/lib/browser/math.js +2 -41
  4. package/lib/browser/math.js.LICENSE.txt +43 -0
  5. package/lib/browser/math.js.map +1 -1
  6. package/lib/cjs/core/create.js +6 -5
  7. package/lib/cjs/core/function/import.js +4 -14
  8. package/lib/cjs/core/function/typed.js +54 -12
  9. package/lib/cjs/defaultInstance.js +3 -3
  10. package/lib/cjs/entry/allFactoriesAny.js +1 -1
  11. package/lib/cjs/entry/allFactoriesNumber.js +1 -1
  12. package/lib/cjs/entry/configReadonly.js +1 -1
  13. package/lib/cjs/entry/dependenciesAny/dependenciesChainClass.generated.js +3 -0
  14. package/lib/cjs/entry/dependenciesAny/dependenciesKldivergence.generated.js +3 -0
  15. package/lib/cjs/entry/dependenciesAny/dependenciesRationalize.generated.js +3 -0
  16. package/lib/cjs/entry/dependenciesAny/dependenciesResolve.generated.js +3 -0
  17. package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +3 -0
  18. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +56 -0
  19. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +6 -0
  20. package/lib/cjs/entry/dependenciesAny/dependenciesSqrtm.generated.js +3 -0
  21. package/lib/cjs/entry/dependenciesAny/dependenciesStd.generated.js +3 -0
  22. package/lib/cjs/entry/dependenciesAny/dependenciesStdTransform.generated.js +3 -0
  23. package/lib/cjs/entry/dependenciesAny.generated.js +8 -0
  24. package/lib/cjs/entry/dependenciesNumber/dependenciesChainClass.generated.js +3 -0
  25. package/lib/cjs/entry/dependenciesNumber/dependenciesRationalize.generated.js +3 -0
  26. package/lib/cjs/entry/dependenciesNumber/dependenciesResolve.generated.js +3 -0
  27. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +3 -0
  28. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +50 -0
  29. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +6 -0
  30. package/lib/cjs/entry/dependenciesNumber/dependenciesStd.generated.js +3 -0
  31. package/lib/cjs/entry/dependenciesNumber/dependenciesStdTransform.generated.js +3 -0
  32. package/lib/cjs/entry/dependenciesNumber.generated.js +8 -0
  33. package/lib/cjs/entry/impureFunctionsAny.generated.js +87 -61
  34. package/lib/cjs/entry/impureFunctionsNumber.generated.js +93 -69
  35. package/lib/cjs/entry/pureFunctionsAny.generated.js +50 -45
  36. package/lib/cjs/entry/pureFunctionsNumber.generated.js +22 -19
  37. package/lib/cjs/expression/Parser.js +1 -1
  38. package/lib/cjs/expression/embeddedDocs/construction/index.js +1 -1
  39. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -5
  40. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyConstant.js +15 -0
  41. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  42. package/lib/cjs/expression/node/AccessorNode.js +216 -173
  43. package/lib/cjs/expression/node/ArrayNode.js +206 -160
  44. package/lib/cjs/expression/node/AssignmentNode.js +321 -270
  45. package/lib/cjs/expression/node/BlockNode.js +223 -172
  46. package/lib/cjs/expression/node/ConditionalNode.js +253 -193
  47. package/lib/cjs/expression/node/ConstantNode.js +216 -171
  48. package/lib/cjs/expression/node/FunctionAssignmentNode.js +258 -196
  49. package/lib/cjs/expression/node/FunctionNode.js +456 -416
  50. package/lib/cjs/expression/node/IndexNode.js +256 -210
  51. package/lib/cjs/expression/node/Node.js +411 -378
  52. package/lib/cjs/expression/node/ObjectNode.js +223 -178
  53. package/lib/cjs/expression/node/OperatorNode.js +474 -397
  54. package/lib/cjs/expression/node/ParenthesisNode.js +189 -143
  55. package/lib/cjs/expression/node/RangeNode.js +272 -224
  56. package/lib/cjs/expression/node/RelationalNode.js +246 -195
  57. package/lib/cjs/expression/node/SymbolNode.js +219 -172
  58. package/lib/cjs/expression/node/utils/access.js +1 -1
  59. package/lib/cjs/expression/node/utils/assign.js +1 -1
  60. package/lib/cjs/expression/operators.js +117 -23
  61. package/lib/cjs/expression/parse.js +37 -19
  62. package/lib/cjs/expression/transform/std.transform.js +3 -1
  63. package/lib/cjs/factoriesAny.js +8 -0
  64. package/lib/cjs/factoriesNumber.js +10 -1
  65. package/lib/cjs/function/algebra/decomposition/qr.js +1 -1
  66. package/lib/cjs/function/algebra/derivative.js +25 -33
  67. package/lib/cjs/function/algebra/leafCount.js +0 -3
  68. package/lib/cjs/function/algebra/rationalize.js +78 -108
  69. package/lib/cjs/function/algebra/resolve.js +53 -16
  70. package/lib/cjs/function/algebra/simplify/util.js +1 -1
  71. package/lib/cjs/function/algebra/simplify.js +90 -115
  72. package/lib/cjs/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +44 -10
  73. package/lib/cjs/function/algebra/simplifyCore.js +196 -93
  74. package/lib/cjs/function/algebra/solver/lsolveAll.js +2 -2
  75. package/lib/cjs/function/algebra/solver/usolveAll.js +2 -2
  76. package/lib/cjs/function/algebra/symbolicEqual.js +14 -32
  77. package/lib/cjs/function/arithmetic/abs.js +7 -14
  78. package/lib/cjs/function/arithmetic/add.js +26 -70
  79. package/lib/cjs/function/arithmetic/addScalar.js +17 -9
  80. package/lib/cjs/function/arithmetic/cbrt.js +7 -11
  81. package/lib/cjs/function/arithmetic/ceil.js +50 -40
  82. package/lib/cjs/function/arithmetic/cube.js +5 -10
  83. package/lib/cjs/function/arithmetic/divide.js +7 -7
  84. package/lib/cjs/function/arithmetic/divideScalar.js +4 -18
  85. package/lib/cjs/function/arithmetic/dotDivide.js +22 -65
  86. package/lib/cjs/function/arithmetic/dotMultiply.js +16 -61
  87. package/lib/cjs/function/arithmetic/dotPow.js +30 -63
  88. package/lib/cjs/function/arithmetic/exp.js +8 -12
  89. package/lib/cjs/function/arithmetic/expm1.js +10 -10
  90. package/lib/cjs/function/arithmetic/fix.js +34 -28
  91. package/lib/cjs/function/arithmetic/floor.js +51 -41
  92. package/lib/cjs/function/arithmetic/gcd.js +27 -68
  93. package/lib/cjs/function/arithmetic/hypot.js +9 -5
  94. package/lib/cjs/function/arithmetic/invmod.js +2 -2
  95. package/lib/cjs/function/arithmetic/lcm.js +27 -68
  96. package/lib/cjs/function/arithmetic/log.js +10 -12
  97. package/lib/cjs/function/arithmetic/log10.js +5 -3
  98. package/lib/cjs/function/arithmetic/log1p.js +11 -7
  99. package/lib/cjs/function/arithmetic/log2.js +5 -3
  100. package/lib/cjs/function/arithmetic/mod.js +22 -64
  101. package/lib/cjs/function/arithmetic/multiply.js +40 -35
  102. package/lib/cjs/function/arithmetic/multiplyScalar.js +2 -9
  103. package/lib/cjs/function/arithmetic/norm.js +1 -5
  104. package/lib/cjs/function/arithmetic/nthRoot.js +83 -95
  105. package/lib/cjs/function/arithmetic/nthRoots.js +2 -2
  106. package/lib/cjs/function/arithmetic/round.js +56 -42
  107. package/lib/cjs/function/arithmetic/sign.js +14 -10
  108. package/lib/cjs/function/arithmetic/sqrt.js +5 -9
  109. package/lib/cjs/function/arithmetic/square.js +6 -10
  110. package/lib/cjs/function/arithmetic/subtract.js +44 -100
  111. package/lib/cjs/function/arithmetic/unaryMinus.js +14 -16
  112. package/lib/cjs/function/arithmetic/unaryPlus.js +6 -4
  113. package/lib/cjs/function/bitwise/bitAnd.js +17 -61
  114. package/lib/cjs/function/bitwise/bitNot.js +6 -4
  115. package/lib/cjs/function/bitwise/bitOr.js +16 -60
  116. package/lib/cjs/function/bitwise/bitXor.js +17 -61
  117. package/lib/cjs/function/bitwise/leftShift.js +69 -82
  118. package/lib/cjs/function/bitwise/rightArithShift.js +69 -82
  119. package/lib/cjs/function/bitwise/rightLogShift.js +69 -82
  120. package/lib/cjs/function/bitwise/useMatrixForArrayScalar.js +36 -0
  121. package/lib/cjs/function/complex/arg.js +5 -3
  122. package/lib/cjs/function/complex/conj.js +6 -7
  123. package/lib/cjs/function/complex/im.js +7 -8
  124. package/lib/cjs/function/complex/re.js +6 -10
  125. package/lib/cjs/function/geometry/distance.js +2 -2
  126. package/lib/cjs/function/logical/and.js +74 -80
  127. package/lib/cjs/function/logical/not.js +13 -6
  128. package/lib/cjs/function/logical/or.js +21 -63
  129. package/lib/cjs/function/logical/xor.js +21 -63
  130. package/lib/cjs/function/matrix/diff.js +11 -8
  131. package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
  132. package/lib/cjs/function/matrix/fft.js +2 -2
  133. package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
  134. package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
  135. package/lib/cjs/function/matrix/ones.js +2 -1
  136. package/lib/cjs/function/matrix/rotate.js +5 -5
  137. package/lib/cjs/function/matrix/sqrtm.js +3 -2
  138. package/lib/cjs/function/matrix/transpose.js +47 -48
  139. package/lib/cjs/function/matrix/zeros.js +2 -1
  140. package/lib/cjs/function/probability/factorial.js +5 -3
  141. package/lib/cjs/function/probability/gamma.js +38 -40
  142. package/lib/cjs/function/probability/kldivergence.js +5 -2
  143. package/lib/cjs/function/probability/lgamma.js +30 -30
  144. package/lib/cjs/function/probability/util/seededRNG.js +2 -2
  145. package/lib/cjs/function/relational/compare.js +21 -67
  146. package/lib/cjs/function/relational/compareNatural.js +59 -54
  147. package/lib/cjs/function/relational/compareText.js +10 -43
  148. package/lib/cjs/function/relational/compareUnits.js +24 -0
  149. package/lib/cjs/function/relational/equal.js +19 -80
  150. package/lib/cjs/function/relational/equalScalar.js +7 -9
  151. package/lib/cjs/function/relational/larger.js +21 -67
  152. package/lib/cjs/function/relational/largerEq.js +21 -67
  153. package/lib/cjs/function/relational/smaller.js +21 -67
  154. package/lib/cjs/function/relational/smallerEq.js +21 -67
  155. package/lib/cjs/function/relational/unequal.js +19 -80
  156. package/lib/cjs/function/special/erf.js +5 -3
  157. package/lib/cjs/function/statistics/std.js +11 -2
  158. package/lib/cjs/function/string/format.js +2 -2
  159. package/lib/cjs/function/string/hex.js +1 -2
  160. package/lib/cjs/function/trigonometry/acos.js +4 -8
  161. package/lib/cjs/function/trigonometry/acosh.js +2 -7
  162. package/lib/cjs/function/trigonometry/acot.js +6 -11
  163. package/lib/cjs/function/trigonometry/acoth.js +4 -8
  164. package/lib/cjs/function/trigonometry/acsc.js +6 -11
  165. package/lib/cjs/function/trigonometry/acsch.js +4 -8
  166. package/lib/cjs/function/trigonometry/asec.js +6 -10
  167. package/lib/cjs/function/trigonometry/asech.js +4 -8
  168. package/lib/cjs/function/trigonometry/asin.js +5 -10
  169. package/lib/cjs/function/trigonometry/asinh.js +4 -9
  170. package/lib/cjs/function/trigonometry/atan.js +5 -11
  171. package/lib/cjs/function/trigonometry/atan2.js +25 -63
  172. package/lib/cjs/function/trigonometry/atanh.js +4 -9
  173. package/lib/cjs/function/trigonometry/cos.js +11 -20
  174. package/lib/cjs/function/trigonometry/cosh.js +5 -19
  175. package/lib/cjs/function/trigonometry/cot.js +9 -15
  176. package/lib/cjs/function/trigonometry/coth.js +4 -15
  177. package/lib/cjs/function/trigonometry/csc.js +11 -17
  178. package/lib/cjs/function/trigonometry/csch.js +4 -15
  179. package/lib/cjs/function/trigonometry/sec.js +11 -17
  180. package/lib/cjs/function/trigonometry/sech.js +4 -15
  181. package/lib/cjs/function/trigonometry/sin.js +11 -21
  182. package/lib/cjs/function/trigonometry/sinh.js +5 -20
  183. package/lib/cjs/function/trigonometry/tan.js +11 -21
  184. package/lib/cjs/function/trigonometry/tanh.js +5 -20
  185. package/lib/cjs/function/trigonometry/trigUnit.js +24 -0
  186. package/lib/cjs/function/unit/to.js +7 -41
  187. package/lib/cjs/function/utils/clone.js +1 -1
  188. package/lib/cjs/function/utils/hasNumericValue.js +5 -1
  189. package/lib/cjs/function/utils/isInteger.js +6 -4
  190. package/lib/cjs/function/utils/isNaN.js +1 -1
  191. package/lib/cjs/function/utils/isNegative.js +11 -7
  192. package/lib/cjs/function/utils/isNumeric.js +6 -4
  193. package/lib/cjs/function/utils/isPositive.js +11 -7
  194. package/lib/cjs/function/utils/isPrime.js +5 -3
  195. package/lib/cjs/function/utils/isZero.js +21 -17
  196. package/lib/cjs/function/utils/numeric.js +11 -4
  197. package/lib/cjs/function/utils/typeOf.js +38 -44
  198. package/lib/cjs/header.js +2 -2
  199. package/lib/cjs/plain/bignumber/index.js +1 -1
  200. package/lib/cjs/type/bignumber/BigNumber.js +2 -2
  201. package/lib/cjs/type/bignumber/function/bignumber.js +6 -4
  202. package/lib/cjs/type/boolean.js +7 -5
  203. package/lib/cjs/type/chain/Chain.js +23 -3
  204. package/lib/cjs/type/complex/Complex.js +18 -14
  205. package/lib/cjs/type/complex/function/complex.js +6 -4
  206. package/lib/cjs/type/fraction/Fraction.js +10 -6
  207. package/lib/cjs/type/fraction/function/fraction.js +6 -4
  208. package/lib/cjs/type/matrix/DenseMatrix.js +21 -6
  209. package/lib/cjs/type/matrix/SparseMatrix.js +12 -2
  210. package/lib/cjs/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +4 -4
  211. package/lib/cjs/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +5 -5
  212. package/lib/cjs/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +5 -5
  213. package/lib/cjs/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +7 -7
  214. package/lib/cjs/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +5 -5
  215. package/lib/cjs/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +5 -5
  216. package/lib/cjs/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +5 -5
  217. package/lib/cjs/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +6 -6
  218. package/lib/cjs/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +5 -5
  219. package/lib/cjs/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +5 -5
  220. package/lib/cjs/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +5 -5
  221. package/lib/cjs/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +5 -5
  222. package/lib/cjs/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +5 -5
  223. package/lib/cjs/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +5 -5
  224. package/lib/cjs/type/matrix/utils/matrixAlgorithmSuite.js +238 -0
  225. package/lib/cjs/type/number.js +6 -4
  226. package/lib/cjs/type/string.js +7 -5
  227. package/lib/cjs/type/unit/Unit.js +98 -45
  228. package/lib/cjs/type/unit/function/createUnit.js +2 -1
  229. package/lib/cjs/type/unit/function/unit.js +14 -5
  230. package/lib/cjs/utils/customs.js +2 -2
  231. package/lib/cjs/utils/emitter.js +1 -1
  232. package/lib/cjs/utils/function.js +2 -2
  233. package/lib/cjs/utils/is.js +27 -25
  234. package/lib/cjs/utils/latex.js +3 -3
  235. package/lib/cjs/utils/lruQueue.js +1 -1
  236. package/lib/cjs/utils/map.js +3 -3
  237. package/lib/cjs/utils/object.js +2 -2
  238. package/lib/cjs/utils/snapshot.js +30 -57
  239. package/lib/cjs/utils/string.js +3 -3
  240. package/lib/cjs/version.js +1 -1
  241. package/lib/esm/core/create.js +2 -1
  242. package/lib/esm/core/function/import.js +2 -12
  243. package/lib/esm/core/function/typed.js +47 -11
  244. package/lib/esm/entry/dependenciesAny/dependenciesChainClass.generated.js +2 -0
  245. package/lib/esm/entry/dependenciesAny/dependenciesKldivergence.generated.js +2 -0
  246. package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
  247. package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +2 -0
  248. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  249. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +34 -0
  250. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +4 -0
  251. package/lib/esm/entry/dependenciesAny/dependenciesSqrtm.generated.js +2 -0
  252. package/lib/esm/entry/dependenciesAny/dependenciesStd.generated.js +2 -0
  253. package/lib/esm/entry/dependenciesAny/dependenciesStdTransform.generated.js +2 -0
  254. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  255. package/lib/esm/entry/dependenciesNumber/dependenciesChainClass.generated.js +2 -0
  256. package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
  257. package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +2 -0
  258. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  259. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +30 -0
  260. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +4 -0
  261. package/lib/esm/entry/dependenciesNumber/dependenciesStd.generated.js +2 -0
  262. package/lib/esm/entry/dependenciesNumber/dependenciesStdTransform.generated.js +2 -0
  263. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  264. package/lib/esm/entry/impureFunctionsAny.generated.js +73 -48
  265. package/lib/esm/entry/impureFunctionsNumber.generated.js +81 -58
  266. package/lib/esm/entry/pureFunctionsAny.generated.js +39 -36
  267. package/lib/esm/entry/pureFunctionsNumber.generated.js +14 -13
  268. package/lib/esm/expression/embeddedDocs/construction/index.js +1 -1
  269. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  270. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyConstant.js +8 -0
  271. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  272. package/lib/esm/expression/node/AccessorNode.js +158 -153
  273. package/lib/esm/expression/node/ArrayNode.js +162 -154
  274. package/lib/esm/expression/node/AssignmentNode.js +257 -245
  275. package/lib/esm/expression/node/BlockNode.js +177 -163
  276. package/lib/esm/expression/node/ConditionalNode.js +197 -174
  277. package/lib/esm/expression/node/ConstantNode.js +171 -163
  278. package/lib/esm/expression/node/FunctionAssignmentNode.js +205 -180
  279. package/lib/esm/expression/node/FunctionNode.js +407 -407
  280. package/lib/esm/expression/node/IndexNode.js +206 -198
  281. package/lib/esm/expression/node/Node.js +325 -325
  282. package/lib/esm/expression/node/ObjectNode.js +166 -157
  283. package/lib/esm/expression/node/OperatorNode.js +414 -377
  284. package/lib/esm/expression/node/ParenthesisNode.js +146 -138
  285. package/lib/esm/expression/node/RangeNode.js +221 -212
  286. package/lib/esm/expression/node/RelationalNode.js +190 -176
  287. package/lib/esm/expression/node/SymbolNode.js +161 -152
  288. package/lib/esm/expression/operators.js +96 -4
  289. package/lib/esm/expression/parse.js +25 -7
  290. package/lib/esm/expression/transform/std.transform.js +3 -1
  291. package/lib/esm/factoriesAny.js +1 -0
  292. package/lib/esm/factoriesNumber.js +1 -0
  293. package/lib/esm/function/algebra/derivative.js +25 -33
  294. package/lib/esm/function/algebra/leafCount.js +0 -3
  295. package/lib/esm/function/algebra/rationalize.js +83 -114
  296. package/lib/esm/function/algebra/resolve.js +25 -16
  297. package/lib/esm/function/algebra/simplify.js +85 -113
  298. package/lib/esm/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +39 -9
  299. package/lib/esm/function/algebra/simplifyCore.js +192 -91
  300. package/lib/esm/function/algebra/symbolicEqual.js +14 -32
  301. package/lib/esm/function/arithmetic/abs.js +3 -16
  302. package/lib/esm/function/arithmetic/add.js +21 -65
  303. package/lib/esm/function/arithmetic/addScalar.js +11 -5
  304. package/lib/esm/function/arithmetic/cbrt.js +7 -10
  305. package/lib/esm/function/arithmetic/ceil.js +25 -25
  306. package/lib/esm/function/arithmetic/cube.js +5 -9
  307. package/lib/esm/function/arithmetic/divide.js +7 -7
  308. package/lib/esm/function/arithmetic/divideScalar.js +2 -19
  309. package/lib/esm/function/arithmetic/dotDivide.js +22 -64
  310. package/lib/esm/function/arithmetic/dotMultiply.js +16 -60
  311. package/lib/esm/function/arithmetic/dotPow.js +30 -62
  312. package/lib/esm/function/arithmetic/exp.js +8 -11
  313. package/lib/esm/function/arithmetic/expm1.js +10 -9
  314. package/lib/esm/function/arithmetic/fix.js +18 -18
  315. package/lib/esm/function/arithmetic/floor.js +26 -26
  316. package/lib/esm/function/arithmetic/gcd.js +26 -70
  317. package/lib/esm/function/arithmetic/hypot.js +7 -6
  318. package/lib/esm/function/arithmetic/invmod.js +1 -1
  319. package/lib/esm/function/arithmetic/lcm.js +26 -70
  320. package/lib/esm/function/arithmetic/log.js +7 -10
  321. package/lib/esm/function/arithmetic/log10.js +1 -3
  322. package/lib/esm/function/arithmetic/log1p.js +4 -6
  323. package/lib/esm/function/arithmetic/log2.js +1 -3
  324. package/lib/esm/function/arithmetic/mod.js +21 -62
  325. package/lib/esm/function/arithmetic/multiply.js +23 -27
  326. package/lib/esm/function/arithmetic/multiplyScalar.js +2 -13
  327. package/lib/esm/function/arithmetic/norm.js +0 -4
  328. package/lib/esm/function/arithmetic/nthRoot.js +41 -76
  329. package/lib/esm/function/arithmetic/nthRoots.js +2 -2
  330. package/lib/esm/function/arithmetic/round.js +26 -28
  331. package/lib/esm/function/arithmetic/sign.js +5 -7
  332. package/lib/esm/function/arithmetic/sqrt.js +5 -8
  333. package/lib/esm/function/arithmetic/square.js +6 -9
  334. package/lib/esm/function/arithmetic/subtract.js +31 -95
  335. package/lib/esm/function/arithmetic/unaryMinus.js +6 -16
  336. package/lib/esm/function/arithmetic/unaryPlus.js +2 -4
  337. package/lib/esm/function/bitwise/bitAnd.js +16 -59
  338. package/lib/esm/function/bitwise/bitNot.js +2 -4
  339. package/lib/esm/function/bitwise/bitOr.js +16 -59
  340. package/lib/esm/function/bitwise/bitXor.js +16 -59
  341. package/lib/esm/function/bitwise/leftShift.js +39 -61
  342. package/lib/esm/function/bitwise/rightArithShift.js +39 -61
  343. package/lib/esm/function/bitwise/rightLogShift.js +39 -61
  344. package/lib/esm/function/bitwise/useMatrixForArrayScalar.js +13 -0
  345. package/lib/esm/function/complex/arg.js +1 -3
  346. package/lib/esm/function/complex/conj.js +3 -12
  347. package/lib/esm/function/complex/im.js +4 -15
  348. package/lib/esm/function/complex/re.js +3 -15
  349. package/lib/esm/function/geometry/distance.js +2 -2
  350. package/lib/esm/function/logical/and.js +35 -57
  351. package/lib/esm/function/logical/not.js +3 -6
  352. package/lib/esm/function/logical/or.js +16 -61
  353. package/lib/esm/function/logical/xor.js +16 -61
  354. package/lib/esm/function/matrix/diff.js +3 -8
  355. package/lib/esm/function/matrix/ones.js +2 -1
  356. package/lib/esm/function/matrix/rotate.js +5 -5
  357. package/lib/esm/function/matrix/sqrtm.js +3 -2
  358. package/lib/esm/function/matrix/transpose.js +47 -50
  359. package/lib/esm/function/matrix/zeros.js +2 -1
  360. package/lib/esm/function/probability/factorial.js +1 -3
  361. package/lib/esm/function/probability/gamma.js +38 -39
  362. package/lib/esm/function/probability/kldivergence.js +3 -2
  363. package/lib/esm/function/probability/lgamma.js +29 -29
  364. package/lib/esm/function/relational/compare.js +21 -67
  365. package/lib/esm/function/relational/compareNatural.js +54 -49
  366. package/lib/esm/function/relational/compareText.js +10 -42
  367. package/lib/esm/function/relational/compareUnits.js +15 -0
  368. package/lib/esm/function/relational/equal.js +19 -79
  369. package/lib/esm/function/relational/equalScalar.js +6 -9
  370. package/lib/esm/function/relational/larger.js +23 -73
  371. package/lib/esm/function/relational/largerEq.js +23 -73
  372. package/lib/esm/function/relational/smaller.js +23 -73
  373. package/lib/esm/function/relational/smallerEq.js +23 -73
  374. package/lib/esm/function/relational/unequal.js +19 -79
  375. package/lib/esm/function/special/erf.js +1 -3
  376. package/lib/esm/function/statistics/std.js +10 -2
  377. package/lib/esm/function/string/format.js +2 -2
  378. package/lib/esm/function/string/hex.js +1 -2
  379. package/lib/esm/function/trigonometry/acos.js +4 -7
  380. package/lib/esm/function/trigonometry/acosh.js +2 -6
  381. package/lib/esm/function/trigonometry/acot.js +6 -10
  382. package/lib/esm/function/trigonometry/acoth.js +4 -7
  383. package/lib/esm/function/trigonometry/acsc.js +6 -10
  384. package/lib/esm/function/trigonometry/acsch.js +4 -7
  385. package/lib/esm/function/trigonometry/asec.js +6 -9
  386. package/lib/esm/function/trigonometry/asech.js +4 -7
  387. package/lib/esm/function/trigonometry/asin.js +5 -9
  388. package/lib/esm/function/trigonometry/asinh.js +4 -8
  389. package/lib/esm/function/trigonometry/atan.js +5 -10
  390. package/lib/esm/function/trigonometry/atan2.js +26 -65
  391. package/lib/esm/function/trigonometry/atanh.js +4 -8
  392. package/lib/esm/function/trigonometry/cos.js +11 -22
  393. package/lib/esm/function/trigonometry/cosh.js +5 -20
  394. package/lib/esm/function/trigonometry/cot.js +10 -20
  395. package/lib/esm/function/trigonometry/coth.js +6 -20
  396. package/lib/esm/function/trigonometry/csc.js +12 -22
  397. package/lib/esm/function/trigonometry/csch.js +6 -20
  398. package/lib/esm/function/trigonometry/sec.js +12 -22
  399. package/lib/esm/function/trigonometry/sech.js +6 -20
  400. package/lib/esm/function/trigonometry/sin.js +11 -23
  401. package/lib/esm/function/trigonometry/sinh.js +5 -21
  402. package/lib/esm/function/trigonometry/tan.js +11 -23
  403. package/lib/esm/function/trigonometry/tanh.js +5 -21
  404. package/lib/esm/function/trigonometry/trigUnit.js +15 -0
  405. package/lib/esm/function/unit/to.js +8 -43
  406. package/lib/esm/function/utils/clone.js +1 -1
  407. package/lib/esm/function/utils/hasNumericValue.js +3 -1
  408. package/lib/esm/function/utils/isInteger.js +2 -4
  409. package/lib/esm/function/utils/isNaN.js +1 -1
  410. package/lib/esm/function/utils/isNegative.js +3 -7
  411. package/lib/esm/function/utils/isNumeric.js +4 -10
  412. package/lib/esm/function/utils/isPositive.js +3 -7
  413. package/lib/esm/function/utils/isPrime.js +1 -3
  414. package/lib/esm/function/utils/isZero.js +13 -17
  415. package/lib/esm/function/utils/numeric.js +11 -4
  416. package/lib/esm/function/utils/typeOf.js +38 -44
  417. package/lib/esm/type/bignumber/function/bignumber.js +1 -3
  418. package/lib/esm/type/boolean.js +1 -3
  419. package/lib/esm/type/chain/Chain.js +23 -3
  420. package/lib/esm/type/complex/Complex.js +4 -0
  421. package/lib/esm/type/complex/function/complex.js +1 -3
  422. package/lib/esm/type/fraction/Fraction.js +4 -0
  423. package/lib/esm/type/fraction/function/fraction.js +1 -3
  424. package/lib/esm/type/matrix/DenseMatrix.js +15 -1
  425. package/lib/esm/type/matrix/SparseMatrix.js +9 -0
  426. package/lib/esm/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +2 -2
  427. package/lib/esm/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +3 -3
  428. package/lib/esm/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +3 -3
  429. package/lib/esm/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +5 -5
  430. package/lib/esm/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +3 -3
  431. package/lib/esm/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +3 -3
  432. package/lib/esm/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +3 -3
  433. package/lib/esm/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +4 -4
  434. package/lib/esm/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +3 -3
  435. package/lib/esm/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +3 -3
  436. package/lib/esm/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +3 -3
  437. package/lib/esm/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +3 -3
  438. package/lib/esm/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +3 -3
  439. package/lib/esm/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +3 -3
  440. package/lib/esm/type/matrix/utils/matrixAlgorithmSuite.js +168 -0
  441. package/lib/esm/type/number.js +1 -3
  442. package/lib/esm/type/string.js +1 -3
  443. package/lib/esm/type/unit/Unit.js +85 -36
  444. package/lib/esm/type/unit/function/createUnit.js +2 -1
  445. package/lib/esm/type/unit/function/unit.js +10 -5
  446. package/lib/esm/utils/is.js +18 -18
  447. package/lib/esm/utils/snapshot.js +22 -48
  448. package/lib/esm/version.js +1 -1
  449. package/package.json +22 -25
  450. package/types/index.d.ts +211 -180
  451. package/types/index.ts +358 -144
  452. package/types/tsconfig.json +4 -1
  453. package/lib/cjs/utils/polyfills.js +0 -14
  454. package/lib/esm/utils/polyfills.js +0 -12
@@ -0,0 +1,168 @@
1
+ import { factory } from '../../../utils/factory.js';
2
+ import { extend } from '../../../utils/object.js';
3
+ import { createMatAlgo13xDD } from './matAlgo13xDD.js';
4
+ import { createMatAlgo14xDs } from './matAlgo14xDs.js';
5
+ var name = 'matrixAlgorithmSuite';
6
+ var dependencies = ['typed', 'matrix'];
7
+ export var createMatrixAlgorithmSuite = /* #__PURE__ */factory(name, dependencies, _ref => {
8
+ var {
9
+ typed,
10
+ matrix
11
+ } = _ref;
12
+ var matAlgo13xDD = createMatAlgo13xDD({
13
+ typed
14
+ });
15
+ var matAlgo14xDs = createMatAlgo14xDs({
16
+ typed
17
+ });
18
+ /**
19
+ * Return a signatures object with the usual boilerplate of
20
+ * matrix algorithms, based on a plain options object with the
21
+ * following properties:
22
+ * elop: function -- the elementwise operation to use, defaults to self
23
+ * SS: function -- the algorithm to apply for two sparse matrices
24
+ * DS: function -- the algorithm to apply for a dense and a sparse matrix
25
+ * SD: function -- algo for a sparse and a dense; defaults to SD flipped
26
+ * Ss: function -- the algorithm to apply for a sparse matrix and scalar
27
+ * sS: function -- algo for scalar and sparse; defaults to Ss flipped
28
+ * scalar: string -- typed-function type for scalars, defaults to 'any'
29
+ *
30
+ * If Ss is not specified, no matrix-scalar signatures are generated.
31
+ *
32
+ * @param {object} options
33
+ * @return {Object<string, function>} signatures
34
+ */
35
+
36
+ return function matrixAlgorithmSuite(options) {
37
+ var elop = options.elop;
38
+ var SD = options.SD || options.DS;
39
+ var matrixSignatures;
40
+
41
+ if (elop) {
42
+ // First the dense ones
43
+ matrixSignatures = {
44
+ 'DenseMatrix, DenseMatrix': (x, y) => matAlgo13xDD(x, y, elop),
45
+ 'Array, Array': (x, y) => matAlgo13xDD(matrix(x), matrix(y), elop).valueOf(),
46
+ 'Array, DenseMatrix': (x, y) => matAlgo13xDD(matrix(x), y, elop),
47
+ 'DenseMatrix, Array': (x, y) => matAlgo13xDD(x, matrix(y), elop)
48
+ }; // Now incorporate sparse matrices
49
+
50
+ if (options.SS) {
51
+ matrixSignatures['SparseMatrix, SparseMatrix'] = (x, y) => options.SS(x, y, elop, false);
52
+ }
53
+
54
+ if (options.DS) {
55
+ matrixSignatures['DenseMatrix, SparseMatrix'] = (x, y) => options.DS(x, y, elop, false);
56
+
57
+ matrixSignatures['Array, SparseMatrix'] = (x, y) => options.DS(matrix(x), y, elop, false);
58
+ }
59
+
60
+ if (SD) {
61
+ matrixSignatures['SparseMatrix, DenseMatrix'] = (x, y) => SD(y, x, elop, true);
62
+
63
+ matrixSignatures['SparseMatrix, Array'] = (x, y) => SD(matrix(y), x, elop, true);
64
+ }
65
+ } else {
66
+ // No elop, use this
67
+ // First the dense ones
68
+ matrixSignatures = {
69
+ 'DenseMatrix, DenseMatrix': typed.referToSelf(self => (x, y) => {
70
+ return matAlgo13xDD(x, y, self);
71
+ }),
72
+ 'Array, Array': typed.referToSelf(self => (x, y) => {
73
+ return matAlgo13xDD(matrix(x), matrix(y), self).valueOf();
74
+ }),
75
+ 'Array, DenseMatrix': typed.referToSelf(self => (x, y) => {
76
+ return matAlgo13xDD(matrix(x), y, self);
77
+ }),
78
+ 'DenseMatrix, Array': typed.referToSelf(self => (x, y) => {
79
+ return matAlgo13xDD(x, matrix(y), self);
80
+ })
81
+ }; // Now incorporate sparse matrices
82
+
83
+ if (options.SS) {
84
+ matrixSignatures['SparseMatrix, SparseMatrix'] = typed.referToSelf(self => (x, y) => {
85
+ return options.SS(x, y, self, false);
86
+ });
87
+ }
88
+
89
+ if (options.DS) {
90
+ matrixSignatures['DenseMatrix, SparseMatrix'] = typed.referToSelf(self => (x, y) => {
91
+ return options.DS(x, y, self, false);
92
+ });
93
+ matrixSignatures['Array, SparseMatrix'] = typed.referToSelf(self => (x, y) => {
94
+ return options.DS(matrix(x), y, self, false);
95
+ });
96
+ }
97
+
98
+ if (SD) {
99
+ matrixSignatures['SparseMatrix, DenseMatrix'] = typed.referToSelf(self => (x, y) => {
100
+ return SD(y, x, self, true);
101
+ });
102
+ matrixSignatures['SparseMatrix, Array'] = typed.referToSelf(self => (x, y) => {
103
+ return SD(matrix(y), x, self, true);
104
+ });
105
+ }
106
+ } // Now add the scalars
107
+
108
+
109
+ var scalar = options.scalar || 'any';
110
+ var Ds = options.Ds || options.Ss;
111
+
112
+ if (Ds) {
113
+ if (elop) {
114
+ matrixSignatures['DenseMatrix,' + scalar] = (x, y) => matAlgo14xDs(x, y, elop, false);
115
+
116
+ matrixSignatures[scalar + ', DenseMatrix'] = (x, y) => matAlgo14xDs(y, x, elop, true);
117
+
118
+ matrixSignatures['Array,' + scalar] = (x, y) => matAlgo14xDs(matrix(x), y, elop, false).valueOf();
119
+
120
+ matrixSignatures[scalar + ', Array'] = (x, y) => matAlgo14xDs(matrix(y), x, elop, true).valueOf();
121
+ } else {
122
+ matrixSignatures['DenseMatrix,' + scalar] = typed.referToSelf(self => (x, y) => {
123
+ return matAlgo14xDs(x, y, self, false);
124
+ });
125
+ matrixSignatures[scalar + ', DenseMatrix'] = typed.referToSelf(self => (x, y) => {
126
+ return matAlgo14xDs(y, x, self, true);
127
+ });
128
+ matrixSignatures['Array,' + scalar] = typed.referToSelf(self => (x, y) => {
129
+ return matAlgo14xDs(matrix(x), y, self, false).valueOf();
130
+ });
131
+ matrixSignatures[scalar + ', Array'] = typed.referToSelf(self => (x, y) => {
132
+ return matAlgo14xDs(matrix(y), x, self, true).valueOf();
133
+ });
134
+ }
135
+ }
136
+
137
+ var sS = options.sS !== undefined ? options.sS : options.Ss;
138
+
139
+ if (elop) {
140
+ if (options.Ss) {
141
+ matrixSignatures['SparseMatrix,' + scalar] = (x, y) => options.Ss(x, y, elop, false);
142
+ }
143
+
144
+ if (sS) {
145
+ matrixSignatures[scalar + ', SparseMatrix'] = (x, y) => sS(y, x, elop, true);
146
+ }
147
+ } else {
148
+ if (options.Ss) {
149
+ matrixSignatures['SparseMatrix,' + scalar] = typed.referToSelf(self => (x, y) => {
150
+ return options.Ss(x, y, self, false);
151
+ });
152
+ }
153
+
154
+ if (sS) {
155
+ matrixSignatures[scalar + ', SparseMatrix'] = typed.referToSelf(self => (x, y) => {
156
+ return sS(y, x, self, true);
157
+ });
158
+ }
159
+ } // Also pull in the scalar signatures if the operator is a typed function
160
+
161
+
162
+ if (elop && elop.signatures) {
163
+ extend(matrixSignatures, elop.signatures);
164
+ }
165
+
166
+ return matrixSignatures;
167
+ };
168
+ });
@@ -146,9 +146,7 @@ export var createNumber = /* #__PURE__ */factory(name, dependencies, _ref => {
146
146
  'Unit, string | Unit': function UnitStringUnit(unit, valuelessUnit) {
147
147
  return unit.toNumber(valuelessUnit);
148
148
  },
149
- 'Array | Matrix': function ArrayMatrix(x) {
150
- return deepMap(x, this);
151
- }
149
+ 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
152
150
  }); // reviver function to parse a JSON object like:
153
151
  //
154
152
  // {"mathjs":"number","value":"2.3"}
@@ -47,9 +47,7 @@ export var createString = /* #__PURE__ */factory(name, dependencies, _ref => {
47
47
  string: function string(x) {
48
48
  return x;
49
49
  },
50
- 'Array | Matrix': function ArrayMatrix(x) {
51
- return deepMap(x, this);
52
- },
50
+ 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self)),
53
51
  any: function any(x) {
54
52
  return String(x);
55
53
  }
@@ -1,5 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _extends from "@babel/runtime/helpers/extends";
3
3
 
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
 
@@ -37,8 +37,8 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
37
37
  /**
38
38
  * A unit can be constructed in the following ways:
39
39
  *
40
- * const a = new Unit(value, name)
41
- * const b = new Unit(null, name)
40
+ * const a = new Unit(value, valuelessUnit)
41
+ * const b = new Unit(null, valuelessUnit)
42
42
  * const c = Unit.parse(str)
43
43
  *
44
44
  * Example usage:
@@ -51,10 +51,10 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
51
51
  * @class Unit
52
52
  * @constructor Unit
53
53
  * @param {number | BigNumber | Fraction | Complex | boolean} [value] A value like 5.2
54
- * @param {string} [name] A unit name like "cm" or "inch", or a derived unit of the form: "u1[^ex1] [u2[^ex2] ...] [/ u3[^ex3] [u4[^ex4]]]", such as "kg m^2/s^2", where each unit appearing after the forward slash is taken to be in the denominator. "kg m^2 s^-2" is a synonym and is also acceptable. Any of the units can include a prefix.
54
+ * @param {string | Unit} valuelessUnit A unit without value. Can have prefix, like "cm"
55
55
  */
56
56
 
57
- function Unit(value, name) {
57
+ function Unit(value, valuelessUnit) {
58
58
  if (!(this instanceof Unit)) {
59
59
  throw new Error('Constructor must be called with the new operator');
60
60
  }
@@ -63,42 +63,42 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
63
63
  throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
64
64
  }
65
65
 
66
- if (name !== undefined && (typeof name !== 'string' || name === '')) {
67
- throw new TypeError('Second parameter in Unit constructor must be a string');
68
- }
69
-
70
- if (name !== undefined) {
71
- var u = Unit.parse(name);
72
- this.units = u.units;
73
- this.dimensions = u.dimensions;
74
- } else {
75
- this.units = [{
76
- unit: UNIT_NONE,
77
- prefix: PREFIXES.NONE,
78
- // link to a list with supported prefixes
79
- power: 0
80
- }];
81
- this.dimensions = [];
82
-
83
- for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
84
- this.dimensions[i] = 0;
85
- }
86
- }
87
-
88
- this.value = value !== undefined && value !== null ? this._normalize(value) : null;
89
66
  this.fixPrefix = false; // if true, function format will not search for the
90
67
  // best prefix but leave it as initially provided.
91
68
  // fixPrefix is set true by the method Unit.to
92
69
  // The justification behind this is that if the constructor is explicitly called,
93
- // the caller wishes the units to be returned exactly as he supplied.
70
+ // the caller wishes the units to be returned exactly as supplied.
94
71
 
95
72
  this.skipAutomaticSimplification = true;
73
+
74
+ if (valuelessUnit === undefined) {
75
+ this.units = [];
76
+ this.dimensions = BASE_DIMENSIONS.map(x => 0);
77
+ } else if (typeof valuelessUnit === 'string') {
78
+ var u = Unit.parse(valuelessUnit);
79
+ this.units = u.units;
80
+ this.dimensions = u.dimensions;
81
+ } else if (isUnit(valuelessUnit) && valuelessUnit.value === null) {
82
+ // clone from valuelessUnit
83
+ this.fixPrefix = valuelessUnit.fixPrefix;
84
+ this.skipAutomaticSimplification = valuelessUnit.skipAutomaticSimplification;
85
+ this.dimensions = valuelessUnit.dimensions.slice(0);
86
+ this.units = valuelessUnit.units.map(u => _extends({}, u));
87
+ } else {
88
+ throw new TypeError('Second parameter in Unit constructor must be a string or valueless Unit');
89
+ }
90
+
91
+ this.value = this._normalize(value);
96
92
  }
97
93
  /**
98
94
  * Attach type information
99
95
  */
100
96
 
101
97
 
98
+ Object.defineProperty(Unit, 'name', {
99
+ value: 'Unit'
100
+ });
101
+ Unit.prototype.constructor = Unit;
102
102
  Unit.prototype.type = 'Unit';
103
103
  Unit.prototype.isUnit = true; // private variables and functions for the Unit parser
104
104
 
@@ -461,6 +461,17 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
461
461
 
462
462
  return unit;
463
463
  };
464
+ /**
465
+ * Return the type of the value of this unit
466
+ *
467
+ * @memberof Unit
468
+ * @ return {string} type of the value of the unit
469
+ */
470
+
471
+
472
+ Unit.prototype.valueType = function () {
473
+ return typeOf(this.value);
474
+ };
464
475
  /**
465
476
  * Return whether the unit is derived (such as m/s, or cm^2, but not N)
466
477
  * @memberof Unit
@@ -648,15 +659,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
648
659
  return this.equalBase(other) && equal(this.value, other.value);
649
660
  };
650
661
  /**
651
- * Multiply this unit with another one
662
+ * Multiply this unit with another one or with a scalar
652
663
  * @memberof Unit
653
664
  * @param {Unit} other
654
665
  * @return {Unit} product of this unit and the other unit
655
666
  */
656
667
 
657
668
 
658
- Unit.prototype.multiply = function (other) {
669
+ Unit.prototype.multiply = function (_other) {
659
670
  var res = this.clone();
671
+ var other = isUnit(_other) ? _other : new Unit(_other);
660
672
 
661
673
  for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
662
674
  // Dimensions arrays may be of different lengths. Default to 0.
@@ -680,19 +692,35 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
680
692
  res.value = null;
681
693
  }
682
694
 
683
- res.skipAutomaticSimplification = false;
695
+ if (isUnit(_other)) {
696
+ res.skipAutomaticSimplification = false;
697
+ }
698
+
684
699
  return getNumericIfUnitless(res);
685
700
  };
701
+ /**
702
+ * Divide a number by this unit
703
+ *
704
+ * @memberof Unit
705
+ * @param {numeric} numerator
706
+ * @param {unit} result of dividing numerator by this unit
707
+ */
708
+
709
+
710
+ Unit.prototype.divideInto = function (numerator) {
711
+ return new Unit(numerator).divide(this);
712
+ };
686
713
  /**
687
714
  * Divide this unit by another one
688
715
  * @memberof Unit
689
- * @param {Unit} other
716
+ * @param {Unit | numeric} other
690
717
  * @return {Unit} result of dividing this unit by the other unit
691
718
  */
692
719
 
693
720
 
694
- Unit.prototype.divide = function (other) {
721
+ Unit.prototype.divide = function (_other) {
695
722
  var res = this.clone();
723
+ var other = isUnit(_other) ? _other : new Unit(_other);
696
724
 
697
725
  for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
698
726
  // Dimensions arrays may be of different lengths. Default to 0.
@@ -718,7 +746,10 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
718
746
  res.value = null;
719
747
  }
720
748
 
721
- res.skipAutomaticSimplification = false;
749
+ if (isUnit(_other)) {
750
+ res.skipAutomaticSimplification = false;
751
+ }
752
+
722
753
  return getNumericIfUnitless(res);
723
754
  };
724
755
  /**
@@ -787,7 +818,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
787
818
  // To give the correct, but unexpected, results for units with an offset.
788
819
  // For example, abs(-283.15 degC) = -263.15 degC !!!
789
820
  // We must take the offset into consideration here
790
- var convert = Unit._getNumberConverter(typeOf(ret.value)); // convert to Fraction or BigNumber if needed
821
+ var convert = ret._numberConverter(); // convert to Fraction or BigNumber if needed
791
822
 
792
823
 
793
824
  var unitValue = convert(ret.units[0].unit.value);
@@ -3627,6 +3658,23 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
3627
3658
  return x;
3628
3659
  }
3629
3660
  };
3661
+ /**
3662
+ * Retrieve the right converter function corresponding with this unit's
3663
+ * value
3664
+ *
3665
+ * @memberof Unit
3666
+ * @return {Function}
3667
+ */
3668
+
3669
+ Unit.prototype._numberConverter = function () {
3670
+ var convert = Unit.typeConverters[this.valueType()];
3671
+
3672
+ if (convert) {
3673
+ return convert;
3674
+ }
3675
+
3676
+ throw new TypeError('Unsupported Unit value type "' + this.valueType() + '"');
3677
+ };
3630
3678
  /**
3631
3679
  * Retrieve the right convertor function corresponding with the type
3632
3680
  * of provided exampleValue.
@@ -3636,6 +3684,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
3636
3684
  * @return {Function}
3637
3685
  */
3638
3686
 
3687
+
3639
3688
  Unit._getNumberConverter = function (type) {
3640
3689
  if (!Unit.typeConverters[type]) {
3641
3690
  throw new TypeError('Unsupported type "' + type + '"');
@@ -34,9 +34,10 @@ export var createCreateUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
34
34
  * math.createUnit('foo')
35
35
  * math.createUnit('knot', {definition: '0.514444444 m/s', aliases: ['knots', 'kt', 'kts']})
36
36
  * math.createUnit('mph', '1 mile/hour')
37
+ * math.createUnit('km', math.unit(1000, 'm'))
37
38
  *
38
39
  * @param {string} name The name of the new unit. Must be unique. Example: 'knot'
39
- * @param {string, Unit} definition Definition of the unit in terms of existing units. For example, '0.514444444 m / s'.
40
+ * @param {string, UnitDefinition, Unit} definition Definition of the unit in terms of existing units. For example, '0.514444444 m / s'.
40
41
  * @param {Object} options (optional) An object containing any of the following properties:
41
42
  * - `prefixes {string}` "none", "short", "long", "binary_short", or "binary_long". The default is "none".
42
43
  * - `aliases {Array}` Array of strings. Example: ['knots', 'kt', 'kts']
@@ -17,10 +17,13 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
17
17
  * Syntax:
18
18
  *
19
19
  * math.unit(unit : string)
20
- * math.unit(value : number, unit : string)
20
+ * math.unit(value : number, valuelessUnit : Unit)
21
+ * math.unit(value : number, valuelessUnit : string)
21
22
  *
22
23
  * Examples:
23
24
  *
25
+ * const kph = math.unit('km/h') // returns Unit km/h (valueless)
26
+ * const v = math.unit(25, kph) // returns Unit 25 km/h
24
27
  * const a = math.unit(5, 'cm') // returns Unit 50 mm
25
28
  * const b = math.unit('23 kg') // returns Unit 23 kg
26
29
  * a.to('m') // returns Unit 0.05 m
@@ -45,11 +48,13 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
45
48
  allowNoUnits: true
46
49
  }); // a unit with value, like '5cm'
47
50
  },
48
- 'number | BigNumber | Fraction | Complex, string': function numberBigNumberFractionComplexString(value, unit) {
51
+ 'number | BigNumber | Fraction | Complex, string | Unit': function numberBigNumberFractionComplexStringUnit(value, unit) {
49
52
  return new Unit(value, unit);
50
53
  },
51
- 'Array | Matrix': function ArrayMatrix(x) {
52
- return deepMap(x, this);
53
- }
54
+ 'number | BigNumber | Fraction': function numberBigNumberFraction(value) {
55
+ // dimensionless
56
+ return new Unit(value);
57
+ },
58
+ 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
54
59
  });
55
60
  });
@@ -111,6 +111,20 @@ export function isConditionalNode(x) {
111
111
  export function isConstantNode(x) {
112
112
  return x && x.isConstantNode === true && x.constructor.prototype.isNode === true || false;
113
113
  }
114
+ /* Very specialized: returns true for those nodes which in the numerator of
115
+ a fraction means that the division in that fraction has precedence over implicit
116
+ multiplication, e.g. -2/3 x parses as (-2/3) x and 3/4 x parses as (3/4) x but
117
+ 6!/8 x parses as 6! / (8x). It is located here because it is shared between
118
+ parse.js and OperatorNode.js (for parsing and printing, respectively).
119
+
120
+ This should *not* be exported from mathjs, unlike most of the tests here.
121
+ Its name does not start with 'is' to prevent utils/snapshot.js from thinking
122
+ it should be exported.
123
+ */
124
+
125
+ export function rule2Node(node) {
126
+ return isConstantNode(node) || isOperatorNode(node) && node.args.length === 1 && isConstantNode(node.args[0]) && '-+~'.includes(node.op);
127
+ }
114
128
  export function isFunctionAssignmentNode(x) {
115
129
  return x && x.isFunctionAssignmentNode === true && x.constructor.prototype.isNode === true || false;
116
130
  }
@@ -145,26 +159,12 @@ export function typeOf(x) {
145
159
  var t = typeof x;
146
160
 
147
161
  if (t === 'object') {
148
- // JavaScript types
149
162
  if (x === null) return 'null';
150
- if (Array.isArray(x)) return 'Array';
151
- if (x instanceof Date) return 'Date';
152
- if (x instanceof RegExp) return 'RegExp'; // math.js types
163
+ if (isBigNumber(x)) return 'BigNumber'; // Special: weird mashup with Decimal
153
164
 
154
- if (isBigNumber(x)) return 'BigNumber';
155
- if (isComplex(x)) return 'Complex';
156
- if (isFraction(x)) return 'Fraction';
157
- if (isMatrix(x)) return 'Matrix';
158
- if (isUnit(x)) return 'Unit';
159
- if (isIndex(x)) return 'Index';
160
- if (isRange(x)) return 'Range';
161
- if (isResultSet(x)) return 'ResultSet';
162
- if (isNode(x)) return x.type;
163
- if (isChain(x)) return 'Chain';
164
- if (isHelp(x)) return 'Help';
165
- return 'Object';
165
+ if (x.constructor && x.constructor.name) return x.constructor.name;
166
+ return 'Object'; // just in case
166
167
  }
167
168
 
168
- if (t === 'function') return 'Function';
169
- return t; // can be 'string', 'number', 'boolean', ...
169
+ return t; // can be 'string', 'number', 'boolean', 'function', 'bigint', ...
170
170
  }
@@ -16,6 +16,7 @@ import assert from 'assert';
16
16
  import * as allIsFunctions from './is.js';
17
17
  import { create } from '../core/create.js';
18
18
  import { endsWith } from './string.js';
19
+ export var validateTypeOf = allIsFunctions.typeOf;
19
20
  export function validateBundle(expectedBundleStructure, bundle) {
20
21
  var originalWarn = console.warn;
21
22
 
@@ -110,21 +111,21 @@ export function createSnapshotFromFactories(factories) {
110
111
  var factory = factories[factoryName];
111
112
  var name = factory.fn;
112
113
  var isTransformFunction = factory.meta && factory.meta.isTransformFunction;
113
- var isClass = !isLowerCase(name[0]) && validateTypeOf(math[name]) === 'Function';
114
+ var isClass = !isLowerCase(name[0]) && validateTypeOf(math[name]) === 'function';
114
115
  var dependenciesName = factory.fn + (isTransformFunction ? 'Transform' : '') + 'Dependencies';
115
- allFactoryFunctions[factoryName] = 'Function';
116
+ allFactoryFunctions[factoryName] = 'function';
116
117
  allFunctionsConstantsClasses[name] = validateTypeOf(math[name]);
117
118
  allDependencyCollections[dependenciesName] = 'Object';
118
119
 
119
120
  if (isTransformFunction) {
120
- allTransformFunctions[name] = 'Function';
121
+ allTransformFunctions[name] = 'function';
121
122
  }
122
123
 
123
124
  if (isClass) {
124
125
  if (endsWith(name, 'Node')) {
125
- allNodeClasses[name] = 'Function';
126
+ allNodeClasses[name] = 'function';
126
127
  } else {
127
- allClasses[name] = 'Function';
128
+ allClasses[name] = 'function';
128
129
  }
129
130
  } else {
130
131
  allFunctionsConstants[name] = validateTypeOf(math[name]);
@@ -144,37 +145,37 @@ export function createSnapshotFromFactories(factories) {
144
145
  var allTypeChecks = {};
145
146
  Object.keys(allIsFunctions).forEach(name => {
146
147
  if (name.indexOf('is') === 0) {
147
- allTypeChecks[name] = 'Function';
148
+ allTypeChecks[name] = 'function';
148
149
  }
149
150
  });
150
151
  var allErrorClasses = {
151
- ArgumentsError: 'Function',
152
- DimensionError: 'Function',
153
- IndexError: 'Function'
152
+ ArgumentsError: 'function',
153
+ DimensionError: 'function',
154
+ IndexError: 'function'
154
155
  };
155
156
 
156
157
  var expectedInstanceStructure = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, allFunctionsConstantsClasses), {}, {
157
- on: 'Function',
158
- off: 'Function',
159
- once: 'Function',
160
- emit: 'Function',
161
- import: 'Function',
162
- config: 'Function',
163
- create: 'Function',
164
- factory: 'Function'
158
+ on: 'function',
159
+ off: 'function',
160
+ once: 'function',
161
+ emit: 'function',
162
+ import: 'function',
163
+ config: 'function',
164
+ create: 'function',
165
+ factory: 'function'
165
166
  }, allTypeChecks), allErrorClasses), {}, {
166
167
  expression: {
167
168
  transform: _objectSpread({}, allTransformFunctions),
168
169
  mathWithTransform: _objectSpread(_objectSpread({}, exclude(allFunctionsConstants, ['chain'])), {}, {
169
- config: 'Function'
170
+ config: 'function'
170
171
  })
171
172
  }
172
173
  });
173
174
 
174
175
  var expectedES6Structure = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, exclude(allFunctionsConstantsClasses, ['E', 'false', 'Infinity', 'NaN', 'null', 'PI', 'true'])), {}, {
175
- create: 'Function',
176
- config: 'Function',
177
- factory: 'Function',
176
+ create: 'function',
177
+ config: 'function',
178
+ factory: 'function',
178
179
  _true: 'boolean',
179
180
  _false: 'boolean',
180
181
  _null: 'null',
@@ -189,33 +190,6 @@ export function createSnapshotFromFactories(factories) {
189
190
  expectedES6Structure
190
191
  };
191
192
  }
192
- export function validateTypeOf(x) {
193
- if (x && x.type === 'Unit') {
194
- return 'Unit';
195
- }
196
-
197
- if (x && x.type === 'Complex') {
198
- return 'Complex';
199
- }
200
-
201
- if (Array.isArray(x)) {
202
- return 'Array';
203
- }
204
-
205
- if (x === null) {
206
- return 'null';
207
- }
208
-
209
- if (typeof x === 'function') {
210
- return 'Function';
211
- }
212
-
213
- if (typeof x === 'object') {
214
- return 'Object';
215
- }
216
-
217
- return typeof x;
218
- }
219
193
 
220
194
  function traverse(obj) {
221
195
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (value, path) => {};
@@ -1,2 +1,2 @@
1
- export var version = '10.6.4'; // Note: This file is automatically generated when building math.js.
1
+ export var version = '11.1.0'; // Note: This file is automatically generated when building math.js.
2
2
  // Changes made in this file will be overwritten.