Today, I completed the first version of BigIntegerCPP, a C++ Big Integer Library. It is meant to be an equivalent of Java’s BigInteger Class. The main purpose of this library is to perform basic arithmetic operations on integers which would not normally fit in a 64 bits integer (unsigned long long).
It took me some time to turn my own code into something publishable to the public. It definitely wasn’t as easy as I expected. The source code is now downloadable from my github account. Feel free to fork the project and add your own code. You can also download the source code directly as a zip file.
The library was built to be used intuitively as if you are doing regular integers arithmetic. First, create the integers you are planning to perform the operations on:
BigInteger a("35742549198872617291353508656626642567"); BigInteger b("1298074214633706835075030044377087");
The addition and multiplication can be then performed naturally:
BigInteger c = a + b; BigInteger d = a * b;
The library supports the C++ ostream operator “<<“. So, a code to display the big integers would look something like this:
cout << a << " + " << b << " = " << c << endl; cout << a << " * " << b << " = " << d << endl;
Be aware that this is the very first version of the library. Therefore, I cannot guarantee any level of quality in terms of correctness or efficiency. I will appreciate it if you report any bugs you find in the comments and include the test case where the library failed.