Using mathjs as a more advanced alternative the the Core JavaScript Math Object
When it comes to doing anything with math in javaScript there is of course the core javaScript Math object that is very helpful. The Object is packed with a whole bunch of usual suspects when it comes to all kinds of things that have to do with Math such as sin, cosine, a PI constant, and so forth. However the Native Math object does have itâ€™s limitations, and does not always work the way I would like it to. I find myself often having ti create a few stand alone methods sometimes such as a nth root method, and also look around for something to help with big number support. There are also many methods missing that have to do with things that have to do with statistics when it comes to things like the various kinds of means, and standard deviation.
A popular alternative to the corejs Math object is math.js, which can be found on npm, and github like most projects. The mathjs module can do everything the Math object can, however it also adds a whole bunch of new features such as big number support. When it comes to native javaScript there is now a native Big Number standard, but it still might now work great in all browsers. In addition certain mathjs equivalents to the Math object methods have additional features, and also a plug in system exists that can be used to further extend mathjs.
1  Installing mathjs and some basic points
Mathjs can be used as a front end solution, as well as in node.js, however in this post I will be mainly going over few nodejs examples. When I first started writing this post I was using mathjs 4.x, and the last time I edited this post there is now a 9.x, so if you run into problems getting some of these examples to work on your end check the version number that you are using first. So then in a node.js environment just install with npm like always when starting a new npm folder.


1.1  Cloning down my test mathjs folder that I made for this post
Another option would be to clone down the git folder that I made for this post.


1.2  using mathjs in place of the Math Object
I tend to favor using mathjs separately as an alternative to the Math Object in core javaScript, rather than monkey patching the Math Object. This means I will have two globals, one lower case, and one upper case. However once goes about importing mathjs the global variable should be separate from the native Math object.
1.3  Plug in system
The mathjs module has a plug in system, and there are additional projects that wok well with mathjs when it comes to getting into a certain discipline involving math. Of course it is not that hard to add my own functionality as well if I cant fine something.
2  The natural logarithm method
For starters I checked out the mathjs natural logarithm method, and have found that it is an improved alternative over the native Math.log method as it can also be used to find base log.
The improvement has to do with base log


With math.js I can just give a second argument


3  mathjs pow method
If you are still wondering what base log is, just think of it as the opposite of using Math.pow. Where I want to find an unknown exponent given a number and base, rater than finding an unknown number given a base, and exponent.


4  Big Numbers
Another major feature of mathjs is a big number constructor.


5  Conclusion
As of this writing it would seem that Mathjs is still being supported which is great. I do get around to editing my nodejs content once in a while, so next time I come around to this post I hope to expand it with at least a few more additional examples.