Multiplatform bigint library

My project is a programming language that is implemented as a Kotlin multiplatform application. In my language, I needed to provide native bignum support, but I didn’t find any multiplatform implementation of BigInt.

Of course, Java has BigInteger, JS has BigInt and in native code you have GMP. I have written a library that wraps these different implementations and presents a general API to work with bigints. Here’s an example:

val a = BigInt.of("10000000000000000000000000000000")
val b = 2
val c = a + b
println(c.toString())

This will of course print 10000000000000000000000000000002.

For native code, I have only tested this on Linux. I’m sure it’d be trivial to get it to run on Windows and OSX, but I don’t have any machines available to test this. However, if anyone needs this, I’ll be happy to integrate any pull requests.

Currently the project is a submodule of my programming language, but if there is an actual interest in this, I could break it out into its own project.

Here’s the code: array/mpbignum at master - array - Codeberg.org

2 Likes

You should probably have used search on this forum since the question was risen multiple times. There are several multiplatform implementations of BigInt. You are welcome to discuss it in Kotlin Slack mathematics channel.

1 Like