![]() |
VOOZH | about |
Boost Libraries are intended to be widely useful, and usable across a broad spectrum of applications. For example, they are helpful for handling large numbers having a range beyond the long long, long double data type (264) in C++.
Installation
Please refer to this Article for the installation of boost. We can download the zip file. After that, we just need to extract the whole in a specified folder of gcc or we can do this easily by command prompt.
Example Applications
We can efficiently use this library in Competitive Programming but before this, we must ensure that your online judge must support boost. Here are some cool tricks that you can use:
1) Big Integer Data Type: We can use either int128_t, int256_t, int512_t, or int1024_t data type according to your requirement. By using these ones, we can achieve precision up to 1024 easily.
Below C++ implementation code for finding the product of large numbers:
Product of 98745636214564698 * 7459874565236544789 = 736630060025131838840151335215258722
2) Arbitrary Precision Data Type: We can use any precision with the help of the cpp_int data type if we are not sure about how much precision is needed in the future. It automatically converts the desired precision at the Run-time.
Below implementation of C++ code for finding the factorial of 30.
Output:
Factorial of 30 = 265252859812191058636308480000000
3) Multiprecision Float: With Boost Multiprecision float, we can achieve precision up to 50 and 100 decimal with cpp_float_50 and cpp_dec_float_100 respectively.
Below is C++ code to calculate the area of a circle with different precision by using a float, decimal, and cpp_float_50 types:
Float: 4.75292 Double: 4.752915525616 Boost Multiprecision: 4.7529155256159980531876290929438093413108253981451