Course


Boost Multiprecision

Learn how to do multi precision computation with Boost

Big Integer in C++ and Boost

We can use big integer datatype. We can use different datatypes like int128_t, int256_t, int1024_t etc. By using this we can get precision up to 1024 easily.

C++ (GCC 9.2.0)
  • Input  

Multiprecision with Boost

We can use any precision using cpp_int datatype. It automatically assigns precision at runtime. For example, let's find out factorial (50) which is improssible to do with normal C++ or STL.

C++ (GCC 9.2.0)
  • Input  

Using multi-precision float, we can get precision up to 50 and 100 decimal places. For this we can use cpp_float_50 or cpp_dec_float_100 respectively. Let us see the example to get the better idea.

C++ (GCC 9.2.0)
  • Input  

What is Boost?

Boost is a large collection of high-quality libraries intended for use in C++. They are free and cover a large variety of categories. Boost is often considered a "second standard library", and many C++ problems are resolved by using Boost. Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.boost.org. Boost covers every corner of programming, and continues to be improved and expanded.

It includes libraries for:

  • String and text processing
  • Containers
  • Iterators
  • Algorithms
  • Function objects and higher-order programming
  • Generic Programming
  • Template Metaprogramming
  • Preprocessor Metaprogramming
  • Concurrent Programming
  • Math and numerics
  • Correctness and testing
  • Data structures
  • Image processing
  • Input/Output
  • Inter-language support
  • Memory
  • Parsing
  • Programming Interfaces
  • Miscellaneous
  • Broken compiler workarounds

The best part about Boost is that most of its libraries are header-only, so there's nothing to compile or link to. Simply download it, extract it into your favorite directory, tell your compiler where to find it, and use it!

However, there are some libraries that need to be compiled. These libraries are generally more heavy-weight, and/or rely heavily on platform-specific functionality. The libraries that need to be compiled are:

  • Date Time
  • Filesystem
  • Graph
  • Iostreams
  • Math/Special Functions*
  • MPI
  • Program options
  • Regular Expressions
  • Serialization
  • Signals
  • System
  • Test
  • Thread
  • Wave

Boost provides instructions on how to do this, and the process is mostly automated. Once built, most libraries will be automatically linked, if possible.

Scientific Computing Essentials