kotlin-multiplatform-bignum
kotlin-multiplatform-bignum copied to clipboard
Added some series-based functions (exp, cos, sin, ...)
Added:
- exp (by infinite series)
- cos (by infinite series)
- sin (by infinite series)
- tan (by cos/sin)
- cosh (by infinite series)
- sinh (by infinite series)
- tanh (by cosh/sinh)
Not added:
- ln - might not be too hard but converges very slowly so need another trick
- arcsin(x) = arctan(x / √(1 - x²))
- arccos(x) = arctan(√(1 - x²) / x)
- arctan - conceivably possible to do similarly, but the series only converges for small values, so need to use Euler's trick
- arsinh(x) = ln(√(1 + x²) + x)
- arcosh(x) = ln(x + √(x - 1)√(x + 1)) = ln(√(x² - 1) + x)
- artanh(x) = ½ ln(x + 1) - ½ ln(1 - x)
I'm still unsure about the way I handled precision here.
I could have tried to use the precision of the number used as input, but the problem is that the decimal mode can currently be null
, which can't work for these things because they always need to know when to stop.
Also I haven't actually signed the commit, but it isn't a complete solution either, so I'll worry about that if it gets even remotely close to usable. :(
Awesome, thanks for the contribution! It will take me some time to go through it in detail and understand everything so please have patience, especially since I can only get some time to work on the library on the weekend. And don't worry about the signature.
The decimal mode was long overdue for a refactor so I'll try to combine that with changes here.
I haven't forgotten about this, but I'm still short on time. It's top of my priority list for the library.