mathjs 14.0.0 → 14.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/HISTORY.md +15 -0
  2. package/NOTICE +1 -1
  3. package/README.md +7 -7
  4. package/bin/cli.js +1 -1
  5. package/lib/browser/math.js +1 -1
  6. package/lib/browser/math.js.LICENSE.txt +5 -5
  7. package/lib/browser/math.js.map +1 -1
  8. package/lib/cjs/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  9. package/lib/cjs/entry/dependenciesAny/dependenciesRandomInt.generated.js +2 -0
  10. package/lib/cjs/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  11. package/lib/cjs/entry/dependenciesNumber/dependenciesRandomInt.generated.js +2 -0
  12. package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -1
  13. package/lib/cjs/entry/pureFunctionsAny.generated.js +3 -0
  14. package/lib/cjs/entry/pureFunctionsNumber.generated.js +5 -4
  15. package/lib/cjs/expression/embeddedDocs/function/arithmetic/sign.js +1 -1
  16. package/lib/cjs/function/algebra/derivative.js +64 -77
  17. package/lib/cjs/function/arithmetic/log.js +12 -5
  18. package/lib/cjs/function/arithmetic/log10.js +15 -7
  19. package/lib/cjs/function/arithmetic/log2.js +9 -4
  20. package/lib/cjs/function/probability/randomInt.js +26 -3
  21. package/lib/cjs/function/relational/larger.js +12 -4
  22. package/lib/cjs/function/relational/smaller.js +12 -4
  23. package/lib/cjs/function/statistics/max.js +1 -1
  24. package/lib/cjs/function/statistics/min.js +1 -1
  25. package/lib/cjs/function/string/print.js +2 -2
  26. package/lib/cjs/function/utils/isInteger.js +1 -1
  27. package/lib/cjs/header.js +3 -3
  28. package/lib/cjs/utils/bigint.js +33 -0
  29. package/lib/cjs/utils/number.js +7 -19
  30. package/lib/cjs/version.js +1 -1
  31. package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  32. package/lib/esm/entry/dependenciesAny/dependenciesRandomInt.generated.js +2 -0
  33. package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  34. package/lib/esm/entry/dependenciesNumber/dependenciesRandomInt.generated.js +2 -0
  35. package/lib/esm/entry/impureFunctionsNumber.generated.js +2 -2
  36. package/lib/esm/entry/pureFunctionsAny.generated.js +3 -0
  37. package/lib/esm/entry/pureFunctionsNumber.generated.js +6 -5
  38. package/lib/esm/expression/embeddedDocs/function/arithmetic/sign.js +1 -1
  39. package/lib/esm/function/algebra/derivative.js +64 -77
  40. package/lib/esm/function/arithmetic/log.js +12 -5
  41. package/lib/esm/function/arithmetic/log10.js +16 -8
  42. package/lib/esm/function/arithmetic/log2.js +9 -4
  43. package/lib/esm/function/probability/randomInt.js +26 -3
  44. package/lib/esm/function/relational/larger.js +12 -4
  45. package/lib/esm/function/relational/smaller.js +12 -4
  46. package/lib/esm/function/statistics/max.js +1 -1
  47. package/lib/esm/function/statistics/min.js +1 -1
  48. package/lib/esm/function/string/print.js +2 -2
  49. package/lib/esm/function/utils/isInteger.js +1 -1
  50. package/lib/esm/header.js +1 -1
  51. package/lib/esm/utils/bigint.js +27 -0
  52. package/lib/esm/utils/number.js +6 -17
  53. package/lib/esm/version.js +1 -1
  54. package/package.json +19 -17
  55. package/types/index.d.ts +5 -8
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Build a bigint logarithm function from a number logarithm,
3
+ * still returning a number. The idea is that 15 hexadecimal digits
4
+ * (60 bits) saturates the mantissa of the log, and each additional hex
5
+ * digit effectively just adds the log of 16 to the resulting value. So
6
+ * convert the most significant 15 hex digits to a number and take its
7
+ * log, and then add the log of 16 for each additional hex digit that
8
+ * was in the bigint.
9
+ * For negative numbers (complex logarithms), following the bignum
10
+ * implementation, it just downgrades to number and uses the complex result.
11
+ * @param {number} log16 the log of 16
12
+ * @param {(number) -> number} numberLog the logarithm function for numbers
13
+ * @param {ConfigurationObject} config the mathjs configuration
14
+ * @param {(number) -> Complex} cplx the associated Complex log
15
+ * @returns {(bigint) -> number} the corresponding logarithm for bigints
16
+ */
17
+ export function promoteLogarithm(log16, numberLog, config, cplx) {
18
+ return function (b) {
19
+ if (b > 0 || config.predictable) {
20
+ if (b <= 0) return NaN;
21
+ var s = b.toString(16);
22
+ var s15 = s.substring(0, 15);
23
+ return log16 * (s.length - s15.length) + numberLog(Number('0x' + s15));
24
+ }
25
+ return cplx(b.toNumber());
26
+ };
27
+ }
@@ -16,16 +16,6 @@ export function isInteger(value) {
16
16
  return isFinite(value) ? value === Math.round(value) : false;
17
17
  }
