I recently released version 1.0.1 of elm-natural. I worked on improving the performance of the arithmetic operations, specifically divModBy
, mul
, and exp
.
For divModBy
I switched from a straightforward divide and conquer algorithm to a really neat but complicated divide-and-correct long division algorithm that’s described in this paper.
For mul
I started using the Karatsuba algorithm for sufficiently large numbers. In this case, numbers with more than 1000 base-2^26 digits or a little more than 7000 decimals digits.
Check out GitHub - dwayne/elm-natural at 1.0.1 to see the performance results and to learn how it compares against cmditch/elm-bigint
.
Chrome benchmark reports
The benchmark report for version 1.0.0.
The benchmark report for version 1.0.1.
It was really satisfying to see how division with remainder went from 1,891 runs/second to 10,987 runs/second.