mathjs 13.2.2 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. package/HISTORY.md +26 -0
  2. package/lib/browser/math.js +1 -1
  3. package/lib/browser/math.js.LICENSE.txt +2 -10
  4. package/lib/browser/math.js.map +1 -1
  5. package/lib/cjs/core/function/import.js +4 -1
  6. package/lib/cjs/core/function/typed.js +1 -1
  7. package/lib/cjs/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
  8. package/lib/cjs/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
  9. package/lib/cjs/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
  10. package/lib/cjs/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
  11. package/lib/cjs/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  12. package/lib/cjs/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
  13. package/lib/cjs/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
  14. package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  15. package/lib/cjs/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  16. package/lib/cjs/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
  17. package/lib/cjs/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
  18. package/lib/cjs/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
  19. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  20. package/lib/cjs/entry/impureFunctionsAny.generated.js +1 -0
  21. package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -0
  22. package/lib/cjs/entry/pureFunctionsAny.generated.js +11 -0
  23. package/lib/cjs/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
  24. package/lib/cjs/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
  25. package/lib/cjs/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
  26. package/lib/cjs/expression/parse.js +26 -36
  27. package/lib/cjs/function/algebra/simplify.js +4 -3
  28. package/lib/cjs/function/algebra/simplifyConstant.js +5 -11
  29. package/lib/cjs/function/arithmetic/ceil.js +21 -2
  30. package/lib/cjs/function/arithmetic/dotDivide.js +4 -3
  31. package/lib/cjs/function/arithmetic/dotPow.js +4 -3
  32. package/lib/cjs/function/arithmetic/fix.js +24 -5
  33. package/lib/cjs/function/arithmetic/floor.js +21 -2
  34. package/lib/cjs/function/arithmetic/log.js +12 -4
  35. package/lib/cjs/function/arithmetic/pow.js +2 -2
  36. package/lib/cjs/function/arithmetic/round.js +3 -5
  37. package/lib/cjs/function/arithmetic/sign.js +1 -1
  38. package/lib/cjs/function/bitwise/bitXor.js +4 -3
  39. package/lib/cjs/function/logical/xor.js +4 -3
  40. package/lib/cjs/function/matrix/filter.js +7 -0
  41. package/lib/cjs/function/matrix/forEach.js +7 -0
  42. package/lib/cjs/function/relational/equal.js +4 -3
  43. package/lib/cjs/function/relational/larger.js +4 -3
  44. package/lib/cjs/function/relational/largerEq.js +4 -3
  45. package/lib/cjs/function/relational/smaller.js +4 -3
  46. package/lib/cjs/function/relational/smallerEq.js +4 -3
  47. package/lib/cjs/function/relational/unequal.js +4 -3
  48. package/lib/cjs/function/utils/isInteger.js +1 -1
  49. package/lib/cjs/function/utils/isNegative.js +1 -1
  50. package/lib/cjs/function/utils/isPositive.js +1 -1
  51. package/lib/cjs/header.js +2 -2
  52. package/lib/cjs/type/bignumber/function/bignumber.js +2 -2
  53. package/lib/cjs/type/fraction/Fraction.js +4 -4
  54. package/lib/cjs/type/fraction/function/fraction.js +3 -0
  55. package/lib/cjs/type/matrix/utils/matAlgo07xSSf.js +39 -43
  56. package/lib/cjs/type/unit/Unit.js +1 -1
  57. package/lib/cjs/utils/object.js +4 -0
  58. package/lib/cjs/utils/string.js +2 -2
  59. package/lib/cjs/version.js +1 -1
  60. package/lib/esm/core/function/import.js +4 -1
  61. package/lib/esm/core/function/typed.js +1 -1
  62. package/lib/esm/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
  63. package/lib/esm/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
  64. package/lib/esm/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
  65. package/lib/esm/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
  66. package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  67. package/lib/esm/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
  68. package/lib/esm/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
  69. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  70. package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  71. package/lib/esm/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
  72. package/lib/esm/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
  73. package/lib/esm/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
  74. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  75. package/lib/esm/entry/impureFunctionsAny.generated.js +1 -0
  76. package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -0
  77. package/lib/esm/entry/pureFunctionsAny.generated.js +11 -0
  78. package/lib/esm/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
  79. package/lib/esm/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
  80. package/lib/esm/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
  81. package/lib/esm/expression/parse.js +26 -36
  82. package/lib/esm/function/algebra/simplify.js +4 -3
  83. package/lib/esm/function/algebra/simplifyConstant.js +5 -11
  84. package/lib/esm/function/arithmetic/ceil.js +21 -2
  85. package/lib/esm/function/arithmetic/dotDivide.js +4 -3
  86. package/lib/esm/function/arithmetic/dotPow.js +4 -3
  87. package/lib/esm/function/arithmetic/fix.js +24 -5
  88. package/lib/esm/function/arithmetic/floor.js +21 -2
  89. package/lib/esm/function/arithmetic/log.js +12 -4
  90. package/lib/esm/function/arithmetic/pow.js +2 -2
  91. package/lib/esm/function/arithmetic/round.js +3 -5
  92. package/lib/esm/function/arithmetic/sign.js +1 -1
  93. package/lib/esm/function/bitwise/bitXor.js +4 -3
  94. package/lib/esm/function/logical/xor.js +4 -3
  95. package/lib/esm/function/matrix/filter.js +7 -0
  96. package/lib/esm/function/matrix/forEach.js +7 -0
  97. package/lib/esm/function/relational/equal.js +4 -3
  98. package/lib/esm/function/relational/larger.js +4 -3
  99. package/lib/esm/function/relational/largerEq.js +4 -3
  100. package/lib/esm/function/relational/smaller.js +4 -3
  101. package/lib/esm/function/relational/smallerEq.js +4 -3
  102. package/lib/esm/function/relational/unequal.js +4 -3
  103. package/lib/esm/function/utils/isInteger.js +1 -1
  104. package/lib/esm/function/utils/isNegative.js +1 -1
  105. package/lib/esm/function/utils/isPositive.js +1 -1
  106. package/lib/esm/type/bignumber/function/bignumber.js +2 -2
  107. package/lib/esm/type/fraction/Fraction.js +4 -4
  108. package/lib/esm/type/fraction/function/fraction.js +3 -0
  109. package/lib/esm/type/matrix/utils/matAlgo07xSSf.js +39 -43
  110. package/lib/esm/type/unit/Unit.js +1 -1
  111. package/lib/esm/utils/object.js +4 -0
  112. package/lib/esm/utils/string.js +2 -2
  113. package/lib/esm/version.js +1 -1
  114. package/package.json +3 -3
  115. package/types/index.d.ts +115 -25
