kotlin-multiplatform-bignum icon indicating copy to clipboard operation
kotlin-multiplatform-bignum copied to clipboard

Added some series-based functions (exp, cos, sin, ...)

Open hakanai opened this issue 2 years ago • 6 comments

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)

hakanai avatar May 26 '22 07:05 hakanai

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. :(

hakanai avatar May 26 '22 07:05 hakanai

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 26 '22 07:05 CLAassistant

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.

ionspin avatar May 26 '22 11:05 ionspin

I haven't forgotten about this, but I'm still short on time. It's top of my priority list for the library.

ionspin avatar Jun 19 '22 12:06 ionspin