18
18
 
19
- /**
20
- * Check if a string contains an integer
21
- * @param {string} str
22
- * @return {boolean} isInteger
23
- */
24
- export function isIntegerStr(str) {
25
- // regex matching strings like "123" and "-123"
26
- return /^-?\d+$/.test(str);
27
- }
28
-
29
19
  /**
30
20
  * Ensure the number type is compatible with the provided value.
31
21
  * If not, return 'number' instead.
@@ -45,8 +35,12 @@ export function isIntegerStr(str) {
45
35
  * @returns {'number' | 'BigNumber' | 'bigint' | 'Fraction'}
46
36
  */
47
37
  export function safeNumberType(numberStr, config) {
48
- if (config.number === 'bigint' && !isIntegerStr(numberStr)) {
49
- return config.numberFallback;
38
+ if (config.number === 'bigint') {
39
+ try {
40
+ BigInt(numberStr);
41
+ } catch (_unused) {
42
+ return config.numberFallback;
43
+ }
50
44
  }
51
45
  return config.number;
52
46
  }
@@ -610,11 +604,6 @@ export function digits(value) {
610
604
  .length;
611
605
  }
612
606
 
613
- /**
614
- * Minimum number added to one that makes the result different than one
615
- */
616
- export var DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16;
617
-
618
607
  /**
619
608
  * Compares two floating point numbers.
620
609
  * @param {number} a - First value to compare
@@ -1,3 +1,3 @@
1
- export var version = '14.0.0';
1
+ export var version = '14.1.0';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "14.0.0",
3
+ "version": "14.1.0",
4
4
  "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
5
5
  "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
6
6
  "homepage": "https://mathjs.org",
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.25.7",
29
+ "@lambdatest/node-tunnel": "^4.0.8",
29
30
  "complex.js": "^2.2.5",
30
31
  "decimal.js": "^10.4.3",
31
32
  "escape-latex": "^1.2.0",
@@ -43,41 +44,42 @@
43
44
  "@babel/preset-env": "7.26.0",
44
45
  "@babel/register": "7.25.9",
45
46
  "@types/assert": "1.5.11",
46
- "@types/mocha": "10.0.9",
47
- "@typescript-eslint/eslint-plugin": "7.16.1",
48
- "@typescript-eslint/parser": "7.16.1",
47
+ "@types/mocha": "10.0.10",
48
+ "@typescript-eslint/eslint-plugin": "8.21.0",
49
+ "@typescript-eslint/parser": "8.21.0",
49
50
  "assert": "2.1.0",
50
51
  "babel-loader": "9.2.1",
51
- "benchmark": "2.1.4",
52
- "c8": "10.1.2",
52
+ "c8": "10.1.3",
53
53
  "codecov": "3.8.3",
54
- "core-js": "3.39.0",
54
+ "core-js": "3.40.0",
55
55
  "del": "8.0.0",
56
56
  "dtslint": "4.2.1",
57
- "eslint": "8.57.0",
57
+ "eigen": "0.2.2",
58
+ "eslint": "8.57.1",
58
59
  "eslint-config-prettier": "9.1.0",
59
60
  "eslint-config-standard": "17.1.0",
60
61
  "eslint-plugin-import": "2.31.0",
61
62
  "eslint-plugin-mocha": "10.5.0",
62
63
  "eslint-plugin-n": "16.6.2",
63
- "eslint-plugin-prettier": "5.2.1",
64
+ "eslint-plugin-prettier": "5.2.3",
64
65
  "eslint-plugin-promise": "6.6.0",
65
66
  "expect-type": "1.1.0",
66
67
  "expr-eval": "2.0.2",
67
68
  "fancy-log": "2.0.0",
68
- "glob": "11.0.0",
69
+ "glob": "11.0.1",
69
70
  "gulp": "5.0.0",
70
71
  "gulp-babel": "8.0.0",
71
72
  "handlebars": "4.7.8",
72
73
  "jsep": "1.4.0",
73
74
  "karma": "6.4.4",
74
- "karma-browserstack-launcher": "1.6.0",
75
75
  "karma-firefox-launcher": "2.1.3",
76
76
  "karma-mocha": "2.0.1",
77
77
  "karma-mocha-reporter": "2.2.5",
78
+ "karma-spec-reporter": "0.0.36",
79
+ "karma-webdriver-launcher": "1.0.8",
78
80
  "karma-webpack": "5.0.1",
79
81
  "mkdirp": "3.0.1",
80
- "mocha": "10.8.2",
82
+ "mocha": "11.1.0",
81
83
  "mocha-junit-reporter": "2.2.1",
82
84
  "ndarray": "1.0.19",
83
85
  "ndarray-determinant": "1.0.0",
@@ -85,14 +87,14 @@
85
87
  "ndarray-ops": "1.2.2",
86
88
  "ndarray-pack": "1.2.1",
87
89
  "numericjs": "1.2.6",
88
- "pad-right": "0.2.2",
89
- "prettier": "3.3.3",
90
+ "prettier": "3.4.2",
90
91
  "process": "0.11.10",
91
92
  "sinon": "19.0.2",
92
93
  "sylvester": "0.0.21",
94
+ "tinybench": "3.1.0",
93
95
  "ts-node": "10.9.2",
94
- "typescript": "5.5.4",
95
- "webpack": "5.96.1",
96
+ "typescript": "5.7.3",
97
+ "webpack": "5.97.1",
96
98
  "zeros": "1.0.0"
97
99
  },
98
100
  "type": "module",
@@ -151,7 +153,7 @@
151
153
  "test:node": "mocha test/node-tests/*.test.js test/node-tests/**/*.test.js",
152
154
  "test:all": "npm run test:src && npm run test:generated && npm run test:node && npm run test:types",
153
155
  "test:browser": "karma start test/browser-test-config/local-karma.js",
154
- "test:browserstack": "karma start test/browser-test-config/browserstack-karma.js",
156
+ "test:lambdatest": "karma start test/browser-test-config/lambdatest-karma.js",
155
157
  "test:types": " tsc -p ./tsconfig.json && node --loader ts-node/esm ./test/typescript-tests/testTypes.ts",
156
158
  "coverage": "c8 --reporter=lcov --reporter=text-summary mocha test/unit-tests && echo \"\nDetailed coverage report is available at ./coverage/lcov-report/index.html\"",
157
159
  "prepublishOnly": "npm run test:all && npm run lint",
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
 
@@ -4046,15 +4049,9 @@ export interface MatrixCtor {
4046
4049
  new (): Matrix
4047
4050
  }
4048
4051
 
4049
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
4052
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4050
4053
  export interface BigNumber extends Decimal {}
4051
4054
 
4052
- export interface Fraction {
4053
- s: bigint
4054
- n: bigint
4055
- d: bigint
4056
- }
4057
-
4058
4055
  export interface Complex {
4059
4056
  re: number
4060
4057
  im: number
@@ -4246,7 +4243,7 @@ export interface UnitDefinition {
4246
4243
  baseName?: string
4247
4244
  }
4248
4245
 
4249
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
4246
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4250
4247
  export interface Index {}
4251
4248
 
4252
4249
  export interface PartitionedMap<T, U> {