Here you can find implementations of the most efficient algorithms to compute
- the factorial function,
- the double factorial function,
- the binomial function.
See also this nice overview.
Additionally you can find in this repository
-
a small database of factorial algorithms which let you quickly find the most appropriate version for your needs.
-
An efficient sieve of Eratosthenes implemented in an object-oriented way.
- Project MpirBasedFunctions : C++
- Project SilverFactorial64 : C#
- Project JavaFactorial : Java
- Project GoFactorial : Go
The C# and the Java version come with a small benchmark program. Here a screenshot of the Java version and a screenshot of the C# version.
To browse the code the following two pages might be more convenient: primes and factorials.
If you want to port the algorithms to other languages the C# version is recommended as the point of departure. The benchmarks indicate that it is a good idea to start with the swing algorithm or (more demanding to implement, but at least twice as fast) the prime swing algorithm.
A good starting point for the binomial function is here.
To build the sources you need for
-
The C# version can be configured to use System.Numerics.BigInteger or to use the MPIR library (an interop is provided).
-
The Java version needs Mikko Tommila's Apfloat library. If you want to compile the benchmark program additionally Karsten Lentzsch's JGoodies is needed.
Sonia Keys ported the algorithms to Go.
Please notify me of any bugs. Want to contribute new algorithms? Great, please contact me. If you already ported to some other language (Scala, F#, Phython, Ruby, Lisp) then please send me your code so I can incorporate it into this repository.