Often I end up using Math.sqrt in projects whenever I need to get the square root of a number. However what if I want the nth root of a number? Such as the cubed root of a number, or any other degree beyond of that of just the number 2 that is what I am set with when using the Math sqrt method. I can not say that I end up having to use this kind of method that often, but still there does not seem to be a built in mMath object method for it.
One solution is to use the Math.pow method to get the nth root of a given root number and degree.
This works by just passing the root number as the base for Math.pow, and then diving 1 by the degree number to get the exponent argument for Math.pow like so.
So there we have it a basic nth root method that seems to work they way it should. However what is the big deal with nth root? Is there some kind of project where a Math method such as this would come into play? I Guess now it is a question of looking for and see about making artful and practical use case examples of nth root.
I am sure that there are many use case examples of nth root, but I would not be surprised if the bulk of them are artful examples. There is however at least a few practical examples of nth root however, one such example might have to do with compounding interest. For example what if I want to know an interest rate that I need to see in order to double an investment of one hundred dollars over say seven years? I can pass 2 for the value of n, and 7 for the degree and get a value of around 1.104, or in another way 10.4%. I can then confirm this by using that value with the Math.pow method to see if it results in double the money, and when I do it indeed does given me just that.
I can not say that I end up using this often in projects, but it is something that I think about now and then. If I find out some other ways to go about using nth root in projects that are helpful, or at least interesting I will be sure to update this post.
There is just having the basic idea at the ready though, which is one reason why I wrote this post. I like to have methods like this at the ready. In time I hope to find, and or make interesting code examples that make use of nth root and other Math methods. I am sure that there is some fun and interesting things that can be done with it when it comes to something artful.