package/types/index.d.ts CHANGED
@@ -10,11 +10,11 @@ export type NoLiteralType<T> = T extends number
10
10
  ? boolean
11
11
  : T
12
12
 
13
- // TODO: introduce generics for MathCollection, MathMatrix, and MathArray
14
13
  export type MathNumericType = number | BigNumber | bigint | Fraction | Complex
15
14
  export type MathScalarType = MathNumericType | Unit
16
- export type MathArray = MathNumericType[] | MathNumericType[][] // TODO: MathArray can also contain Unit
17
- export type MathCollection = MathArray | Matrix
15
+ export type MathGeneric<T extends MathScalarType = MathNumericType> = T
16
+ export type MathArray<T = MathGeneric> = T[] | Array<MathArray<T>>
17
+ export type MathCollection<T = MathGeneric> = MathArray<T> | Matrix<T>
18
18
  export type MathType = MathScalarType | MathCollection
19
19
  export type MathExpression = string | string[] | MathCollection
20
20
 
@@ -719,6 +719,7 @@ export interface MathJsInstance extends MathJsFactory {
719
719
  * fraction
720
720
  * @returns Returns a fraction
721
721
  */
722
+ fraction(numerator: bigint, denominator: bigint): Fraction
722
723
  fraction(numerator: number, denominator: number): Fraction
723
724
 
724
725
  /**
@@ -751,6 +752,11 @@ export interface MathJsInstance extends MathJsFactory {
751
752
  format?: 'sparse' | 'dense',
752
753
  dataType?: string
753
754
  ): Matrix
755
+ matrix<T extends MathScalarType>(
756
+ data: MathCollection<T>,
757
+ format?: 'sparse' | 'dense',
758
+ dataType?: string
759
+ ): Matrix<T>
754
760
 
755
761
  /**
756
762
  * Create a number or convert a string, boolean, or unit to a number.
@@ -1147,6 +1153,14 @@ export interface MathJsInstance extends MathJsFactory {
1147
1153
  n?: number | BigNumber
1148
1154
  ): NoLiteralType<T>
1149
1155
  ceil<U extends MathCollection>(x: MathNumericType, n: U): U
1156
+ ceil<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1157
+ ceil(x: Unit, unit: Unit): Unit
1158
+ ceil(x: Unit, n: number | BigNumber, unit: Unit): Unit
1159
+ ceil<U extends MathCollection<Unit>>(
1160
+ x: U,
1161
+ n: number | BigNumber,
1162
+ unit: Unit
1163
+ ): U
1150
1164
 
1151
1165
  /**
1152
1166
  * Round a value towards zero. For matrices, the function is evaluated
@@ -1160,6 +1174,14 @@ export interface MathJsInstance extends MathJsFactory {
1160
1174
  n?: number | BigNumber
1161
1175
  ): NoLiteralType<T>
1162
1176
  fix<U extends MathCollection>(x: MathNumericType, n: U): U
1177
+ fix<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1178
+ fix(x: Unit, unit: Unit): Unit
1179
+ fix(x: Unit, n: number | BigNumber, unit: Unit): Unit
1180
+ fix<U extends MathCollection<Unit>>(
1181
+ x: U,
1182
+ n: number | BigNumber,
1183
+ unit: Unit
1184
+ ): U
1163
1185
 
1164
1186
  /**
1165
1187
  * Round a value towards minus infinity. For matrices, the function is
@@ -1173,6 +1195,14 @@ export interface MathJsInstance extends MathJsFactory {
1173
1195
  n?: number | BigNumber
1174
1196
  ): NoLiteralType<T>
1175
1197
  floor<U extends MathCollection>(x: MathNumericType, n: U): U
1198
+ floor<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1199
+ floor(x: Unit, unit: Unit): Unit
1200
+ floor(x: Unit, n: number | BigNumber, unit: Unit): Unit
1201
+ floor<U extends MathCollection<Unit>>(
1202
+ x: U,
1203
+ n: number | BigNumber,
1204
+ unit: Unit
1205
+ ): U
1176
1206
 
1177
1207
  /**
1178
1208
  * Round a value towards the nearest integer. For matrices, the function
@@ -1186,10 +1216,14 @@ export interface MathJsInstance extends MathJsFactory {
1186
1216
  n?: number | BigNumber
1187
1217
  ): NoLiteralType<T>
1188
1218
  round<U extends MathCollection>(x: MathNumericType, n: U): U
1189
- round<U extends MathCollection>(x: U, unit: Unit): U
1219
+ round<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1190
1220
  round(x: Unit, unit: Unit): Unit
1191
1221
  round(x: Unit, n: number | BigNumber, unit: Unit): Unit
1192
- round<U extends MathCollection>(x: U, n: number | BigNumber, unit: Unit): U
1222
+ round<U extends MathCollection<Unit>>(
1223
+ x: U,
1224
+ n: number | BigNumber,
1225
+ unit: Unit
1226
+ ): U
1193
1227
 
1194
1228
  // End of group of rounding functions
1195
1229
 
@@ -1359,9 +1393,10 @@ export interface MathJsInstance extends MathJsFactory {
1359
1393
  multiply<T extends Matrix>(x: T, y: MathType): Matrix
1360
1394
  multiply<T extends Matrix>(x: MathType, y: T): Matrix
1361
1395
 
1362
- multiply<T extends MathNumericType[]>(x: T, y: T[]): T
1363
- multiply<T extends MathNumericType[]>(x: T[], y: T): T
1364
- multiply<T extends MathArray>(x: T, y: T): T
1396
+ multiply<T extends MathArray>(x: T, y: T[]): T
1397
+ multiply<T extends MathArray>(x: T[], y: T): T
1398
+ multiply<T extends MathArray>(x: T[], y: T[]): T
1399
+ multiply<T extends MathArray>(x: T, y: T): MathScalarType
1365
1400
  multiply(x: Unit, y: Unit): Unit
1366
1401
  multiply(x: number, y: number): number
1367
1402
  multiply(x: MathType, y: MathType): MathType
@@ -1940,8 +1975,7 @@ export interface MathJsInstance extends MathJsFactory {
1940
1975
  | ((
1941
1976
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1942
1977
  value: any,
1943
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1944
- index: any,
1978
+ index: number[],
1945
1979
  matrix: MathCollection | string[]
1946
1980
  ) => boolean)
1947
1981
  | RegExp
@@ -1965,7 +1999,7 @@ export interface MathJsInstance extends MathJsFactory {
1965
1999
  forEach<T extends MathCollection>(
1966
2000
  x: T,
1967
2001
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1968
- callback: (value: any, index: any, matrix: T) => void
2002
+ callback: (value: any, index: number[], matrix: T) => void
1969
2003
  ): void
1970
2004
 
1971
2005
  /**
@@ -3965,7 +3999,7 @@ export const {
3965
3999
  varianceTransformDependencies
3966
4000
  }: Record<string, FactoryFunctionMap>
3967
4001
 
3968
- export interface Matrix {
4002
+ export interface Matrix<T = MathGeneric> {
3969
4003
  type: string
3970
4004
  storage(): string
3971
4005
  datatype(): string
@@ -3982,7 +4016,7 @@ export interface Matrix {
3982
4016
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3983
4017
  set(index: number[], value: any, defaultValue?: number | string): Matrix
3984
4018
  resize(size: MathCollection, defaultValue?: number | string): Matrix
3985
- clone(): Matrix
4019
+ clone(): Matrix<T>
3986
4020
  size(): number[]
3987
4021
  map(
3988
4022
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -3994,8 +4028,8 @@ export interface Matrix {
3994
4028
  callback: (a: any, b: number[], c: Matrix) => void,
3995
4029
  skipZeros?: boolean
3996
4030
  ): void
3997
- toArray(): MathArray
3998
- valueOf(): MathArray
4031
+ toArray(): MathArray<T>
4032
+ valueOf(): MathArray<T>
3999
4033
  format(
4000
4034
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4001
4035
  options?: FormatOptions | number | BigNumber | ((value: any) => string)
@@ -4005,7 +4039,7 @@ export interface Matrix {
4005
4039
  toJSON(): any
4006
4040
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4007
4041
  diagonal(k?: number | BigNumber): any[]
4008
- swapRows(i: number, j: number): Matrix
4042
+ swapRows(i: number, j: number): Matrix<T>
4009
4043
  }
4010
4044
 
4011
4045
  export interface MatrixCtor {
@@ -4016,9 +4050,9 @@ export interface MatrixCtor {
4016
4050
  export interface BigNumber extends Decimal {}
4017
4051
 
4018
4052
  export interface Fraction {
4019
- s: number
4020
- n: number
4021
- d: number
4053
+ s: bigint
4054
+ n: bigint
4055
+ d: bigint
4022
4056
  }
4023
4057
 
4024
4058
  export interface Complex {
@@ -4995,6 +5029,25 @@ export interface MathJsChain<TValue> {
4995
5029
  this: MathJsChain<T>,
4996
5030
  n?: number | BigNumber | MathCollection
4997
5031
  ): MathJsChain<T>
5032
+ ceil<U extends MathCollection>(
5033
+ this: MathJsChain<MathNumericType | U>,
5034
+ n: U
5035
+ ): MathJsChain<U>
5036
+ ceil(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5037
+ ceil<U extends MathCollection<Unit>>(
5038
+ this: MathJsChain<U>,
5039
+ unit: Unit
5040
+ ): MathJsChain<U>
5041
+ ceil(
5042
+ this: MathJsChain<Unit>,
5043
+ n: number | BigNumber,
5044
+ unit: Unit
5045
+ ): MathJsChain<Unit>
5046
+ ceil<U extends MathCollection<Unit>>(
5047
+ this: MathJsChain<U>,
5048
+ n: number | BigNumber,
5049
+ unit: Unit
5050
+ ): MathJsChain<U>
4998
5051
 
4999
5052
  /**
5000
5053
  * Round a value towards zero. For matrices, the function is evaluated
@@ -5005,6 +5058,25 @@ export interface MathJsChain<TValue> {
5005
5058
  this: MathJsChain<T>,
5006
5059
  n?: number | BigNumber | MathCollection
5007
5060
  ): MathJsChain<T>
5061
+ fix<U extends MathCollection>(
5062
+ this: MathJsChain<MathNumericType | U>,
5063
+ n: U
5064
+ ): MathJsChain<U>
5065
+ fix(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5066
+ fix<U extends MathCollection<Unit>>(
5067
+ this: MathJsChain<U>,
5068
+ unit: Unit
5069
+ ): MathJsChain<U>
5070
+ fix(
5071
+ this: MathJsChain<Unit>,
5072
+ n: number | BigNumber,
5073
+ unit: Unit
5074
+ ): MathJsChain<Unit>
5075
+ fix<U extends MathCollection<Unit>>(
5076
+ this: MathJsChain<U>,
5077
+ n: number | BigNumber,
5078
+ unit: Unit
5079
+ ): MathJsChain<U>
5008
5080
 
5009
5081
  /**
5010
5082
  * Round a value towards minus infinity. For matrices, the function is
@@ -5015,6 +5087,25 @@ export interface MathJsChain<TValue> {
5015
5087
  this: MathJsChain<T>,
5016
5088
  n?: number | BigNumber | MathCollection
5017
5089
  ): MathJsChain<T>
5090
+ floor<U extends MathCollection>(
5091
+ this: MathJsChain<MathNumericType | U>,
5092
+ n: U
5093
+ ): MathJsChain<U>
5094
+ floor(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5095
+ floor<U extends MathCollection<Unit>>(
5096
+ this: MathJsChain<U>,
5097
+ unit: Unit
5098
+ ): MathJsChain<U>
5099
+ floor(
5100
+ this: MathJsChain<Unit>,
5101
+ n: number | BigNumber,
5102
+ unit: Unit
5103
+ ): MathJsChain<Unit>
5104
+ floor<U extends MathCollection<Unit>>(
5105
+ this: MathJsChain<U>,
5106
+ n: number | BigNumber,
5107
+ unit: Unit
5108
+ ): MathJsChain<U>
5018
5109
 
5019
5110
  /**
5020
5111
  * Round a value towards the nearest integer. For matrices, the function
@@ -5030,7 +5121,7 @@ export interface MathJsChain<TValue> {
5030
5121
  n: U
5031
5122
  ): MathJsChain<U>
5032
5123
  round(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5033
- round<U extends MathCollection>(
5124
+ round<U extends MathCollection<Unit>>(
5034
5125
  this: MathJsChain<U>,
5035
5126
  unit: Unit
5036
5127
  ): MathJsChain<U>
@@ -5039,7 +5130,7 @@ export interface MathJsChain<TValue> {
5039
5130
  n: number | BigNumber,
5040
5131
  unit: Unit
5041
5132
  ): MathJsChain<Unit>
5042
- round<U extends MathCollection>(
5133
+ round<U extends MathCollection<Unit>>(
5043
5134
  this: MathJsChain<U>,
5044
5135
  n: number | BigNumber,
5045
5136
  unit: Unit
@@ -5714,8 +5805,7 @@ export interface MathJsChain<TValue> {
5714
5805
  | ((
5715
5806
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5716
5807
  value: any,
5717
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5718
- index: any,
5808
+ index: number[],
5719
5809
  matrix: MathCollection | string[]
5720
5810
  ) => boolean)
5721
5811
  | RegExp
@@ -5734,7 +5824,7 @@ export interface MathJsChain<TValue> {
5734
5824
  forEach<T extends MathCollection>(
5735
5825
  this: MathJsChain<T>,
5736
5826
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5737
- callback: (value: any, index: any, matrix: T) => void
5827
+ callback: (value: any, index: number[], matrix: T) => void
5738
5828
  ): void
5739
5829
 
5740
5830
  /**
@@ -5764,7 +5854,7 @@ export interface MathJsChain<TValue> {
5764
5854
  map<T extends MathCollection>(
5765
5855
  this: MathJsChain<T>,
5766
5856
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5767
- callback: (value: any, index: any, matrix: T) => MathType | string
5857
+ callback: (value: any, index: number[], matrix: T) => MathType | string
5768
5858
  ): MathJsChain<T>
5769
5859
 
5770
5860
  /**