1 /////////////////////////////////////////////////////////////// 2 // Copyright 2012 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 // 7 // Compare arithmetic results using fixed_int to GMP results. 8 // 9 10 #ifdef _MSC_VER 11 # define _SCL_SECURE_NO_WARNINGS 12 #endif 13 14 //[mixed_eg 15 #include <boost/multiprecision/cpp_int.hpp> 16 main()17int main() 18 { 19 using namespace boost::multiprecision; 20 21 boost::uint64_t i = (std::numeric_limits<boost::uint64_t>::max)(); 22 boost::uint64_t j = 1; 23 24 uint128_t ui128; 25 uint256_t ui256; 26 // 27 // Start by performing arithmetic on 64-bit integers to yield 128-bit results: 28 // 29 std::cout << std::hex << std::showbase << i << std::endl; 30 std::cout << std::hex << std::showbase << add(ui128, i, j) << std::endl; 31 std::cout << std::hex << std::showbase << multiply(ui128, i, i) << std::endl; 32 // 33 // The try squaring a 128-bit integer to yield a 256-bit result: 34 // 35 ui128 = (std::numeric_limits<uint128_t>::max)(); 36 std::cout << std::hex << std::showbase << multiply(ui256, ui128, ui128) << std::endl; 37 38 return 0; 39 } 40 //] 41 42 /* 43 44 Program output: 45 46 //[mixed_output 47 48 0xffffffffffffffff 49 0x10000000000000000 50 0xFFFFFFFFFFFFFFFE0000000000000001 51 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE00000000000000000000000000000001 52 53 //] 54 */ 55 56