mathjs 13.2.3 → 14.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/HISTORY.md +24 -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/derivative.js +64 -77
  28. package/lib/cjs/function/algebra/simplify.js +4 -3
  29. package/lib/cjs/function/algebra/simplifyConstant.js +5 -11
  30. package/lib/cjs/function/arithmetic/ceil.js +21 -2
  31. package/lib/cjs/function/arithmetic/dotDivide.js +4 -3
  32. package/lib/cjs/function/arithmetic/dotPow.js +4 -3
  33. package/lib/cjs/function/arithmetic/fix.js +24 -5
  34. package/lib/cjs/function/arithmetic/floor.js +21 -2
  35. package/lib/cjs/function/arithmetic/log.js +12 -4
  36. package/lib/cjs/function/arithmetic/pow.js +2 -2
  37. package/lib/cjs/function/arithmetic/round.js +3 -5
  38. package/lib/cjs/function/arithmetic/sign.js +1 -1
  39. package/lib/cjs/function/bitwise/bitXor.js +4 -3
  40. package/lib/cjs/function/logical/xor.js +4 -3
  41. package/lib/cjs/function/relational/equal.js +4 -3
  42. package/lib/cjs/function/relational/larger.js +4 -3
  43. package/lib/cjs/function/relational/largerEq.js +4 -3
  44. package/lib/cjs/function/relational/smaller.js +4 -3
  45. package/lib/cjs/function/relational/smallerEq.js +4 -3
  46. package/lib/cjs/function/relational/unequal.js +4 -3
  47. package/lib/cjs/function/utils/isInteger.js +1 -1
  48. package/lib/cjs/function/utils/isNegative.js +1 -1
  49. package/lib/cjs/function/utils/isPositive.js +1 -1
  50. package/lib/cjs/header.js +2 -2
  51. package/lib/cjs/type/bignumber/function/bignumber.js +2 -2
  52. package/lib/cjs/type/fraction/Fraction.js +4 -4
  53. package/lib/cjs/type/fraction/function/fraction.js +3 -0
  54. package/lib/cjs/type/matrix/utils/matAlgo07xSSf.js +39 -43
  55. package/lib/cjs/type/unit/Unit.js +1 -1
  56. package/lib/cjs/utils/string.js +2 -2
  57. package/lib/cjs/version.js +1 -1
  58. package/lib/esm/core/function/import.js +4 -1
  59. package/lib/esm/core/function/typed.js +1 -1
  60. package/lib/esm/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
  61. package/lib/esm/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
  62. package/lib/esm/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
  63. package/lib/esm/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
  64. package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  65. package/lib/esm/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
  66. package/lib/esm/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
  67. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  68. package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  69. package/lib/esm/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
  70. package/lib/esm/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
  71. package/lib/esm/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
  72. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  73. package/lib/esm/entry/impureFunctionsAny.generated.js +1 -0
  74. package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -0
  75. package/lib/esm/entry/pureFunctionsAny.generated.js +11 -0
  76. package/lib/esm/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
  77. package/lib/esm/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
  78. package/lib/esm/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
  79. package/lib/esm/expression/parse.js +26 -36
  80. package/lib/esm/function/algebra/derivative.js +64 -77
  81. package/lib/esm/function/algebra/simplify.js +4 -3
  82. package/lib/esm/function/algebra/simplifyConstant.js +5 -11
  83. package/lib/esm/function/arithmetic/ceil.js +21 -2
  84. package/lib/esm/function/arithmetic/dotDivide.js +4 -3
  85. package/lib/esm/function/arithmetic/dotPow.js +4 -3
  86. package/lib/esm/function/arithmetic/fix.js +24 -5
  87. package/lib/esm/function/arithmetic/floor.js +21 -2
  88. package/lib/esm/function/arithmetic/log.js +12 -4
  89. package/lib/esm/function/arithmetic/pow.js +2 -2
  90. package/lib/esm/function/arithmetic/round.js +3 -5
  91. package/lib/esm/function/arithmetic/sign.js +1 -1
  92. package/lib/esm/function/bitwise/bitXor.js +4 -3
  93. package/lib/esm/function/logical/xor.js +4 -3
  94. package/lib/esm/function/relational/equal.js +4 -3
  95. package/lib/esm/function/relational/larger.js +4 -3
  96. package/lib/esm/function/relational/largerEq.js +4 -3
  97. package/lib/esm/function/relational/smaller.js +4 -3
  98. package/lib/esm/function/relational/smallerEq.js +4 -3
  99. package/lib/esm/function/relational/unequal.js +4 -3
  100. package/lib/esm/function/utils/isInteger.js +1 -1
  101. package/lib/esm/function/utils/isNegative.js +1 -1
  102. package/lib/esm/function/utils/isPositive.js +1 -1
  103. package/lib/esm/type/bignumber/function/bignumber.js +2 -2
  104. package/lib/esm/type/fraction/Fraction.js +4 -4
  105. package/lib/esm/type/fraction/function/fraction.js +3 -0
  106. package/lib/esm/type/matrix/utils/matAlgo07xSSf.js +39 -43
  107. package/lib/esm/type/unit/Unit.js +1 -1
  108. package/lib/esm/utils/string.js +2 -2
  109. package/lib/esm/version.js +1 -1
  110. package/package.json +13 -13
  111. package/types/index.d.ts +112 -23
