-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement pow #12
Comments
I've been working on some vector stuff and needed your library to get around the whole floating-point issue. Despite using your library in other projects, I never needed precision powers or roots, so I came to the repo to just double check and didn't find those features. I was going to open a new Issue, and seen you already did. Anyways, I did some research on how to calculate, technically approximate, powers and roots, and put together the functions bellow. It allows for "Imaginary Numbers", although it really just uses the absolute value of the Base, then negates the sign before returning the result. Similarly, negative exponents will take the reciprocal of the resulting power.
I'm hesitant to fork the project and try to implement this myself, but I hope @royNiladri or any other contributors will find this helpful. Given the robustness of the codebase, I'm sure the core functions can be used as to replicate these methods without needing to add too much more. |
Hi. If you have some bandwidth, do you mind creating a pull request with your suggested changes? We can integrate it in the library then🙂 |
I can do so maybe tonight. It definitely needs to be refined and heavily tested. The method tends to throw itself into an infinite loop in certain cases, but I came across a few way to do the approximations, so if this method doesn't work out, I'll try the others. I'll update this issue as I progress in the meantime. Don't want to submit a pull request that introduces something that may completely change. |
Update: I got it to work but some fractional exponents cause the recursive nth-root I'll push an integer exponent only version tonight and submit a pull request on that. Tomorrow I'll try to implement a Taylor series method that doesn't use the reclusive As a side note, the Taylor series method will allow the user to define the number of steps in the logarithm, equating to the amount of precision (more so accuracy within one or two decimal places at the end). Given everything, I was able to find, most math libraries and API's use these methods behind the scenes, so it would be realistically no different than using those with the added advantage of using the precision of the functions in this project. |
Hi @Jsoto22 , It would be great if you can wrap up the whole thing before we publish, but if you have time crunch, do let me know, we will publish in current state with notes in readme about what currently works, and what is pending implementation. Once again, thanks for taking this up! :) |
@royNiladri You're welcome and will do. |
Raise a number to another number. Both can be non integer and cases resulting in imaginary number [like bigDecimal.pow(-21, 0.5)] should throw an error.
The text was updated successfully, but these errors were encountered: