Document developer requirements/guidelines for the Number bundle
#3559 opened on Oct 17, 2025
Description
Recently, I have just been throwing any mathjs methods I create into the number bundle with their standard factories, on the theory that if their factory defines implementations for other types, those will just be ignored when the number-only instance is generated.
However, I was working on adding a scalarDivide() function (which would check if one vector is a scalar multiple of another, e.g., scalarDivide([1.5, 3], [1, 2]) = 1.5 but scalarDivide([2, 3], [1, 2]) = undefined), and I went to add it to factoriesNumber and discovered that neither dotMultiply nor dotDivide is in the number bundle. Yet these operations make perfect sense for ordinary arrays of numbers. So, it would be helpful to have some clarification:
-
What is the criterion for a method to be included in the number bundle? Should
dotMultiplyanddotDividebe added, and the list of functions scanned for others that should be added? Or perhaps are there methods now in the number bundle that should be removed? -
Is there/could there be automated testing for what is and isn't in the number bundle?
-
When does the implementation need to be changed for inclusion in the number bundle vs. when can the same factory just be included in factoriesNumber as in factoriesAny?
This guidance should be added to the "Implementing a new function" section of the README.