ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
345 stars 41 forks source link

[Question] Lacking advanced math features #199

Open JoonasC opened 2 years ago

JoonasC commented 2 years ago

Currently this library is lacking advanced math features, such as: sin, cos, sqrt, nroot, log, etc.

Are these within the scope of this library?

If not, what workaround would you suggest?

ionspin commented 2 years ago

Hi @JoonasC , This is also related to issue #41.

I'd definitely say that it is in scope of the library, and BigInteger has at least sqrt implemented, but the rest are unfortunately missing. Currently I don't have time to implement them, so contributions are welcome!

As for a workaround, apart from implementing these operations possibly as extension functions or even better contributing them to the code :smiley: , I don't have anything concrete to suggest.

abudden commented 1 year ago

I can't offer any help with this as my kotlin skills aren't good enough, but this java BigDecimal repository might be a useful reference source for anyone willing to have a go: https://github.com/eobermuhlner/big-math

hakanai commented 1 year ago

You've seen the PR, right? The code in there is pretty much inspired by theirs. ;)

They too have some very arbitrary magic numbers for how much precision to add for each operation. That's the one thing that made it both hard to understand and unclear how to map to this library. Doubly baffling, because if you go and look at code for something else like bc, the magic numbers for how much precision to add aren't even the same. (So presumably, one of them is wrong? But which one?)

Sorting out the actual precision requirements for each function is probably the sole thing making it hard. If someone were to go through and say that so and so function needs so much precision when doing each step, someone else could just go through and churn the code out.

ionspin commented 1 year ago

Here is the pull request in question, https://github.com/ionspin/kotlin-multiplatform-bignum/pull/235 which I unfortunately still haven't had time to dive into, as it's related to precision refactoring, and I'm trying to launch an MVP for my startup at the same time. Once again, haven't forgotten about it, just no time :(