package/types/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { Decimal } from 'decimal.js'
2
+ import { Fraction } from 'fraction.js'
3
+
4
+ export { Fraction }
2
5
 
3
6
  export as namespace math
4
7
 
@@ -10,11 +13,11 @@ export type NoLiteralType<T> = T extends number
10
13
  ? boolean
11
14
  : T
12
15
 
13
- // TODO: introduce generics for MathCollection, MathMatrix, and MathArray
14
16
  export type MathNumericType = number | BigNumber | bigint | Fraction | Complex
15
17
  export type MathScalarType = MathNumericType | Unit
16
- export type MathArray = MathNumericType[] | MathNumericType[][] // TODO: MathArray can also contain Unit
17
- export type MathCollection = MathArray | Matrix
18
+ export type MathGeneric<T extends MathScalarType = MathNumericType> = T
19
+ export type MathArray<T = MathGeneric> = T[] | Array<MathArray<T>>
20
+ export type MathCollection<T = MathGeneric> = MathArray<T> | Matrix<T>
18
21
  export type MathType = MathScalarType | MathCollection
19
22
  export type MathExpression = string | string[] | MathCollection
20
23
 
@@ -719,6 +722,7 @@ export interface MathJsInstance extends MathJsFactory {
719
722
  * fraction
720
723
  * @returns Returns a fraction
721
724
  */
725
+ fraction(numerator: bigint, denominator: bigint): Fraction
722
726
  fraction(numerator: number, denominator: number): Fraction
723
727
 
724
728
  /**
@@ -751,6 +755,11 @@ export interface MathJsInstance extends MathJsFactory {
751
755
  format?: 'sparse' | 'dense',
752
756
  dataType?: string
753
757
  ): Matrix
758
+ matrix<T extends MathScalarType>(
759
+ data: MathCollection<T>,
760
+ format?: 'sparse' | 'dense',
761
+ dataType?: string
762
+ ): Matrix<T>
754
763
 
755
764
  /**
756
765
  * Create a number or convert a string, boolean, or unit to a number.
@@ -1147,6 +1156,14 @@ export interface MathJsInstance extends MathJsFactory {
1147
1156
  n?: number | BigNumber
1148
1157
  ): NoLiteralType<T>
1149
1158
  ceil<U extends MathCollection>(x: MathNumericType, n: U): U
1159
+ ceil<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1160
+ ceil(x: Unit, unit: Unit): Unit
1161
+ ceil(x: Unit, n: number | BigNumber, unit: Unit): Unit
1162
+ ceil<U extends MathCollection<Unit>>(
1163
+ x: U,
1164
+ n: number | BigNumber,
1165
+ unit: Unit
1166
+ ): U
1150
1167
 
1151
1168
  /**
1152
1169
  * Round a value towards zero. For matrices, the function is evaluated
@@ -1160,6 +1177,14 @@ export interface MathJsInstance extends MathJsFactory {
1160
1177
  n?: number | BigNumber
1161
1178
  ): NoLiteralType<T>
1162
1179
  fix<U extends MathCollection>(x: MathNumericType, n: U): U
1180
+ fix<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1181
+ fix(x: Unit, unit: Unit): Unit
1182
+ fix(x: Unit, n: number | BigNumber, unit: Unit): Unit
1183
+ fix<U extends MathCollection<Unit>>(
1184
+ x: U,
1185
+ n: number | BigNumber,
1186
+ unit: Unit
1187
+ ): U
1163
1188
 
1164
1189
  /**
1165
1190
  * Round a value towards minus infinity. For matrices, the function is
@@ -1173,6 +1198,14 @@ export interface MathJsInstance extends MathJsFactory {
1173
1198
  n?: number | BigNumber
1174
1199
  ): NoLiteralType<T>
1175
1200
  floor<U extends MathCollection>(x: MathNumericType, n: U): U
1201
+ floor<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1202
+ floor(x: Unit, unit: Unit): Unit
1203
+ floor(x: Unit, n: number | BigNumber, unit: Unit): Unit
1204
+ floor<U extends MathCollection<Unit>>(
1205
+ x: U,
1206
+ n: number | BigNumber,
1207
+ unit: Unit
1208
+ ): U
1176
1209
 
1177
1210
  /**
1178
1211
  * Round a value towards the nearest integer. For matrices, the function
@@ -1186,10 +1219,14 @@ export interface MathJsInstance extends MathJsFactory {
1186
1219
  n?: number | BigNumber
1187
1220
  ): NoLiteralType<T>
1188
1221
  round<U extends MathCollection>(x: MathNumericType, n: U): U
1189
- round<U extends MathCollection>(x: U, unit: Unit): U
1222
+ round<U extends MathCollection<Unit>>(x: U, unit: Unit): U
1190
1223
  round(x: Unit, unit: Unit): Unit
1191
1224
  round(x: Unit, n: number | BigNumber, unit: Unit): Unit
1192
- round<U extends MathCollection>(x: U, n: number | BigNumber, unit: Unit): U
1225
+ round<U extends MathCollection<Unit>>(
1226
+ x: U,
1227
+ n: number | BigNumber,
1228
+ unit: Unit
1229
+ ): U
1193
1230
 
1194
1231
  // End of group of rounding functions
1195
1232
 
@@ -1359,9 +1396,10 @@ export interface MathJsInstance extends MathJsFactory {
1359
1396
  multiply<T extends Matrix>(x: T, y: MathType): Matrix
1360
1397
  multiply<T extends Matrix>(x: MathType, y: T): Matrix
1361
1398
 
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
1399
+ multiply<T extends MathArray>(x: T, y: T[]): T
1400
+ multiply<T extends MathArray>(x: T[], y: T): T
1401
+ multiply<T extends MathArray>(x: T[], y: T[]): T
1402
+ multiply<T extends MathArray>(x: T, y: T): MathScalarType
1365
1403
  multiply(x: Unit, y: Unit): Unit
1366
1404
  multiply(x: number, y: number): number
1367
1405
  multiply(x: MathType, y: MathType): MathType
@@ -3964,7 +4002,7 @@ export const {
3964
4002
  varianceTransformDependencies
3965
4003
  }: Record<string, FactoryFunctionMap>
3966
4004
 
3967
- export interface Matrix {
4005
+ export interface Matrix<T = MathGeneric> {
3968
4006
  type: string
3969
4007
  storage(): string
3970
4008
  datatype(): string
@@ -3981,7 +4019,7 @@ export interface Matrix {
3981
4019
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3982
4020
  set(index: number[], value: any, defaultValue?: number | string): Matrix
3983
4021
  resize(size: MathCollection, defaultValue?: number | string): Matrix
3984
- clone(): Matrix
4022
+ clone(): Matrix<T>
3985
4023
  size(): number[]
3986
4024
  map(
3987
4025
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -3993,8 +4031,8 @@ export interface Matrix {
3993
4031
  callback: (a: any, b: number[], c: Matrix) => void,
3994
4032
  skipZeros?: boolean
3995
4033
  ): void
3996
- toArray(): MathArray
3997
- valueOf(): MathArray
4034
+ toArray(): MathArray<T>
4035
+ valueOf(): MathArray<T>
3998
4036
  format(
3999
4037
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4000
4038
  options?: FormatOptions | number | BigNumber | ((value: any) => string)
@@ -4004,22 +4042,16 @@ export interface Matrix {
4004
4042
  toJSON(): any
4005
4043
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4006
4044
  diagonal(k?: number | BigNumber): any[]
4007
- swapRows(i: number, j: number): Matrix
4045
+ swapRows(i: number, j: number): Matrix<T>
4008
4046
  }
4009
4047
 
4010
4048
  export interface MatrixCtor {
4011
4049
  new (): Matrix
4012
4050
  }
4013
4051
 
4014
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
4052
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4015
4053
  export interface BigNumber extends Decimal {}
4016
4054
 
4017
- export interface Fraction {
4018
- s: number
4019
- n: number
4020
- d: number
4021
- }
4022
-
4023
4055
  export interface Complex {
4024
4056
  re: number
4025
4057
  im: number
@@ -4211,7 +4243,7 @@ export interface UnitDefinition {
4211
4243
  baseName?: string
4212
4244
  }
4213
4245
 
4214
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
4246
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4215
4247
  export interface Index {}
4216
4248
 
4217
4249
  export interface PartitionedMap<T, U> {
@@ -4994,6 +5026,25 @@ export interface MathJsChain<TValue> {
4994
5026
  this: MathJsChain<T>,
4995
5027
  n?: number | BigNumber | MathCollection
4996
5028
  ): MathJsChain<T>
5029
+ ceil<U extends MathCollection>(
5030
+ this: MathJsChain<MathNumericType | U>,
5031
+ n: U
5032
+ ): MathJsChain<U>
5033
+ ceil(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5034
+ ceil<U extends MathCollection<Unit>>(
5035
+ this: MathJsChain<U>,
5036
+ unit: Unit
5037
+ ): MathJsChain<U>
5038
+ ceil(
5039
+ this: MathJsChain<Unit>,
5040
+ n: number | BigNumber,
5041
+ unit: Unit
5042
+ ): MathJsChain<Unit>
5043
+ ceil<U extends MathCollection<Unit>>(
5044
+ this: MathJsChain<U>,
5045
+ n: number | BigNumber,
5046
+ unit: Unit
5047
+ ): MathJsChain<U>
4997
5048
 
4998
5049
  /**
4999
5050
  * Round a value towards zero. For matrices, the function is evaluated
@@ -5004,6 +5055,25 @@ export interface MathJsChain<TValue> {
5004
5055
  this: MathJsChain<T>,
5005
5056
  n?: number | BigNumber | MathCollection
5006
5057
  ): MathJsChain<T>
5058
+ fix<U extends MathCollection>(
5059
+ this: MathJsChain<MathNumericType | U>,
5060
+ n: U
5061
+ ): MathJsChain<U>
5062
+ fix(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5063
+ fix<U extends MathCollection<Unit>>(
5064
+ this: MathJsChain<U>,
5065
+ unit: Unit
5066
+ ): MathJsChain<U>
5067
+ fix(
5068
+ this: MathJsChain<Unit>,
5069
+ n: number | BigNumber,
5070
+ unit: Unit
5071
+ ): MathJsChain<Unit>
5072
+ fix<U extends MathCollection<Unit>>(
5073
+ this: MathJsChain<U>,
5074
+ n: number | BigNumber,
5075
+ unit: Unit
5076
+ ): MathJsChain<U>
5007
5077
 
5008
5078
  /**
5009
5079
  * Round a value towards minus infinity. For matrices, the function is
@@ -5014,6 +5084,25 @@ export interface MathJsChain<TValue> {
5014
5084
  this: MathJsChain<T>,
5015
5085
  n?: number | BigNumber | MathCollection
5016
5086
  ): MathJsChain<T>
5087
+ floor<U extends MathCollection>(
5088
+ this: MathJsChain<MathNumericType | U>,
5089
+ n: U
5090
+ ): MathJsChain<U>
5091
+ floor(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5092
+ floor<U extends MathCollection<Unit>>(
5093
+ this: MathJsChain<U>,
5094
+ unit: Unit
5095
+ ): MathJsChain<U>
5096
+ floor(
5097
+ this: MathJsChain<Unit>,
5098
+ n: number | BigNumber,
5099
+ unit: Unit
5100
+ ): MathJsChain<Unit>
5101
+ floor<U extends MathCollection<Unit>>(
5102
+ this: MathJsChain<U>,
5103
+ n: number | BigNumber,
5104
+ unit: Unit
5105
+ ): MathJsChain<U>
5017
5106
 
5018
5107
  /**
5019
5108
  * Round a value towards the nearest integer. For matrices, the function
@@ -5029,7 +5118,7 @@ export interface MathJsChain<TValue> {
5029
5118
  n: U
5030
5119
  ): MathJsChain<U>
5031
5120
  round(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
5032
- round<U extends MathCollection>(
5121
+ round<U extends MathCollection<Unit>>(
5033
5122
  this: MathJsChain<U>,
5034
5123
  unit: Unit
5035
5124
  ): MathJsChain<U>
@@ -5038,7 +5127,7 @@ export interface MathJsChain<TValue> {
5038
5127
  n: number | BigNumber,
5039
5128
  unit: Unit
5040
5129
  ): MathJsChain<Unit>
5041
- round<U extends MathCollection>(
5130
+ round<U extends MathCollection<Unit>>(
5042
5131
  this: MathJsChain<U>,
5043
5132
  n: number | BigNumber,
5044
5133
  unit: Unit