BigDecimal implementation in OpenJDK is very well written and quite fast, compared to other similar libraries. There is no much reason to reimplement it. It is very hard to do a general-purpose (sic!) arbitrary precision arithmetics library that is so fast. Engineers who wrote it did a very good job.

However, you can do better if you don’t need a general-purpose library, but have some particular set of constraints. For example, in this repo I implemented an Int96 integer type based on 3 ints to solve the problem I had at hand (the problem is explained in readme). Using a general-purpose BigInteger type was too slow. It still took a couple of days on my machine to find a solution, whereas with BigInteger I had no chance to arrive at the answer in a reasonable time.

Written by

Project Lead for the Kotlin Programming Language @JetBrains

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store