ionspin / kotlin-multiplatform-bignum

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

Support for radices other than 10 #236

Open hakanai opened 2 years ago

hakanai commented 2 years ago

Is your feature request related to a problem? Please describe.

The calculator app I've written (not currently using this library, but I'm certainly considering it) currently works in bases 10 and 12, and I'm considering adding support for base 16.

BigDecimal is (as the name says) only for base 10, not allowing me to pass in a radix.

Describe the solution you'd like

A BigNumber class or similar where the radix can be specified would be ideal. BigDecimal could possibly remain as a specialisation of a big number for base 10, but any radix-independent methods could be moved to the superclass.

Describe alternatives you've considered

a. do all the maths in decimal and convert each way. I'd get rounding errors here and there, but it can't be any worse than using double precision. b. make my own BigRational or BigNumber utilities, possibly building on top of BigInteger.