A fast, portable C++ library for multi-precision integer math.Copyright 2010 by Chad Nelson
What is it?
It's a C++ library that lets your program handle much, much larger integer numbers than the built-in
long, or even
long long types, and handle them using the same syntax that C and C++ use for the built-in integer types.
The maximum size of the integer is limited only by the memory available to store it. In practice that's millions of hexadecimal digits, so it's effectively infinite.
- This is not (yet) an official Boost library.
Why would I use it?
- Because it's completely portable. It's written entirely in modern C++, with many different types of operating system, compiler, and hardware in mind. It will compile cleanly on many operating systems without any changes, automatically adapting to the most efficient native integer sizes available.
- Because it's fast. Speed of execution takes a back seat to portability, so it doesn't include things like assembly-language modules to wring every last CPU cycle out of it -- but it's still pretty darn fast.
- Because it has the features you need. Modular arithmetic. Fixed- or variable-length integer types. Cryptographically-secure prime number generation. Bit manipulation functions. Exception- or error-code-based operation. A friendly and intuitive interface. Thread-safe operation (which can be disabled for maximum speed). Complete and carefully maintained documentation. What more could you want?
- Because it's open-source. You can see exactly how it works. You can never be left high and dry because the company that made it goes out of business, or decides that it's not profitable to maintain it. If you find a bug that isn't fixed fast enough for you, you can fix it yourself, no waiting for someone else to get around to it.
- Because it's closed-source-friendly and commercial-friendly. It's licensed under the Boost Software License 1.0 (which you can find at http://www.boost.org/LICENSE_1_0.txt), an OSI-approved open-source license that permits you to use it for pretty much anything you want, and doesn't make any anti-commercial or anti-closed-source demands.
How do I use it?
That's the best part. If you've installed the Boost library already, all you need to do is add
#include <boost/xint/xint.hpp> at the top of your source code file and declare your variable as type
boost::xint::integer. Then just use it the way you'd use any integer. If you need something more advanced, take a look in the reference section and you just might find it.
More information on how to use it can be found on the pages listed below.
Detailed Usage Information: