1 /////////////////////////////////////////////////////////////// 2 // Copyright 2011 John Maddock. Distributed under the Boost 3 // Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt 5 6 #include <boost/multiprecision/cpp_int.hpp> 7 #include <iostream> 8 t1()9void t1() 10 { 11 //[cpp_int_eg 12 //=#include <boost/multiprecision/cpp_int.hpp> 13 //=#include <iostream> 14 //= 15 //=int main() 16 //={ 17 using namespace boost::multiprecision; 18 19 int128_t v = 1; 20 21 // Do some fixed precision arithmetic: 22 for(unsigned i = 1; i <= 20; ++i) 23 v *= i; 24 25 std::cout << v << std::endl; // prints 2432902008176640000 (i.e. 20!) 26 27 // Repeat at arbitrary precision: 28 cpp_int u = 1; 29 for(unsigned i = 1; i <= 100; ++i) 30 u *= i; 31 32 // prints 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 (i.e. 100!) 33 std::cout << u << std::endl; 34 35 //= return 0; 36 //=} 37 //] 38 } 39 t3()40void t3() 41 { 42 //[cpp_rational_eg 43 //=#include <boost/multiprecision/cpp_int.hpp> 44 //=#include <iostream> 45 //= 46 //=int main() 47 //={ 48 using namespace boost::multiprecision; 49 50 cpp_rational v = 1; 51 52 // Do some arithmetic: 53 for(unsigned i = 1; i <= 1000; ++i) 54 v *= i; 55 v /= 10; 56 57 std::cout << v << std::endl; // prints 1000! / 10 58 std::cout << numerator(v) << std::endl; 59 std::cout << denominator(v) << std::endl; 60 61 cpp_rational w(2, 3); // component wise constructor 62 std::cout << w << std::endl; // prints 2/3 63 //= return 0; 64 //=} 65 //] 66 } 67 68 main()69int main() 70 { 71 t1(); 72 t3(); 73 return 0; 74 } 75 76