221 Commits

Author SHA1 Message Date
Glen Whitney
8c659a86cd
fix: respect tolerances in function isInteger (#3575) 2025-10-31 09:10:07 +01:00
Glen Whitney
faf249b6c0
feature: add function bernoulli to calculate Bernoulli numbers (#3551) 2025-10-29 10:47:11 +01:00
Richard Taylor
92152117f5
Fix: don't throw exception when filter/map/forEach an empty array (#3567)
Removes out-of-bounds access to first element in optimizeCallback when
  the provided array/matrix is empty. Also adds numerous unit tests for such
  edge cases, and fixes a previously unreported internal bug in SparseMatrix,
  violating its own invariants on empty matrices.

  Resolves #3564.
---------

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
2025-10-27 00:39:35 -07:00
Glen Whitney
9ee2a00877
feat: implement functions isFinite and isBounded (#3554) 2025-10-18 13:17:14 +02:00
Jos de Jong
8c783a9461 Merge branch 'develop' into v15
# Conflicts:
#	HISTORY.md
#	test/unit-tests/type/matrix/Index.test.js
2025-10-10 09:09:40 +02:00
David Contreras
5a8eb1064a
fix: #3541 throw an error when evaluating a range with a step of zero (#3548) 2025-10-10 08:31:41 +02:00
Jos de Jong
302ed812e1
fix: #3529 change function size to always return an Array (#3535) 2025-10-09 10:33:15 +02:00
Jos de Jong
338dfe9ae3
fix: #3530 throw an error when trying to flatten a SparseMatrix (#3536) 2025-10-08 08:17:25 -07:00
Josh Kelley
4ec99fc022
fix: typos in code comments (#3544) 2025-10-01 11:50:17 +02:00
Jos de Jong
1e3c2a99aa Merge branch 'develop' into v15
# Conflicts:
#	HISTORY.md
2025-09-24 11:25:19 +02:00
Ikem
0b84ce264d
feat: add nullish coalescing operator support (#3497)
Resolves #3353.

* test: enhance nullish coalescing tests for arrays, matrices, and conditional expressions

* docs: add nullish coalescing operator precedence details and update syntax documentation
---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
2025-09-17 19:49:15 -04:00
kyle-compute
aedbee550d
fix: #3512 sign of zero not returning zero in case of a fraction
* sign of zero fraction should return 0/1 instead of 1/1

* moved fraction zero test into correct fraction block

* moved fraction zero test into correct fraction block
2025-07-24 09:21:05 +02:00
David Contreras
10602fdbfd
feat: matrix subset according to type of input (#3485) 2025-07-16 10:40:13 +02:00
Jacopo Mercolini
8d19c8b51e
feat: toBest(unit, unitList, offset) function (#3484)
* feat: toBest tests

* feat: toBest function initial

* fix: tests and function changes

* fix: dependencies

* new way to handle

* updated tests

* test updated

* tests fixed

* cleaned useless tests

* cleaned useless condition

* fix: missing comments

* fix: moved tests

* other fix and clean

* change test to work with npx mocha "path" -g "toBest"

* deleted check large and small value

* deleted precision test and fix options to bestprefix

* fix: moved toBest tests in correct file

* fix: math create

* fix: aligned files pre-mr

* fix: toBest docs test

* fix: lint issues

* fix: comments

* fix: added a helper function to simplify the test readability

* fix: unit.md and units.md docs updated

* fix: test on units.length

* added post process denormalize for tobest function to string returned value

* removed this.clone into format

* feat improve incompatible units test

* fix assign prefixes

* fixed examples

* changed order of params of assertUnit

* fixed comments and added toBest in knowProblems at doc.test

* refactor: update toBest functionality and adjust related tests for accuracy

* refactor: remove unnecessary offset initialization in prefix application

---------

Co-authored-by: Luca Quercetti <l.quercetti@wecodeyou.it>
Co-authored-by: Elia Alesiani <elia.alesiani@gmail.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Co-authored-by: lucaQ <lucaquercetti@gmail.com>
Co-authored-by: EliaAlesiani <105418798+EliaAlesiani@users.noreply.github.com>
2025-07-09 19:16:47 +02:00
Jos de Jong
8e76654c7f Merge branch 'develop' into v15
# Conflicts:
#	AUTHORS
#	HISTORY.md
2025-06-04 10:45:11 +02:00
Delaney Sylvans
7a617b1ee2
fix: support multiplication of arrays with units (#3456) 2025-05-28 17:00:58 +02:00
Glen Whitney
72a2442c32
Feat: Enhance Kronecker product to handle arbitrary dimension (#3461)
Previously `math.kron()` always returned a 2D matrix, and could not handle 3D or greater arrays. Now it always returns an array of the max dimension of its arguments.

Resolves #1753.
---------

Co-authored-by: Delaney Sylvans <delaneysylvans@gmail.com>
2025-04-22 17:08:21 -07:00
Orel Ben Neriah
4039df04ca
fix: #3387 use utility isNaN for consistent max and min results (#3389)
* fix: use utility isNaN for consistent max and min results

* test: add NaN comparison cases for larger and smaller functions

* docs: update descriptions for larger, smaller, max, and min functions to clarify NaN behavior

* refactor: rename isNaN to mathIsNaN for extra clarity

---------

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2025-02-28 15:19:28 +01:00
Glen Whitney
127ea626fc
feat: #3041, #3340 rename apply to mapSlices (#3357)
* chore: Rename `apply` to `mapSlices`

  This renaming conforms with the Julia name for the function formerly
  called `apply`, and allows it to be called from the expression parser.
  The previous name `apply` is kept as an alias for `mapSlices`, for
  backward compatibility. This commit implements an `alias` metadata
  property for function factories to facilitate the `apply` alias for
  `mapSlices`.

  As a separate bonus, this PR corrects several typos in function docs
  and removes now-passing doc tests from the list of "known failing" doc
  tests to get down to 45 known failures and 136 total issues in doc tests.
  (Most of the excess of 136 as compared to 45 are just due to roundoff
  error/slight inaccuracy of what the documentation claims the result will
  be and the actual result returned by mathjs. When the 45 are eliminated,
  a reasonable numeric tolerance can be decided on for doc testing and
  then the doc tests can be made binding rather than advisory.

* refactor: changes per PR review

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2025-01-30 13:19:23 +01:00
Glen Whitney
1a85b8796a
fix: #3360 add bigint support to matrix indices and ranges (#3361)
* fix: Accept bigints as matrix indices and range params, demoting to number

* feat: bigint support in range(), clarify demotion in Range()

* feat: range() support Fraction, better errors for single non-string argument

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2025-01-30 13:07:24 +01:00
Glen Whitney
773a5c5cff
fix: #3247 don't override type-native floor/ceil within tolerance of value (#3369)
* fix: Don't override type-native floor/ceil when within tolerance of value

* refactor: extend bigint safety to round and fix

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2025-01-30 12:55:44 +01:00
Glen Whitney
8510b850ad
fix: handle bigints properly in more cases (#3345)
* fix: Handle bigints properly in more cases
  * Allow a bigint to appear in a max/min of nonhomogeneous arguments
  * If randomInt is called with a bigint or a pair of bigints, return
    a bigint.
  * Preserve uniformity of results if randomInt is called with a very large
    range.
  * Extend log, log2, and log10 to bigints
  * Add tests for all of the above issues.
  * Bonus: fix one JSDoc comment issue. If every PR fixes one, we will soon
    get through the 150+

* fix: Refactors per comments and 1 bonus doc test (isInteger)

* chore: fix lint

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2025-01-24 10:59:13 +01:00
Paul Korzhyk
e0d56d2da7
fix: make derivative much faster (#3322) 2024-11-28 13:37:42 +01:00
Jos de Jong
52bcd8fee0 feat: upgrade to fraction.js@5.2.1 and implement support for log(x: Fraction, base: Fraction) 2024-11-20 11:57:10 +01:00
Jos de Jong
e93780e6d5 Merge branch 'develop' into v14 2024-11-20 11:41:30 +01:00
Jos de Jong
67ddc724e1 fix: #3260 improve type definitions and documentation on the callback indices of map, filter, and forEach 2024-11-20 11:32:11 +01:00
Jos de Jong
e00d3678c6 fix: #3323 support functions in function clone 2024-11-20 10:34:59 +01:00
Jos de Jong
301d00e8a5
feat: upgrade to fraction.js@5 (#3312) 2024-11-06 17:25:31 +01:00
Jos de Jong
22db7d2df3 Revert "feat: upgrade to fraction.js@5 (#3283)"
This reverts commit 9b81230950b5bed113817dc4ec7803df7e51313e.
2024-11-06 17:14:16 +01:00
Jos de Jong
9b81230950
feat: upgrade to fraction.js@5 (#3283) 2024-11-06 17:08:26 +01:00
Akki
66775ee8b5
fix: #3219 updated matAlgo07xSSf algorithm to return sparse matrix (#3307) 2024-11-06 17:02:02 +01:00
Orel Ben Neriah
9dca98b0c3
feat: adds unit support to ceil, floor, and fix functions (#3269)
BREAKING CHANGE:
The matrix types now support generics. For most practical cases, this doesn't cause a breaking change, but it is possible that it breaks typings in some specific edge cases.
2024-10-21 12:50:17 +02:00
Jos de Jong
d1ecf44e2f fix: #3253 cannot use identifiers containing special characters in function derivative 2024-09-04 12:19:46 +02:00
David Contreras
bcf0da46f0
feat: support multiple inputs in function map (#3228) 2024-08-22 13:35:21 +02:00
David Contreras
459ae13725
docs: spelling fixes in the embedded docs (#3252)
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-08-21 14:30:40 +02:00
David Contreras
c8e4bbd573
fix: function map not always working with matrices (#3242)
* Removed maxArgumentCount in favor of applyCallback

* Making a pure _recurse function

* Added cbrt tests, removed unnecesary changes in functions.

* Fixed main bottleneck

* Restored back function before unintended change

* Fix format

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-08-01 15:54:20 +02:00
David Contreras
cf24943d4c
feat: add matrix datatypes in more cases (#3235) 2024-07-30 19:48:19 +02:00
Vistinum
975d1ba800
fix: use exact values for US liquid volume units (#3229)
1 US gallon is defined as 231 cubic inches, which is exactly 3.785411784 L (since 1 inch is defined as 25.4 mm). Other units are defined against the gallon.

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-07-11 13:16:46 +02:00
David Contreras
5785cb95f1
Broadcast refactor (#3220) 2024-06-19 18:51:37 +02:00
Jos de Jong
ab3461d484
feat: implement support for bigint (#3207, #2737) 2024-05-31 12:43:09 +02:00
Jos de Jong
1f05a35d68
chore: convert CJS files to ESM (#3204) 2024-05-22 08:46:14 +02:00
Jos de Jong
31b68ced13 chore: adjust isPositive, isNegative, and isZero to the new relTol and absTol 2024-05-15 11:12:19 +02:00
David Contreras
eded7e1dc3
feat: nearly equal with relative and absolute tolerance (#3152)
* nearlyEqual with absolute and relative tolerances

* Format

* nearlyEqual for bigNumber

* Added skip for NaN

* Reduce diff a bit

* Issue with examples in jsdcos

* Updated all calls for nearlyEqual

* Fixed failing tests

* Changed epsilon to relTol, absTol

* Changed references to epsilon in docs and tests

* Added warning for config.epsilon

* Fix warning in zeta.test

* Added config test

* Added sinon to test console.warn

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-05-15 10:56:11 +02:00
Jos de Jong
5ee9f6f8d6 Merge branch 'refs/heads/develop' into v13 2024-05-15 10:51:15 +02:00
Laurent Gérin
81d2e71445
fix #3192: function isNaN returns false for NaN units in a matrix or array
* Use referToSelf() to recursively check if various types are NaN in an array or matrix

* fix array test description from isNegative to isNaN

* Add test for units in a matrix

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-04-24 09:31:06 +02:00
Jos de Jong
a41def8360 fix: #3172 simplify "true and true" 2024-03-13 14:25:56 +01:00
Jos de Jong
f37d4154ad Merge branch 'develop' into v13 2024-02-22 17:19:48 +01:00
Jos de Jong
f504ffe1d3 chore: update devDependencies (most notably eslint) 2024-02-22 16:27:24 +01:00
Brian Fugate
85b65da6cb
Fix: #3100 function round not handling round-off errors (#3136)
* Fixing rounding bug from issue 3100

* Corrected syntax and converted if...else to logic using ternary operator

* Removing nearlyEqual comparison because a false
return value was mathematically impossible by
user input.

Adding dynamic epsilon logic to cover cases when
a user requests to round a number to a higher
precision than epsilon in the config file.

Also adding tests to cover dynamic epsilon cases.

* Removing dynamic epsilon and adding test for changing config.epsilon during runtime

* Reintroducing nearly equal verification for
round function.

Adding test case for changing epsilon at runtime.

Both tests for changing epsilon at runtime also
verify the false nearlyEqual scenario.

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-02-22 16:17:05 +01:00
David Contreras
e1817baa0b
Determinant with small numbers fix (#3139) 2024-02-14 17:49:07 +01:00