cpp_int.hpp 104 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372
////////////////////////////////////////////////////////////////
//  Copyright 2012 - 2022 John Maddock.
//  Copyright 2022 Christopher Kormanyos.
//  Distributed under the Boost Software License,
//  Version 1.0. (See accompanying file LICENSE_1_0.txt
//  or copy at https://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_MP_CPP_INT_HPP
#define BOOST_MP_CPP_INT_HPP

#include <cstdint>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <type_traits>
#include <string>
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/detail/endian.hpp>
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/detail/integer_ops.hpp>
#include <boost/multiprecision/detail/rebind.hpp>
#include <boost/multiprecision/cpp_int/cpp_int_config.hpp>
#include <boost/multiprecision/rational_adaptor.hpp>
#include <boost/multiprecision/traits/is_byte_container.hpp>
#include <boost/multiprecision/cpp_int/checked.hpp>
#include <boost/multiprecision/detail/constexpr.hpp>
#include <boost/multiprecision/detail/float128_functions.hpp>
#include <boost/multiprecision/cpp_int/value_pack.hpp>
#include <boost/multiprecision/detail/empty_value.hpp>
#include <boost/multiprecision/detail/no_exceptions_support.hpp>
#include <boost/multiprecision/detail/assert.hpp>
#include <boost/multiprecision/detail/fpclassify.hpp>

namespace boost {
namespace multiprecision {
namespace backends {

#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4307) // integral constant overflow (oveflow is in a branch not taken when it would overflow)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4702) // Unreachable code (reachability depends on template params)
#endif
#if defined(__GNUC__) && !defined(__clang__)
// see https://github.com/boostorg/multiprecision/issues/413
// and https://github.com/boostorg/multiprecision/issues/431
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

template <std::size_t MinBits = 0, std::size_t MaxBits = 0, boost::multiprecision::cpp_integer_type SignType = signed_magnitude, cpp_int_check_type Checked = unchecked, class Allocator = typename std::conditional<MinBits && (MinBits == MaxBits), void, std::allocator<limb_type> >::type>
struct cpp_int_backend;

} // namespace backends

namespace detail {

template <std::size_t MinBits, std::size_t MaxBits, boost::multiprecision::cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct is_byte_container<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> > : public std::false_type
{};

} // namespace detail

namespace backends {

namespace detail {
   template <std::size_t Value1, std::size_t Value2>
   struct static_unsigned_max
   {
      static constexpr std::size_t value = (Value1 > Value2) ? Value1 : Value2;
   };
} // Namespace detail

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator, bool trivial = false>
struct cpp_int_base;
//
// Traits class determines the maximum and minimum precision values:
//
template <class T>
struct max_precision;

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct max_precision<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >
{
   static constexpr std::size_t value = std::is_void<Allocator>::value ? detail::static_unsigned_max<MinBits, MaxBits>::value
                                                                       : (((MaxBits >= MinBits) && MaxBits) ? MaxBits : SIZE_MAX);
};

template <class T>
struct min_precision;

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct min_precision<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >
{
   static constexpr std::size_t value = (std::is_void<Allocator>::value ? detail::static_unsigned_max<MinBits, MaxBits>::value : MinBits);
};
//
// Traits class determines whether the number of bits precision requested could fit in a native type,
// we call this a "trivial" cpp_int:
//
template <class T>
struct is_trivial_cpp_int
{
   static constexpr bool value = false;
};

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >
{
   using self = cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>;
   static constexpr bool value = std::is_void<Allocator>::value && (max_precision<self>::value <= (sizeof(double_limb_type) * CHAR_BIT) - (SignType == signed_packed ? 1 : 0));
};

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct is_trivial_cpp_int<cpp_int_base<MinBits, MaxBits, SignType, Checked, Allocator, true> >
{
   static constexpr bool value = true;
};

} // namespace backends
//
// Traits class to determine whether a cpp_int_backend is signed or not:
//
template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct is_unsigned_number<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >
    : public std::integral_constant<bool, (SignType == unsigned_magnitude) || (SignType == unsigned_packed)>
{};

namespace backends {
//
// Traits class determines whether T should be implicitly convertible to U, or
// whether the constructor should be made explicit.  The latter happens if we
// are losing the sign, or have fewer digits precision in the target type:
//
template <class T, class U>
struct is_implicit_cpp_int_conversion;

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator, std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
struct is_implicit_cpp_int_conversion<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >
{
   using t1 = cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>;
   using t2 = cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>;
   static constexpr bool value =
       (is_signed_number<t2>::value || !is_signed_number<t1>::value) && (max_precision<t1>::value <= max_precision<t2>::value);
};

//
// Traits class to determine whether operations on a cpp_int may throw:
//
template <class T>
struct is_non_throwing_cpp_int : public std::integral_constant<bool, false>
{};
template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType>
struct is_non_throwing_cpp_int<cpp_int_backend<MinBits, MaxBits, SignType, unchecked, void> > : public std::integral_constant<bool, true>
{};

//
// Traits class, determines whether the cpp_int is fixed precision or not:
//
template <class T>
struct is_fixed_precision;
template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct is_fixed_precision<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >
    : public std::integral_constant<bool, max_precision<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value != SIZE_MAX>
{};

namespace detail {

inline BOOST_MP_CXX14_CONSTEXPR void verify_new_size(std::size_t new_size, std::size_t min_size, const std::integral_constant<int, checked>&)
{
   if (new_size < min_size)
      BOOST_MP_THROW_EXCEPTION(std::overflow_error("Unable to allocate sufficient storage for the value of the result: value overflows the maximum allowable magnitude."));
}
inline BOOST_MP_CXX14_CONSTEXPR void verify_new_size(std::size_t /*new_size*/, std::size_t /*min_size*/, const std::integral_constant<int, unchecked>&) {}

template <class U>
inline BOOST_MP_CXX14_CONSTEXPR void verify_limb_mask(bool b, U limb, U mask, const std::integral_constant<int, checked>&)
{
   // When we mask out "limb" with "mask", do we loose bits?  If so it's an overflow error:
   if (b && (limb & ~mask))
      BOOST_MP_THROW_EXCEPTION(std::overflow_error("Overflow in cpp_int arithmetic: there is insufficient precision in the target type to hold all of the bits of the result."));
}
template <class U>
inline BOOST_MP_CXX14_CONSTEXPR void verify_limb_mask(bool /*b*/, U /*limb*/, U /*mask*/, const std::integral_constant<int, unchecked>&) {}

} // namespace detail

//
// Now define the various data layouts that are possible as partial specializations of the base class,
// starting with the default arbitrary precision signed integer type:
//
template <std::size_t MinBits, std::size_t MaxBits, cpp_int_check_type Checked, class Allocator>
struct cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, false>
    : private boost::multiprecision::detail::empty_value<typename detail::rebind<limb_type, Allocator>::type>
{
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2, bool trivial2>
   friend struct cpp_int_base;

   using allocator_type = typename detail::rebind<limb_type, Allocator>::type;
   using limb_pointer = typename std::allocator_traits<allocator_type>::pointer      ;
   using const_limb_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
   using checked_type = std::integral_constant<int, Checked>;

   //
   // Interface invariants:
   //
   static_assert(!std::is_void<Allocator>::value, "Allocator must not be void here");

   using base_type = boost::multiprecision::detail::empty_value<allocator_type>;

private:
   struct limb_data
   {
      std::size_t        capacity;
      limb_pointer    data;
   };

 public:
   static constexpr std::size_t limb_bits           = sizeof(limb_type) * CHAR_BIT;
   static constexpr limb_type   max_limb_value      = ~static_cast<limb_type>(0u);
   static constexpr limb_type   sign_bit_mask       = static_cast<limb_type>(1u) << (limb_bits - 1);
   static constexpr std::size_t internal_limb_count =
                                       MinBits
                                           ? (MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0))
                                           : (sizeof(limb_data) / sizeof(limb_type)) > 1 ? (sizeof(limb_data) / sizeof(limb_type)) : 2;
 private:
   union data_type
   {
      limb_data        ld;
      limb_type        la[internal_limb_count];
      limb_type        first;
      double_limb_type double_first;

      constexpr data_type() noexcept : first(0) {}
      constexpr data_type(limb_type i) noexcept : first(i) {}
      constexpr data_type(signed_limb_type i) noexcept : first(static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(i))) {}
#if BOOST_MP_ENDIAN_LITTLE_BYTE
      constexpr data_type(double_limb_type i) noexcept : double_first(i)
      {}
      constexpr data_type(signed_double_limb_type i) noexcept : double_first(static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i))) {}
#endif
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !(defined(BOOST_MSVC) && (BOOST_MSVC < 1900))
      constexpr data_type(limb_type* limbs, std::size_t len) noexcept : ld{ len, limbs }
      {}
#else
      constexpr data_type(limb_type* limbs, std::size_t len) noexcept
      {
         ld.capacity = len;
         ld.data = limbs;
      }
#endif
   };

   data_type m_data;
   std::size_t  m_limbs;
   bool      m_sign, m_internal, m_alias;

 public:
   //
   // Direct construction:
   //
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(limb_type i) noexcept
       : m_data(i),
         m_limbs(1),
         m_sign(false),
         m_internal(true),
         m_alias(false) {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(signed_limb_type i) noexcept
       : m_data(i),
         m_limbs(1),
         m_sign(i < 0),
         m_internal(true),
         m_alias(false) {}
#if BOOST_MP_ENDIAN_LITTLE_BYTE && !defined(BOOST_MP_TEST_NO_LE)
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(double_limb_type i) noexcept
       : m_data(i),
         m_limbs(i > max_limb_value ? 2 : 1),
         m_sign(false),
         m_internal(true),
         m_alias(false)
   {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(signed_double_limb_type i) noexcept
       : m_data(i),
         m_limbs(i < 0 ? (static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i)) > static_cast<double_limb_type>(max_limb_value) ? 2 : 1) : (i > max_limb_value ? 2 : 1)),
         m_sign(i < 0),
         m_internal(true),
         m_alias(false) {}
#endif
   //
   // Aliasing constructor aliases data:
   //
   struct scoped_shared_storage : private boost::multiprecision::detail::empty_value<allocator_type>
   {
    private:
      limb_type*      data;
      std::size_t        capacity;
      std::size_t        allocated;
      bool            is_alias;
      allocator_type& allocator() noexcept { return boost::multiprecision::detail::empty_value<allocator_type>::get(); }

    public:
      scoped_shared_storage(const allocator_type& a, std::size_t len)
          : boost::multiprecision::detail::empty_value<allocator_type>(boost::multiprecision::detail::empty_init_t(), a), capacity(len), allocated(0), is_alias(false)
      {
         data = allocator().allocate(len);
      }
      scoped_shared_storage(const cpp_int_base& i, std::size_t len)
          : boost::multiprecision::detail::empty_value<allocator_type>(boost::multiprecision::detail::empty_init_t(), i.allocator()), capacity(len), allocated(0), is_alias(false)
      {
         data = allocator().allocate(len);
      }
      scoped_shared_storage(limb_type* limbs, std::size_t n) : data(limbs), capacity(n), allocated(0), is_alias(true) {}
      ~scoped_shared_storage()
      {
         if(!is_alias)
            allocator().deallocate(data, capacity);
      }
      limb_type* allocate(std::size_t n) noexcept 
      {
         limb_type* result = data + allocated;
         allocated += n;
         BOOST_MP_ASSERT(allocated <= capacity);
         return result; 
      }
      void deallocate(std::size_t n)
      {
         BOOST_MP_ASSERT(n <= allocated);
         allocated -= n;
      }
   };
   explicit constexpr cpp_int_base(limb_type* data, std::size_t offset, std::size_t len) noexcept
       : m_data(data + offset, len),
         m_limbs(len),
         m_sign(false),
         m_internal(false),
         m_alias(true) {}
   // This next constructor is for constructing const objects from const limb_type*'s only.
   // Unfortunately we appear to have no way to assert that within the language, and the const_cast
   // is a side effect of that :(
   explicit constexpr cpp_int_base(const limb_type* data, std::size_t offset, std::size_t len) noexcept
       : m_data(const_cast<limb_type*>(data) + offset, len),
         m_limbs(len),
         m_sign(false),
         m_internal(false),
         m_alias(true) {}
   explicit cpp_int_base(scoped_shared_storage& data, std::size_t len) noexcept
       : m_data(data.allocate(len), len),
         m_limbs(len),
         m_sign(false),
         m_internal(false),
         m_alias(true) {}
   //
   // Helper functions for getting at our internal data, and manipulating storage:
   //
   BOOST_MP_FORCEINLINE allocator_type&       allocator() noexcept { return base_type::get(); }
   BOOST_MP_FORCEINLINE const allocator_type& allocator() const noexcept { return base_type::get(); }
   BOOST_MP_FORCEINLINE std::size_t              size() const noexcept { return m_limbs; }
   BOOST_MP_FORCEINLINE limb_pointer          limbs() noexcept { return m_internal ? m_data.la : m_data.ld.data; }
   BOOST_MP_FORCEINLINE const_limb_pointer    limbs() const noexcept { return m_internal ? m_data.la : m_data.ld.data; }
   BOOST_MP_FORCEINLINE std::size_t              capacity() const noexcept { return m_internal ? internal_limb_count : m_data.ld.capacity; }
   BOOST_MP_FORCEINLINE bool                  sign() const noexcept { return m_sign; }
   void                                       sign(bool b) noexcept
   {
      m_sign = b;
      // Check for zero value:
      if (m_sign && (m_limbs == 1))
      {
         if (limbs()[0] == 0)
            m_sign = false;
      }
   }
   void resize(std::size_t new_size, std::size_t min_size)
   {
      constexpr std::size_t max_limbs = MaxBits / (CHAR_BIT * sizeof(limb_type)) + ((MaxBits % (CHAR_BIT * sizeof(limb_type))) ? 1 : 0);
      // We never resize beyond MaxSize:
      if (new_size > max_limbs)
         new_size = max_limbs;
      detail::verify_new_size(new_size, min_size, checked_type());
      // See if we have enough capacity already:
      std::size_t cap = capacity();
      if (new_size > cap)
      {
         // We must not be an alias, memory allocation here defeats the whole point of aliasing:
         BOOST_MP_ASSERT(!m_alias);
         // Allocate a new buffer and copy everything over:
         cap             = (std::min)((std::max)(cap * 4, new_size), max_limbs);
         limb_pointer pl = allocator().allocate(cap);
         std::memcpy(pl, limbs(), size() * sizeof(limbs()[0]));
         if (!m_internal && !m_alias)
            allocator().deallocate(limbs(), capacity());
         else
            m_internal = false;
         m_limbs            = new_size;
         m_data.ld.capacity = cap;
         m_data.ld.data     = pl;
      }
      else
      {
         m_limbs = new_size;
      }
   }
   BOOST_MP_FORCEINLINE void normalize() noexcept
   {
      limb_pointer p = limbs();
      while ((m_limbs - 1) && !p[m_limbs - 1])
         --m_limbs;
   }
   BOOST_MP_FORCEINLINE constexpr cpp_int_base() noexcept : m_data(), m_limbs(1), m_sign(false), m_internal(true), m_alias(false){}
   BOOST_MP_FORCEINLINE                 cpp_int_base(const cpp_int_base& o) : base_type(o), m_limbs(o.m_alias ? o.m_limbs : 0), m_sign(o.m_sign), m_internal(o.m_alias ? false : true), m_alias(o.m_alias)
   {
      if (m_alias)
      {
         m_data.ld = o.m_data.ld;
      }
      else
      {
         resize(o.size(), o.size());
         std::memcpy(limbs(), o.limbs(), o.size() * sizeof(limbs()[0]));
      }
   }
   // rvalue copy:
   cpp_int_base(cpp_int_base&& o)
      : base_type(static_cast<base_type&&>(o)), m_limbs(o.m_limbs), m_sign(o.m_sign), m_internal(o.m_internal), m_alias(o.m_alias)
   {
      if (m_internal)
      {
         std::memcpy(limbs(), o.limbs(), o.size() * sizeof(limbs()[0]));
      }
      else
      {
         m_data.ld = o.m_data.ld;
         o.m_limbs = 0;
         o.m_internal = true;
      }
   }
   cpp_int_base& operator=(cpp_int_base&& o) noexcept
   {
      if (!m_internal && !m_alias)
         allocator().deallocate(m_data.ld.data, m_data.ld.capacity);
      *static_cast<base_type*>(this) = static_cast<base_type&&>(o);
      m_limbs = o.m_limbs;
      m_sign = o.m_sign;
      m_internal = o.m_internal;
      m_alias = o.m_alias;
      if (m_internal)
      {
         std::memcpy(limbs(), o.limbs(), o.size() * sizeof(limbs()[0]));
      }
      else
      {
         m_data.ld = o.m_data.ld;
         o.m_limbs = 0;
         o.m_internal = true;
      }
      return *this;
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_int_check_type Checked2>
   cpp_int_base& operator=(cpp_int_base<MinBits2, MaxBits2, signed_magnitude, Checked2, Allocator>&& o) noexcept
   {
      if(o.m_internal)
      {
         m_sign = o.m_sign;
         this->resize(o.size(), o.size());
         std::memcpy(this->limbs(), o.limbs(), o.size() * sizeof(*(o.limbs())));
         return *this;
      }
      if (!m_internal && !m_alias)
         allocator().deallocate(m_data.ld.data, m_data.ld.capacity);
      *static_cast<base_type*>(this) = static_cast<typename cpp_int_base<MinBits2, MaxBits2, signed_magnitude, Checked2, Allocator>::base_type&&>(o);
      m_limbs                        = o.m_limbs;
      m_sign                         = o.m_sign;
      m_internal                     = o.m_internal;
      m_alias                        = o.m_alias;
      m_data.ld.capacity             = o.m_data.ld.capacity;
      m_data.ld.data                 = o.limbs();
      o.m_limbs                      = 0;
      o.m_internal                   = true;
      return *this;
   }
   BOOST_MP_FORCEINLINE ~cpp_int_base() noexcept
   {
      if (!m_internal && !m_alias)
         allocator().deallocate(limbs(), capacity());
   }
   void assign(const cpp_int_base& o)
   {
      if (this != &o)
      {
         static_cast<base_type&>(*this) = static_cast<const base_type&>(o);
         m_limbs                        = 0;
         resize(o.size(), o.size());
         std::memcpy(limbs(), o.limbs(), o.size() * sizeof(limbs()[0]));
         m_sign = o.m_sign;
      }
   }
   BOOST_MP_FORCEINLINE void negate() noexcept
   {
      m_sign = !m_sign;
      // Check for zero value:
      if (m_sign && (m_limbs == 1))
      {
         if (limbs()[0] == 0)
            m_sign = false;
      }
   }
   BOOST_MP_FORCEINLINE bool isneg() const noexcept
   {
      return m_sign;
   }
   BOOST_MP_FORCEINLINE void do_swap(cpp_int_base& o) noexcept
   {
      std::swap(m_data, o.m_data);
      std::swap(m_sign, o.m_sign);
      std::swap(m_internal, o.m_internal);
      std::swap(m_limbs, o.m_limbs);
      std::swap(m_alias, o.m_alias);
   }

 protected:
   template <class A>
   void check_in_range(const A&) noexcept {}
};

template <std::size_t MinBits, std::size_t MaxBits, cpp_int_check_type Checked, class Allocator>
constexpr std::size_t cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, false>::limb_bits;
template <std::size_t MinBits, std::size_t MaxBits, cpp_int_check_type Checked, class Allocator>
constexpr limb_type cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, false>::max_limb_value;
template <std::size_t MinBits, std::size_t MaxBits, cpp_int_check_type Checked, class Allocator>
constexpr limb_type cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, false>::sign_bit_mask;
template <std::size_t MinBits, std::size_t MaxBits, cpp_int_check_type Checked, class Allocator>
constexpr std::size_t cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, false>::internal_limb_count;

template <std::size_t MinBits, std::size_t MaxBits, cpp_int_check_type Checked, class Allocator>
struct cpp_int_base<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator, false>
    : private boost::multiprecision::detail::empty_value<typename detail::rebind<limb_type, Allocator>::type>
{
   //
   // There is currently no support for unsigned arbitrary precision arithmetic, largely
   // because it's not clear what subtraction should do:
   //
   static_assert(((sizeof(Allocator) == 0) && !std::is_void<Allocator>::value), "There is curently no support for unsigned arbitrary precision integers.");
};
//
// Fixed precision (i.e. no allocator), signed-magnitude type with limb-usage count:
//
template <std::size_t MinBits, cpp_int_check_type Checked>
struct cpp_int_base<MinBits, MinBits, signed_magnitude, Checked, void, false>
{
   using limb_pointer = limb_type*        ;
   using const_limb_pointer = const limb_type*  ;
   using checked_type = std::integral_constant<int, Checked>;

   struct scoped_shared_storage 
   {
      BOOST_MP_CXX14_CONSTEXPR  scoped_shared_storage(const cpp_int_base&, std::size_t) {}
      BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {}
   };

   //
   // Interface invariants:
   //
   static_assert(MinBits > sizeof(double_limb_type) * CHAR_BIT, "Template parameter MinBits is inconsistent with the parameter trivial - did you mistakingly try to override the trivial parameter?");

 public:
   static constexpr std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT;
   static constexpr limb_type max_limb_value = ~static_cast<limb_type>(0u);
   static constexpr limb_type sign_bit_mask = static_cast<limb_type>(1u) << (limb_bits - 1);
   static constexpr std::size_t  internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0);
   static constexpr limb_type upper_limb_mask = (MinBits % limb_bits) ? (limb_type(1) << (MinBits % limb_bits)) - 1 : (~limb_type(0));
   static_assert(internal_limb_count >= 2, "A fixed precision integer type must have at least 2 limbs");

 private:
   union data_type
   {
      limb_type        m_data[internal_limb_count];
      limb_type        m_first_limb;
      double_limb_type m_double_first_limb;

      constexpr data_type()
          : m_data{0}
      {}
      constexpr data_type(limb_type i)
          : m_data{i}
      {}
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
      constexpr data_type(limb_type i, limb_type j) : m_data{i, j}
      {}
#endif
      constexpr data_type(double_limb_type i) : m_double_first_limb(i)
      {
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
         if (BOOST_MP_IS_CONST_EVALUATED(m_double_first_limb))
         {
            data_type t(static_cast<limb_type>(i & max_limb_value), static_cast<limb_type>(i >> limb_bits));
            *this = t;
         }
#endif
      }
      template <limb_type... VALUES>
      constexpr data_type(literals::detail::value_pack<VALUES...>) : m_data{VALUES...}
      {}
   } m_wrapper;
   std::uint16_t m_limbs;
   bool            m_sign;

 public:
   //
   // Direct construction:
   //
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(limb_type i) noexcept
       : m_wrapper(i),
         m_limbs(1),
         m_sign(false) {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(signed_limb_type i) noexcept
       : m_wrapper(limb_type(i < 0 ? static_cast<limb_type>(-static_cast<signed_double_limb_type>(i)) : i)),
         m_limbs(1),
         m_sign(i < 0) {}
#if BOOST_MP_ENDIAN_LITTLE_BYTE && !defined(BOOST_MP_TEST_NO_LE)
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(double_limb_type i) noexcept
       : m_wrapper(i),
         m_limbs(i > max_limb_value ? 2 : 1),
         m_sign(false)
   {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(signed_double_limb_type i) noexcept
       : m_wrapper(double_limb_type(i < 0 ? static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i)) : i)),
         m_limbs(i < 0 ? (static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i)) > max_limb_value ? 2 : 1) : (i > max_limb_value ? 2 : 1)),
         m_sign(i < 0) {}
#endif
   template <limb_type... VALUES>
   constexpr cpp_int_base(literals::detail::value_pack<VALUES...> i)
       : m_wrapper(i), m_limbs(sizeof...(VALUES)), m_sign(false)
   {}
   constexpr cpp_int_base(literals::detail::value_pack<> i)
       : m_wrapper(i), m_limbs(1), m_sign(false) {}
   constexpr cpp_int_base(const cpp_int_base& a, const literals::detail::negate_tag&)
       : m_wrapper(a.m_wrapper), m_limbs(a.m_limbs), m_sign((a.m_limbs == 1) && (*a.limbs() == 0) ? false : !a.m_sign) {}
   explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_wrapper(), m_limbs(0), m_sign(false)
   {}
   //
   // These are deprecated in C++20 unless we make them explicit:
   //
   BOOST_MP_CXX14_CONSTEXPR cpp_int_base& operator=(const cpp_int_base&) = default;
   //
   // Helper functions for getting at our internal data, and manipulating storage:
   //
   BOOST_MP_FORCEINLINE constexpr std::size_t              size() const noexcept { return m_limbs; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return m_wrapper.m_data; }
   BOOST_MP_FORCEINLINE constexpr const_limb_pointer    limbs() const noexcept { return m_wrapper.m_data; }
   BOOST_MP_FORCEINLINE constexpr bool                  sign() const noexcept { return m_sign; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void         sign(bool b) noexcept
   {
      m_sign = b;
      // Check for zero value:
      if (m_sign && (m_limbs == 1))
      {
         if (limbs()[0] == 0)
            m_sign = false;
      }
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(std::size_t new_size, std::size_t min_size) noexcept((Checked == unchecked))
   {
      m_limbs = static_cast<std::uint16_t>((std::min)(new_size, internal_limb_count));
      detail::verify_new_size(m_limbs, min_size, checked_type());
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void normalize() noexcept((Checked == unchecked))
   {
      limb_pointer p = limbs();
      detail::verify_limb_mask(m_limbs == internal_limb_count, p[m_limbs - 1], upper_limb_mask, checked_type());
      p[internal_limb_count - 1] &= upper_limb_mask;
      while ((m_limbs - 1) && !p[m_limbs - 1])
         --m_limbs;
      if ((m_limbs == 1) && (!*p))
         m_sign = false; // zero is always unsigned
   }

   BOOST_MP_FORCEINLINE constexpr cpp_int_base() noexcept : m_wrapper(limb_type(0u)), m_limbs(1), m_sign(false) {}
   // Not defaulted, it breaks constexpr support in the Intel compiler for some reason:
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(const cpp_int_base& o) noexcept
       : m_wrapper(o.m_wrapper),
         m_limbs(o.m_limbs),
         m_sign(o.m_sign) {}
   // Defaulted functions:
   //~cpp_int_base() noexcept {}

   void BOOST_MP_CXX14_CONSTEXPR assign(const cpp_int_base& o) noexcept
   {
      if (this != &o)
      {
         m_limbs = o.m_limbs;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
         if (BOOST_MP_IS_CONST_EVALUATED(m_limbs))
         {
            for (std::size_t i = 0; i < m_limbs; ++i)
               limbs()[i] = o.limbs()[i];
         }
         else
#endif
            std::memcpy(limbs(), o.limbs(), o.size() * sizeof(o.limbs()[0]));
         m_sign = o.m_sign;
      }
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void negate() noexcept
   {
      m_sign = !m_sign;
      // Check for zero value:
      if (m_sign && (m_limbs == 1))
      {
         if (limbs()[0] == 0)
            m_sign = false;
      }
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR bool isneg() const noexcept
   {
      return m_sign;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void do_swap(cpp_int_base& o) noexcept
   {
      for (std::size_t i = 0; i < (std::max)(size(), o.size()); ++i)
         std_constexpr::swap(m_wrapper.m_data[i], o.m_wrapper.m_data[i]);
      std_constexpr::swap(m_sign, o.m_sign);
      std_constexpr::swap(m_limbs, o.m_limbs);
   }

 protected:
   template <class A>
   BOOST_MP_CXX14_CONSTEXPR void check_in_range(const A&) noexcept {}
};

template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr std::size_t cpp_int_base<MinBits, MinBits, signed_magnitude, Checked, void, false>::limb_bits;
template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr limb_type cpp_int_base<MinBits, MinBits, signed_magnitude, Checked, void, false>::max_limb_value;
template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr limb_type cpp_int_base<MinBits, MinBits, signed_magnitude, Checked, void, false>::sign_bit_mask;
template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr std::size_t cpp_int_base<MinBits, MinBits, signed_magnitude, Checked, void, false>::internal_limb_count;
//
// Fixed precision (i.e. no allocator), unsigned type with limb-usage count:
//
template <std::size_t MinBits, cpp_int_check_type Checked>
struct cpp_int_base<MinBits, MinBits, unsigned_magnitude, Checked, void, false>
{
   using limb_pointer = limb_type*        ;
   using const_limb_pointer = const limb_type*  ;
   using checked_type = std::integral_constant<int, Checked>;

   struct scoped_shared_storage 
   {
      BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, std::size_t) {}
      BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {}
   };
   //
   // Interface invariants:
   //
   static_assert(MinBits > sizeof(double_limb_type) * CHAR_BIT, "Template parameter MinBits is inconsistent with the parameter trivial - did you mistakingly try to override the trivial parameter?");

 public:
   static constexpr std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT;
   static constexpr limb_type max_limb_value = ~static_cast<limb_type>(0u);
   static constexpr limb_type sign_bit_mask = static_cast<limb_type>(1u) << (limb_bits - 1);
   static constexpr std::size_t internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0);
   static constexpr limb_type upper_limb_mask = (MinBits % limb_bits) ? (limb_type(1) << (MinBits % limb_bits)) - 1 : (~limb_type(0));
   static_assert(internal_limb_count >= 2, "A fixed precision integer type must have at least 2 limbs");

 private:
   union data_type
   {
      limb_type        m_data[internal_limb_count];
      limb_type        m_first_limb;
      double_limb_type m_double_first_limb;

      constexpr data_type()
          : m_data{0}
      {}
      constexpr data_type(limb_type i)
          : m_data{i}
      {}
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
      constexpr data_type(limb_type i, limb_type j) : m_data{i, j}
      {}
#endif
      constexpr data_type(double_limb_type i) : m_double_first_limb(i)
      {
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
         if (BOOST_MP_IS_CONST_EVALUATED(m_double_first_limb))
         {
            data_type t(static_cast<limb_type>(i & max_limb_value), static_cast<limb_type>(i >> limb_bits));
            *this = t;
         }
#endif
      }
      template <limb_type... VALUES>
      constexpr data_type(literals::detail::value_pack<VALUES...>) : m_data{VALUES...}
      {}
   } m_wrapper;
   std::size_t m_limbs;

 public:
   //
   // Direct construction:
   //
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(limb_type i) noexcept
       : m_wrapper(i),
         m_limbs(1) {}
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(signed_limb_type i) noexcept((Checked == unchecked))
       : m_wrapper(static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(i))),
         m_limbs(1)
   {
      if (i < 0)
         negate();
   }
#if BOOST_MP_ENDIAN_LITTLE_BYTE && !defined(BOOST_MP_TEST_NO_LE)
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(double_limb_type i) noexcept
       : m_wrapper(i),
         m_limbs(i > max_limb_value ? 2 : 1)
   {}
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(signed_double_limb_type i) noexcept((Checked == unchecked))
       : m_wrapper(double_limb_type(i < 0 ? static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i)) : i)),
         m_limbs(i < 0 ? (static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i)) > max_limb_value ? 2 : 1) : (i > max_limb_value ? 2 : 1))
   {
      if (i < 0)
         negate();
   }
#endif
   template <limb_type... VALUES>
   constexpr cpp_int_base(literals::detail::value_pack<VALUES...> i)
       : m_wrapper(i), m_limbs(sizeof...(VALUES))
   {}
   constexpr cpp_int_base(literals::detail::value_pack<>)
       : m_wrapper(static_cast<limb_type>(0u)), m_limbs(1) {}
   explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_wrapper(), m_limbs(1)
   {}
       //
   // Helper functions for getting at our internal data, and manipulating storage:
   //
   BOOST_MP_FORCEINLINE constexpr std::size_t              size() const noexcept { return m_limbs; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return m_wrapper.m_data; }
   BOOST_MP_FORCEINLINE constexpr const_limb_pointer    limbs() const noexcept { return m_wrapper.m_data; }
   BOOST_MP_FORCEINLINE constexpr bool                  sign() const noexcept { return false; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void         sign(bool b) noexcept((Checked == unchecked))
   {
      if (b)
         negate();
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(std::size_t new_size, std::size_t min_size) noexcept((Checked == unchecked))
   {
      m_limbs = (std::min)(new_size, internal_limb_count);
      detail::verify_new_size(m_limbs, min_size, checked_type());
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void normalize() noexcept((Checked == unchecked))
   {
      limb_pointer p = limbs();
      detail::verify_limb_mask(m_limbs == internal_limb_count, p[internal_limb_count - 1], upper_limb_mask, checked_type());
      p[internal_limb_count - 1] &= upper_limb_mask;
      while ((m_limbs - 1) && !p[m_limbs - 1])
         --m_limbs;
   }

   BOOST_MP_FORCEINLINE constexpr cpp_int_base() noexcept
       : m_wrapper(limb_type(0u)),
         m_limbs(1) {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(const cpp_int_base& o) noexcept
       : m_wrapper(o.m_wrapper),
         m_limbs(o.m_limbs) {}
   // Defaulted functions:
   //~cpp_int_base() noexcept {}
   //
   // These are deprecated in C++20 unless we make them explicit:
   //
   BOOST_MP_CXX14_CONSTEXPR cpp_int_base& operator=(const cpp_int_base&) = default;

   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void assign(const cpp_int_base& o) noexcept
   {
      if (this != &o)
      {
         m_limbs = o.m_limbs;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
         if (BOOST_MP_IS_CONST_EVALUATED(m_limbs))
         {
            for (std::size_t i = 0; i < m_limbs; ++i)
               limbs()[i] = o.limbs()[i];
         }
         else
#endif
            std::memcpy(limbs(), o.limbs(), o.size() * sizeof(limbs()[0]));
      }
   }

 private:
   void check_negate(const std::integral_constant<int, checked>&)
   {
      BOOST_MP_THROW_EXCEPTION(std::range_error("Attempt to negate an unsigned number."));
   }
   BOOST_MP_CXX14_CONSTEXPR void check_negate(const std::integral_constant<int, unchecked>&) {}

 public:
   BOOST_MP_CXX14_CONSTEXPR void negate() noexcept((Checked == unchecked))
   {
      // Not so much a negate as a complement - this gets called when subtraction
      // would result in a "negative" number:
      if ((m_limbs == 1) && (m_wrapper.m_data[0] == 0))
         return; // negating zero is always zero, and always OK.
      check_negate(checked_type());
      std::size_t i = m_limbs;
      for (; i < internal_limb_count; ++i)
         m_wrapper.m_data[i] = 0;
      m_limbs = internal_limb_count;
      for (i = 0; i < internal_limb_count; ++i)
         m_wrapper.m_data[i] = ~m_wrapper.m_data[i];
      normalize();
      eval_increment(static_cast<cpp_int_backend<MinBits, MinBits, unsigned_magnitude, Checked, void>&>(*this));
   }
   BOOST_MP_FORCEINLINE constexpr bool isneg() const noexcept
   {
      return false;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void do_swap(cpp_int_base& o) noexcept
   {
      for (std::size_t i = 0; i < (std::max)(size(), o.size()); ++i)
         std_constexpr::swap(m_wrapper.m_data[i], o.m_wrapper.m_data[i]);
      std_constexpr::swap(m_limbs, o.m_limbs);
   }

 protected:
   template <class A>
   BOOST_MP_CXX14_CONSTEXPR void check_in_range(const A&) noexcept {}
};

template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr std::size_t cpp_int_base<MinBits, MinBits, unsigned_magnitude, Checked, void, false>::limb_bits;
template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr limb_type cpp_int_base<MinBits, MinBits, unsigned_magnitude, Checked, void, false>::max_limb_value;
template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr limb_type cpp_int_base<MinBits, MinBits, unsigned_magnitude, Checked, void, false>::sign_bit_mask;
template <std::size_t MinBits, cpp_int_check_type Checked>
constexpr std::size_t cpp_int_base<MinBits, MinBits, unsigned_magnitude, Checked, void, false>::internal_limb_count;
//
// Traits classes to figure out a native type with N bits, these vary from boost::uint_t<N> only
// because some platforms have native integer types longer than long long, "really long long" anyone??
//
template <unsigned N, bool s>
struct trivial_limb_type_imp
{
   using type = double_limb_type;
};

template <unsigned N>
struct trivial_limb_type_imp<N, true>
{
   using type = typename boost::multiprecision::detail::uint_t<N>::least;
};

template <unsigned N>
struct trivial_limb_type : public trivial_limb_type_imp<N, N <= sizeof(long long) * CHAR_BIT>
{};
//
// Backend for fixed precision signed-magnitude type which will fit entirely inside a "double_limb_type":
//
template <std::size_t MinBits, cpp_int_check_type Checked>
struct cpp_int_base<MinBits, MinBits, signed_magnitude, Checked, void, true>
{
   using local_limb_type = typename trivial_limb_type<static_cast<unsigned>(MinBits)>::type;
   using limb_pointer = local_limb_type*;
   using const_limb_pointer = const local_limb_type*;
   using checked_type = std::integral_constant<int, Checked>;

   struct scoped_shared_storage 
   {
      BOOST_MP_CXX14_CONSTEXPR      scoped_shared_storage(const cpp_int_base&, std::size_t) {}
      BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {}
   };

 protected:
   static constexpr std::size_t limb_bits = sizeof(local_limb_type) * CHAR_BIT;
   static constexpr local_limb_type limb_mask = (MinBits < limb_bits) ? local_limb_type((local_limb_type(~local_limb_type(0))) >> (limb_bits - MinBits)) : local_limb_type(~local_limb_type(0));

 private:
   local_limb_type m_data;
   bool            m_sign;

   //
   // Interface invariants:
   //
   static_assert(MinBits <= sizeof(double_limb_type) * CHAR_BIT, "Template parameter MinBits is inconsistent with the parameter trivial - did you mistakingly try to override the trivial parameter?");

 protected:
   template <class T>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<!(!boost::multiprecision::detail::is_integral<T>::value || (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= static_cast<int>(MinBits))))>::type
   check_in_range(T val, const std::integral_constant<int, checked>&)
   {
      using common_type = typename std::common_type<typename boost::multiprecision::detail::make_unsigned<T>::type, local_limb_type>::type;

      if (static_cast<common_type>(boost::multiprecision::detail::unsigned_abs(val)) > static_cast<common_type>(limb_mask))
         BOOST_MP_THROW_EXCEPTION(std::range_error("The argument to a cpp_int constructor exceeded the largest value it can represent."));
   }
   template <class T>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<!(boost::multiprecision::detail::is_integral<T>::value || (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= static_cast<int>(MinBits))))>::type
   check_in_range(T val, const std::integral_constant<int, checked>&)
   {
      using std::abs;
      using common_type = typename std::common_type<T, local_limb_type>::type;

      if (static_cast<common_type>(abs(val)) > static_cast<common_type>(limb_mask))
         BOOST_MP_THROW_EXCEPTION(std::range_error("The argument to a cpp_int constructor exceeded the largest value it can represent."));
   }
   template <class T, int C>
   BOOST_MP_CXX14_CONSTEXPR void check_in_range(T, const std::integral_constant<int, C>&) noexcept {}

   template <class T>
   BOOST_MP_CXX14_CONSTEXPR void check_in_range(T val) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<T>(), checked_type())))
   {
      check_in_range(val, checked_type());
   }

 public:
   //
   // Direct construction:
   //
   template <class SI>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(SI i, typename std::enable_if<boost::multiprecision::detail::is_signed<SI>::value && boost::multiprecision::detail::is_integral<SI>::value && (Checked == unchecked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>())))
       : m_data(i < 0 ? static_cast<local_limb_type>(static_cast<typename boost::multiprecision::detail::make_unsigned<SI>::type>(boost::multiprecision::detail::unsigned_abs(i)) & limb_mask) : static_cast<local_limb_type>(i & limb_mask)), m_sign(i < 0) {}
   template <class SI>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(SI i, typename std::enable_if<boost::multiprecision::detail::is_signed<SI>::value && boost::multiprecision::detail::is_integral<SI>::value && (Checked == checked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>())))
       : m_data(i < 0 ? (static_cast<local_limb_type>(static_cast<typename boost::multiprecision::detail::make_unsigned<SI>::type>(boost::multiprecision::detail::unsigned_abs(i)) & limb_mask)) : static_cast<local_limb_type>(i & limb_mask)), m_sign(i < 0)
   {
      check_in_range(i);
   }
   template <class UI>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(UI i, typename std::enable_if<boost::multiprecision::detail::is_unsigned<UI>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(static_cast<local_limb_type>(i) & limb_mask),
         m_sign(false) {}
   template <class UI>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(UI i, typename std::enable_if<boost::multiprecision::detail::is_unsigned<UI>::value && (Checked == checked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<UI>())))
       : m_data(static_cast<local_limb_type>(i) & limb_mask), m_sign(false) { check_in_range(i); }
#if !(defined(__clang__) && defined(__MINGW32__))
   template <class F>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(F i, typename std::enable_if<std::is_floating_point<F>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(static_cast<local_limb_type>(i < 0 ? -i : i) & limb_mask),
         m_sign(i < 0) {}
   template <class F>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(F i, typename std::enable_if<std::is_floating_point<F>::value && (Checked == checked)>::type const* = nullptr)
       : m_data(static_cast<local_limb_type>(i < 0 ? -i : i) & limb_mask), m_sign(i < 0) { check_in_range(i); }
#else
   //
   // conversion from float to __int128 is broken on clang/mingw, 
   // see: https://bugs.llvm.org/show_bug.cgi?id=48940
   // Since no floating point type has more than 64 bits of
   // precision, we can simply cast to an intermediate type to
   // solve the issue:
   //
   template <class F>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(F i, typename std::enable_if<std::is_floating_point<F>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(static_cast<local_limb_type>(static_cast<std::uint64_t>(i < 0 ? -i : i)) & limb_mask),
         m_sign(i < 0) {}
   template <class F>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(F i, typename std::enable_if<std::is_floating_point<F>::value && (Checked == checked)>::type const* = nullptr)
       : m_data(static_cast<local_limb_type>(static_cast<std::uint64_t>(i < 0 ? -i : i)) & limb_mask), m_sign(i < 0) { check_in_range(i); }
#endif

   constexpr cpp_int_base(literals::detail::value_pack<>) noexcept
       : m_data(static_cast<local_limb_type>(0u)),
         m_sign(false)
   {}
   template <limb_type a>
   constexpr cpp_int_base(literals::detail::value_pack<a>) noexcept
       : m_data(static_cast<local_limb_type>(a)),
         m_sign(false) {}
   template <limb_type a, limb_type b>
   constexpr cpp_int_base(literals::detail::value_pack<a, b>) noexcept
       : m_data(static_cast<local_limb_type>(a) | (static_cast<local_limb_type>(b) << bits_per_limb)),
         m_sign(false) {}
   constexpr cpp_int_base(const cpp_int_base& a, const literals::detail::negate_tag&) noexcept
       : m_data(a.m_data),
         m_sign(a.m_data ? !a.m_sign : false) {}
   //
   // These are deprecated in C++20 unless we make them explicit:
   //
   BOOST_MP_CXX14_CONSTEXPR cpp_int_base& operator=(const cpp_int_base&) = default;

   explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_data(0), m_sign(false)
   {}
       //
   // Helper functions for getting at our internal data, and manipulating storage:
   //
   BOOST_MP_FORCEINLINE constexpr std::size_t              size() const noexcept { return 1; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return &m_data; }
   BOOST_MP_FORCEINLINE constexpr const_limb_pointer    limbs() const noexcept { return &m_data; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR bool         sign() const noexcept { return m_sign; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void         sign(bool b) noexcept
   {
      m_sign = b;
      // Check for zero value:
      if (m_sign && !m_data)
      {
         m_sign = false;
      }
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(std::size_t /* new_size */, std::size_t min_size)
   {
      detail::verify_new_size(2, min_size, checked_type());
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void normalize() noexcept((Checked == unchecked))
   {
      if (!m_data)
         m_sign = false; // zero is always unsigned
      detail::verify_limb_mask(true, m_data, limb_mask, checked_type());
      m_data &= limb_mask;
   }

   BOOST_MP_FORCEINLINE constexpr cpp_int_base() noexcept : m_data(0), m_sign(false) {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(const cpp_int_base& o) noexcept
       : m_data(o.m_data),
         m_sign(o.m_sign) {}
   //~cpp_int_base() noexcept {}
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void assign(const cpp_int_base& o) noexcept
   {
      m_data = o.m_data;
      m_sign = o.m_sign;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void negate() noexcept
   {
      m_sign = !m_sign;
      // Check for zero value:
      if (m_data == 0)
      {
         m_sign = false;
      }
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR bool isneg() const noexcept
   {
      return m_sign;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void do_swap(cpp_int_base& o) noexcept
   {
      std_constexpr::swap(m_sign, o.m_sign);
      std_constexpr::swap(m_data, o.m_data);
   }
};
//
// Backend for unsigned fixed precision (i.e. no allocator) type which will fit entirely inside a "double_limb_type":
//
template <std::size_t MinBits, cpp_int_check_type Checked>
struct cpp_int_base<MinBits, MinBits, unsigned_magnitude, Checked, void, true>
{
   using local_limb_type = typename trivial_limb_type<static_cast<unsigned>(MinBits)>::type;
   using limb_pointer = local_limb_type*                         ;
   using const_limb_pointer = const local_limb_type*                   ;

   struct scoped_shared_storage 
   {
      BOOST_MP_CXX14_CONSTEXPR      scoped_shared_storage(const cpp_int_base&, std::size_t) {}
      BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {}
   };

 private:
   static constexpr std::size_t limb_bits = sizeof(local_limb_type) * CHAR_BIT;
   static constexpr local_limb_type limb_mask = limb_bits != MinBits ? static_cast<local_limb_type>(static_cast<local_limb_type>(~local_limb_type(0)) >> (limb_bits - MinBits))
                                                                           : static_cast<local_limb_type>(~local_limb_type(0));

   local_limb_type m_data;

   using checked_type = std::integral_constant<int, Checked>;

   //
   // Interface invariants:
   //
   static_assert(MinBits <= sizeof(double_limb_type) * CHAR_BIT, "Template parameter MinBits is inconsistent with the parameter trivial - did you mistakingly try to override the trivial parameter?");

 protected:
   template <class T>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !(std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::digits <= static_cast<int>(MinBits)))>::type
   check_in_range(T val, const std::integral_constant<int, checked>&, const std::integral_constant<bool, false>&)
   {
      using common_type = typename std::common_type<T, local_limb_type>::type;

      if (static_cast<common_type>(val) > limb_mask)
         BOOST_MP_THROW_EXCEPTION(std::range_error("The argument to a cpp_int constructor exceeded the largest value it can represent."));
   }
   template <class T>
   BOOST_MP_CXX14_CONSTEXPR void check_in_range(T val, const std::integral_constant<int, checked>&, const std::integral_constant<bool, true>&)
   {
      using common_type = typename std::common_type<T, local_limb_type>::type;

      if (static_cast<common_type>(val) > static_cast<common_type>(limb_mask))
         BOOST_MP_THROW_EXCEPTION(std::range_error("The argument to a cpp_int constructor exceeded the largest value it can represent."));
      if (val < 0)
         BOOST_MP_THROW_EXCEPTION(std::range_error("The argument to an unsigned cpp_int constructor was negative."));
   }
   template <class T, int C, bool B>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void check_in_range(T, const std::integral_constant<int, C>&, const std::integral_constant<bool, B>&) noexcept {}

   template <class T>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void check_in_range(T val) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<T>(), checked_type(), boost::multiprecision::detail::is_signed<T>())))
   {
      check_in_range(val, checked_type(), boost::multiprecision::detail::is_signed<T>());
   }

 public:
   //
   // Direct construction:
   //
#ifdef __MSVC_RUNTIME_CHECKS
   template <class SI>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(SI i, typename std::enable_if<boost::multiprecision::detail::is_signed<SI>::value && boost::multiprecision::detail::is_integral<SI>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(i < 0 ? (1 + ~static_cast<local_limb_type>(-i & limb_mask)) & limb_mask : static_cast<local_limb_type>(i & limb_mask))
   {}
   template <class SI>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(SI i, typename std::enable_if<boost::multiprecision::detail::is_signed<SI>::value && boost::multiprecision::detail::is_integral<SI>::value && (Checked == checked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>())))
       : m_data(i < 0 ? 1 + ~static_cast<local_limb_type>(-i & limb_mask) : static_cast<local_limb_type>(i & limb_mask)) { check_in_range(i); }
   template <class UI>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(UI i, typename std::enable_if<boost::multiprecision::detail::is_unsigned<UI>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(static_cast<local_limb_type>(i& limb_mask)) {}
   template <class UI>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(UI i, typename std::enable_if<boost::multiprecision::detail::is_unsigned<UI>::value && (Checked == checked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<UI>())))
       : m_data(static_cast<local_limb_type>(i & limb_mask)) { check_in_range(i); }
#else
   template <class SI>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(SI i, typename std::enable_if<boost::multiprecision::detail::is_signed<SI>::value && boost::multiprecision::detail::is_integral<SI>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(i < 0 ? (1 + ~static_cast<local_limb_type>(-i)) & limb_mask : static_cast<local_limb_type>(i) & limb_mask)
   {}
   template <class SI>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(SI i, typename std::enable_if<boost::multiprecision::detail::is_signed<SI>::value && boost::multiprecision::detail::is_integral<SI>::value && (Checked == checked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>())))
       : m_data(i < 0 ? 1 + ~static_cast<local_limb_type>(-i) : static_cast<local_limb_type>(i)) { check_in_range(i); }
   template <class UI>
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(UI i, typename std::enable_if<boost::multiprecision::detail::is_unsigned<UI>::value && (Checked == unchecked)>::type const* = nullptr) noexcept
       : m_data(static_cast<local_limb_type>(i) & limb_mask) {}
   template <class UI>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(UI i, typename std::enable_if<boost::multiprecision::detail::is_unsigned<UI>::value && (Checked == checked)>::type const* = nullptr) noexcept(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<UI>())))
       : m_data(static_cast<local_limb_type>(i)) { check_in_range(i); }
#endif
   template <class F>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_base(F i, typename std::enable_if<std::is_floating_point<F>::value >::type const* = nullptr) noexcept((Checked == unchecked))
       : m_data(static_cast<local_limb_type>(i < 0 ? -i : i) & limb_mask)
   {
      check_in_range(i);
      if (i < 0)
         negate();
   }
   constexpr cpp_int_base(literals::detail::value_pack<>) noexcept
       : m_data(static_cast<local_limb_type>(0u))
   {}
   template <limb_type a>
   constexpr cpp_int_base(literals::detail::value_pack<a>) noexcept
       : m_data(static_cast<local_limb_type>(a)) {}
   template <limb_type a, limb_type b>
   constexpr cpp_int_base(literals::detail::value_pack<a, b>) noexcept
       : m_data(static_cast<local_limb_type>(a) | (static_cast<local_limb_type>(b) << bits_per_limb)) {}
   //
   // These are deprecated in C++20 unless we make them explicit:
   //
   BOOST_MP_CXX14_CONSTEXPR cpp_int_base& operator=(const cpp_int_base&) = default;

   explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_data(0)
   {}
       //
   // Helper functions for getting at our internal data, and manipulating storage:
   //
   BOOST_MP_FORCEINLINE constexpr std::size_t              size() const noexcept { return 1; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return &m_data; }
   BOOST_MP_FORCEINLINE constexpr const_limb_pointer    limbs() const noexcept { return &m_data; }
   BOOST_MP_FORCEINLINE constexpr bool                  sign() const noexcept { return false; }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void         sign(bool b) noexcept((Checked == unchecked))
   {
      if (b)
         negate();
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(unsigned, std::size_t min_size)
   {
      detail::verify_new_size(2, min_size, checked_type());
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void normalize() noexcept((Checked == unchecked))
   {
      detail::verify_limb_mask(true, m_data, limb_mask, checked_type());
      m_data &= limb_mask;
   }

   BOOST_MP_FORCEINLINE constexpr cpp_int_base() noexcept : m_data(0) {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_base(const cpp_int_base& o) noexcept
       : m_data(o.m_data) {}
   //~cpp_int_base() noexcept {}
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void assign(const cpp_int_base& o) noexcept
   {
      m_data = o.m_data;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void negate()
   #if !defined(BOOST_NO_CXX17_IF_CONSTEXPR)
   noexcept((Checked == unchecked))
   #endif
   {
      BOOST_IF_CONSTEXPR(Checked == checked)
      {
         BOOST_MP_THROW_EXCEPTION(std::range_error("Attempt to negate an unsigned type."));
      }
      m_data = ~m_data;
      ++m_data;
   }
   BOOST_MP_FORCEINLINE constexpr bool isneg() const noexcept
   {
      return false;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void do_swap(cpp_int_base& o) noexcept
   {
      std_constexpr::swap(m_data, o.m_data);
   }
};
//
// Traits class, lets us know whether type T can be directly converted to the base type,
// used to enable/disable constructors etc:
//
template <class Arg, class Base>
struct is_allowed_cpp_int_base_conversion : public std::conditional<
                                                std::is_same<Arg, limb_type>::value || std::is_same<Arg, signed_limb_type>::value
#if BOOST_MP_ENDIAN_LITTLE_BYTE && !defined(BOOST_MP_TEST_NO_LE)
                                                    || std::is_same<Arg, double_limb_type>::value || std::is_same<Arg, signed_double_limb_type>::value
#endif
                                                    || literals::detail::is_value_pack<Arg>::value || (is_trivial_cpp_int<Base>::value && boost::multiprecision::detail::is_arithmetic<Arg>::value),
                                                std::integral_constant<bool, true>,
                                                std::integral_constant<bool, false>>::type
{};
//
// Now the actual backend, normalising parameters passed to the base class:
//
template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct cpp_int_backend
    : public cpp_int_base<
          min_precision<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value,
          max_precision<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value,
          SignType,
          Checked,
          Allocator,
          is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value>
{
   using self_type = cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>;
   using base_type = cpp_int_base<
       min_precision<self_type>::value,
       max_precision<self_type>::value,
       SignType,
       Checked,
       Allocator,
       is_trivial_cpp_int<self_type>::value>;
   using trivial_tag = std::integral_constant<bool, is_trivial_cpp_int<self_type>::value>;

 public:
   using signed_types = typename std::conditional<
       is_trivial_cpp_int<self_type>::value,
       std::tuple<
           signed char, short, int, long,
           long long, signed_double_limb_type>,
       std::tuple<signed_limb_type, signed_double_limb_type> >::type;
   using unsigned_types = typename std::conditional<
       is_trivial_cpp_int<self_type>::value,
       std::tuple<unsigned char, unsigned short, unsigned,
                 unsigned long, unsigned long long, double_limb_type>,
       std::tuple<limb_type, double_limb_type> >::type;
   using float_types = typename std::conditional<
       is_trivial_cpp_int<self_type>::value,
       std::tuple<float, double, long double>,
       std::tuple<long double> >::type;
   using checked_type = std::integral_constant<int, Checked>        ;

   BOOST_MP_FORCEINLINE constexpr cpp_int_backend() noexcept {}
   BOOST_MP_FORCEINLINE constexpr cpp_int_backend(const cpp_int_backend& o) noexcept(std::is_void<Allocator>::value) : base_type(o) {}
   // rvalue copy:
   BOOST_MP_FORCEINLINE constexpr cpp_int_backend(cpp_int_backend&& o) noexcept
       : base_type(static_cast<base_type&&>(o))
   {}
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2>
   BOOST_MP_FORCEINLINE BOOST_CXX14_CONSTEXPR cpp_int_backend(cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2>&& o, typename std::enable_if<is_implicit_cpp_int_conversion<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2>, self_type>::value>::type* = nullptr) noexcept
   {
      *this = static_cast<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2>&&>(o);
   }
   //
   // Direct construction from arithmetic type:
   //
   template <class Arg>
   BOOST_MP_FORCEINLINE constexpr cpp_int_backend(Arg i, typename std::enable_if<is_allowed_cpp_int_base_conversion<Arg, base_type>::value>::type const* = nullptr) noexcept(noexcept(base_type(std::declval<Arg>())))
       : base_type(i) {}
   //
   // Aliasing constructor: the result will alias the memory referenced, unless
   // we have fixed precision and storage, in which case we copy the memory:
   //
   explicit constexpr cpp_int_backend(limb_type* data, std::size_t offset, std::size_t len) noexcept
       : base_type(data, offset, len) {}
   explicit cpp_int_backend(const limb_type* data, std::size_t offset, std::size_t len) noexcept
       : base_type(data, offset, len) { this->normalize(); }
   explicit constexpr cpp_int_backend(typename base_type::scoped_shared_storage& data, std::size_t len) noexcept
       : base_type(data, len) {}

 private:
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other, std::true_type const&, std::true_type const&)
   {
      // Assigning trivial type to trivial type:
      this->check_in_range(*other.limbs());
      *this->limbs() = static_cast<typename self_type::local_limb_type>(*other.limbs());
      this->sign(other.sign());
      this->normalize();
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other, std::true_type const&, std::false_type const&)
   {
      // non-trivial to trivial narrowing conversion:
      double_limb_type v = *other.limbs();
      if (other.size() > 1)
      {
         v |= static_cast<double_limb_type>(other.limbs()[1]) << bits_per_limb;
         BOOST_IF_CONSTEXPR(Checked == checked)
         {
            if (other.size() > 2)
            {
               BOOST_MP_THROW_EXCEPTION(std::range_error("Assignment of a cpp_int that is out of range for the target type."));
            }
         }
      }
      *this = v;
      this->sign(other.sign());
      this->normalize();
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other, std::false_type const&, std::true_type const&)
   {
      // trivial to non-trivial, treat the trivial argument as if it were an unsigned arithmetic type, then set the sign afterwards:
      *this = static_cast<
          typename boost::multiprecision::detail::canonical<
              typename cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>::local_limb_type,
              cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::type>(*other.limbs());
      this->sign(other.sign());
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other, std::false_type const&, std::false_type const&)
   {
      // regular non-trivial to non-trivial assign:
      this->resize(other.size(), other.size());

#if !defined(BOOST_MP_HAS_IS_CONSTANT_EVALUATED) && !defined(BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED) && !defined(BOOST_NO_CXX14_CONSTEXPR)
      std::size_t count = (std::min)(other.size(), this->size());
      for (std::size_t i = 0; i < count; ++i)
         this->limbs()[i] = other.limbs()[i];
#else
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
      if (BOOST_MP_IS_CONST_EVALUATED(other.size()))
      {
         std::size_t count = (std::min)(other.size(), this->size());
         for (std::size_t i = 0; i < count; ++i)
            this->limbs()[i] = other.limbs()[i];
      }
      else
#endif
      {
         static_assert(sizeof(other.limbs()[0]) == sizeof(this->limbs()[0]), "This method requires equal limb sizes");
         std::memcpy(this->limbs(), other.limbs(), (std::min)(other.size() * sizeof(other.limbs()[0]), this->size() * sizeof(this->limbs()[0])));
      }
#endif
      this->sign(other.sign());
      this->normalize();
   }

 public:
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR cpp_int_backend(
       const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other,
       typename std::enable_if<is_implicit_cpp_int_conversion<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>, self_type>::value>::type* = nullptr)
       : base_type()
   {
      do_assign(
          other,
          std::integral_constant<bool, is_trivial_cpp_int<self_type>::value>(),
          std::integral_constant<bool, is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value>());
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   explicit BOOST_MP_CXX14_CONSTEXPR cpp_int_backend(
       const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other,
       typename std::enable_if< !(is_implicit_cpp_int_conversion<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>, self_type>::value)>::type* = nullptr)
       : base_type()
   {
      do_assign(
          other,
          std::integral_constant<bool, is_trivial_cpp_int<self_type>::value>(),
          std::integral_constant<bool, is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value>());
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR cpp_int_backend& operator=(
       const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& other)
   {
      do_assign(
          other,
          std::integral_constant<bool, is_trivial_cpp_int<self_type>::value>(),
          std::integral_constant<bool, is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value>());
      return *this;
   }
   constexpr cpp_int_backend(const cpp_int_backend& a, const literals::detail::negate_tag& tag)
       : base_type(static_cast<const base_type&>(a), tag)
   {}

   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_backend& operator=(const cpp_int_backend& o) noexcept(noexcept(std::declval<cpp_int_backend>().assign(std::declval<const cpp_int_backend&>())))
   {
      this->assign(o);
      return *this;
   }
   // rvalue copy:
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR cpp_int_backend& operator=(cpp_int_backend&& o) noexcept(noexcept(std::declval<base_type&>() = std::declval<base_type>()))
   {
      *static_cast<base_type*>(this) = static_cast<base_type&&>(o);
      return *this;
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<((MaxBits2 <= MaxBits) || (MaxBits == 0)) && !std::is_void<Allocator>::value, cpp_int_backend&>::type operator=(cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator>&& o) noexcept
   {
      *static_cast<base_type*>(this) = static_cast<typename cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2>::base_type&&>(o);
      return *this;
   }

   template <class A>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<
         boost::multiprecision::detail::is_unsigned<A>::value
         && trivial_tag::value, cpp_int_backend&>::type 
      operator=(const A& val)
         noexcept(noexcept(std::declval<cpp_int_backend>().check_in_range(std::declval<A>())))
   {
      this->check_in_range(val);
      *this->limbs() = static_cast<typename self_type::local_limb_type>(val);
      this->sign(false);
      this->normalize();
      return *this;
   }
   template <class A>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<
         !(boost::multiprecision::detail::is_unsigned<A>::value || !boost::multiprecision::detail::is_integral<A>::value)
         && trivial_tag::value, cpp_int_backend&>::type
      operator=(const A& val)
         noexcept(noexcept(std::declval<cpp_int_backend>().check_in_range(std::declval<A>())) && noexcept(std::declval<cpp_int_backend>().sign(true)))
   {
      this->check_in_range(val);
      *this->limbs() = (val < 0) ? static_cast<typename self_type::local_limb_type>(boost::multiprecision::detail::unsigned_abs(val)) : static_cast<typename self_type::local_limb_type>(val);
      this->sign(val < 0);
      this->normalize();
      return *this;
   }
   template <class A>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<
         std::is_convertible<A, limb_type>::value 
         && !boost::multiprecision::detail::is_integral<A>::value
         && trivial_tag::value, cpp_int_backend&>::type 
      operator=(const A& val)
   {
      this->check_in_range(val);
      *this->limbs() = (val < 0) ? static_cast<typename self_type::local_limb_type>(boost::multiprecision::detail::abs(val)) : static_cast<typename self_type::local_limb_type>(val);
      this->sign(val < 0);
      this->normalize();
      return *this;
   }
   template <class A>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<
         std::is_same<A, limb_type>::value && !trivial_tag::value, cpp_int_backend&>::type
      operator=(A i) noexcept
   {
      this->resize(1, 1);
      *this->limbs() = i;
      this->sign(false);
      return *this;
   }
   template <class A>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if <
         std::is_same<A, signed_limb_type>::value && !trivial_tag::value, cpp_int_backend&>::type
      operator=(A i) noexcept(noexcept(std::declval<cpp_int_backend>().sign(true)))
   {
      this->resize(1, 1);
      *this->limbs() = static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(i));
      this->sign(i < 0);
      return *this;
   }
   template <class A>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if <
         std::is_same<A, double_limb_type>::value && !trivial_tag::value, cpp_int_backend&>::type
      operator=(A i) noexcept
   {
      static_assert(sizeof(i) == 2 * sizeof(limb_type), "Failed integer size check");
      static_assert(base_type::internal_limb_count >= 2, "Failed internal limb count");
      typename base_type::limb_pointer p = this->limbs();
#ifdef __MSVC_RUNTIME_CHECKS
      *p = static_cast<limb_type>(i & ~static_cast<limb_type>(0));
#else
      *p                        = static_cast<limb_type>(i);
#endif
      p[1] = static_cast<limb_type>(i >> base_type::limb_bits);
      this->resize(p[1] ? 2 : 1, p[1] ? 2 : 1);
      this->sign(false);
      return *this;
   }
   template <class A>
   BOOST_MP_CXX14_CONSTEXPR typename std::enable_if <
         std::is_same<A, signed_double_limb_type>::value && !trivial_tag::value, cpp_int_backend&>::type
      operator=(A i) noexcept(noexcept(std::declval<cpp_int_backend>().sign(true)))
   {
      static_assert(sizeof(i) == 2 * sizeof(limb_type), "double limb type size check failed");
      static_assert(base_type::internal_limb_count >= 2, "Failed internal limb count check");
      bool s = false;
      if (i < 0)
         s = true;
      double_limb_type                 ui = static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i));
      typename base_type::limb_pointer p  = this->limbs();
#ifdef __MSVC_RUNTIME_CHECKS
      *p = static_cast<limb_type>(ui & ~static_cast<limb_type>(0));
#else
      *p                        = static_cast<limb_type>(ui);
#endif
      p[1] = static_cast<limb_type>(ui >> base_type::limb_bits);
      this->resize(p[1] ? 2 : 1, p[1] ? 2 : 1);
      this->sign(s);
      return *this;
   }
private:
   template <class F>
   BOOST_MP_CXX14_CONSTEXPR void do_assign_float(F a)
   {
      using default_ops::eval_add;
      using default_ops::eval_subtract;
      BOOST_MP_FLOAT128_USING using std::floor; using std::frexp; using std::ldexp;

      if (a < 0)
      {
         do_assign_float(-a);
         this->sign(true);
         return;
      }

      if (a == 0)
      {
         *this = static_cast<limb_type>(0u);
      }

      if (a == 1)
      {
         *this = static_cast<limb_type>(1u);
      }

      if (!BOOST_MP_ISFINITE(a))
      {
         BOOST_MP_THROW_EXCEPTION(std::runtime_error("Cannot convert a non-finite number to an integer."));
      }

      int         e = 0;
      F f(0), term(0);
      *this = static_cast<limb_type>(0u);

      f = frexp(a, &e);

#if !(defined(__clang__) && (__clang_major__ <= 7))
      constexpr limb_type shift = std::numeric_limits<limb_type>::digits;
#else
      // clang 7 has an issue converting long double to unsigned long long in
      // release mode (bits get dropped, conversion appears to go via float)
      // Never extract more than double bits at a time:
      constexpr limb_type shift = std::numeric_limits<limb_type>::digits > std::numeric_limits<double>::digits
            ? std::numeric_limits<double>::digits : std::numeric_limits<limb_type>::digits;
#endif

      while (f != static_cast<F>(0.0f))
      {
         // extract int sized bits from f:
         f    = ldexp(f, shift);
         term = floor(f);
         e = e - static_cast<int>(shift);
         eval_left_shift(*this, shift);
#if !(defined(__clang__) && (__clang_major__ <= 7))
         if (term > 0)
            eval_add(*this, static_cast<limb_type>(term));
         else
            eval_subtract(*this, static_cast<limb_type>(-term));
#else
         // clang 7 requires extra cast to double to avoid buggy code generation:
         if (term > 0)
            eval_add(*this, static_cast<limb_type>(static_cast<double>(term)));
         else
            eval_subtract(*this, static_cast<limb_type>(static_cast<double>(-term)));
#endif
         f -= term;
      }
      if (e > 0)
         eval_left_shift(*this, static_cast<unsigned int>(e));
      else if (e < 0)
         eval_right_shift(*this, static_cast<unsigned int>(-e));
   }
public:
   template <class A>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if <
      std::is_floating_point<A>::value && !trivial_tag::value, cpp_int_backend&>::type
      operator=(A a)
   {
      do_assign_float(a);
      return *this;
   }

 private:
   void do_assign_string(const char* s, const std::integral_constant<bool, true>&)
   {
      std::size_t n  = s ? std::strlen(s) : 0;
      *this          = 0;
      unsigned radix = 10;
      bool     isneg = false;
      if (n && (*s == '-'))
      {
         --n;
         ++s;
         isneg = true;
      }
      if (n && (*s == '0'))
      {
         if ((n > 1) && ((s[1] == 'x') || (s[1] == 'X')))
         {
            radix = 16;
            s += 2;
            n -= 2;
         }
         else
         {
            radix = 8;
            n -= 1;
         }
      }
      if (n)
      {
         unsigned val;
         while (*s)
         {
            if (*s >= '0' && *s <= '9')
               val = static_cast<unsigned>(*s - '0');
            else if (*s >= 'a' && *s <= 'f')
               val = 10u + static_cast<unsigned>(*s - 'a');
            else if (*s >= 'A' && *s <= 'F')
               val = 10u + static_cast<unsigned>(*s - 'A');
            else
               val = radix + 1u;
            if (val >= radix)
            {
               BOOST_MP_THROW_EXCEPTION(std::runtime_error("Unexpected content found while parsing character string."));
            }
            *this->limbs() = detail::checked_multiply(*this->limbs(), static_cast<typename base_type::local_limb_type>(radix), checked_type());
            *this->limbs() = detail::checked_add(*this->limbs(), static_cast<typename base_type::local_limb_type>(val), checked_type());
            ++s;
         }
      }
      if (isneg)
         this->negate();
   }
   void do_assign_string(const char* s, const std::integral_constant<bool, false>&)
   {
      using default_ops::eval_add;
      using default_ops::eval_multiply;
      std::size_t n  = s ? std::strlen(s) : 0;
      *this          = static_cast<limb_type>(0u);
      unsigned radix = 10;
      bool     isneg = false;
      if (n && (*s == '-'))
      {
         --n;
         ++s;
         isneg = true;
      }
      if (n && (*s == '0'))
      {
         if ((n > 1) && ((s[1] == 'x') || (s[1] == 'X')))
         {
            radix = 16;
            s += 2;
            n -= 2;
         }
         else
         {
            radix = 8;
            n -= 1;
         }
      }
      //
      // Exception guarantee: create the result in stack variable "result"
      // then do a swap at the end.  In the event of a throw, *this will
      // be left unchanged.
      //
      cpp_int_backend result;
      if (n)
      {
         if (radix == 16)
         {
            while (*s == '0')
               ++s;
            std::size_t bitcount = 4 * std::strlen(s);
            limb_type   val;
            std::size_t limb, shift;
            if (bitcount > 4)
               bitcount -= 4;
            else
               bitcount = 0;
            std::size_t newsize = bitcount / (sizeof(limb_type) * CHAR_BIT) + 1;
            result.resize(static_cast<unsigned>(newsize), static_cast<unsigned>(newsize)); // will throw if this is a checked integer that cannot be resized
            std::memset(result.limbs(), 0, result.size() * sizeof(limb_type));
            while (*s)
            {
               if (*s >= '0' && *s <= '9')
                  val = static_cast<unsigned>(*s - '0');
               else if (*s >= 'a' && *s <= 'f')
                  val = 10u + static_cast<unsigned>(*s - 'a');
               else if (*s >= 'A' && *s <= 'F')
                  val = 10u + static_cast<unsigned>(*s - 'A');
               else
               {
                  #if defined(BOOST_NO_EXCEPTIONS)
                  val = static_cast<unsigned>('0');
                  #endif

                  BOOST_MP_THROW_EXCEPTION(std::runtime_error("Unexpected content found while parsing character string."));
               }
               limb  = bitcount / (sizeof(limb_type) * CHAR_BIT);
               shift = bitcount % (sizeof(limb_type) * CHAR_BIT);
               val <<= shift;
               if (result.size() > limb)
               {
                  result.limbs()[limb] |= val;
               }
               ++s;
               bitcount -= 4;
            }
            result.normalize();
         }
         else if (radix == 8)
         {
            while (*s == '0')
               ++s;
            std::size_t bitcount = 3 * std::strlen(s);
            limb_type   val;
            std::size_t limb, shift;
            if (bitcount > 3)
               bitcount -= 3;
            else
               bitcount = 0;
            std::size_t newsize = bitcount / (sizeof(limb_type) * CHAR_BIT) + 1;
            result.resize(static_cast<unsigned>(newsize), static_cast<unsigned>(newsize)); // will throw if this is a checked integer that cannot be resized
            std::memset(result.limbs(), 0, result.size() * sizeof(limb_type));
            while (*s)
            {
               if (*s >= '0' && *s <= '7')
                  val = static_cast<unsigned>(*s - '0');
               else
               {
                  #if defined(BOOST_NO_EXCEPTIONS)
                  val = static_cast<unsigned>('0');
                  #endif

                  BOOST_MP_THROW_EXCEPTION(std::runtime_error("Unexpected content found while parsing character string."));
               }
               limb  = bitcount / (sizeof(limb_type) * CHAR_BIT);
               shift = bitcount % (sizeof(limb_type) * CHAR_BIT);
               if (result.size() > limb)
               {
                  result.limbs()[limb] |= (val << shift);
                  if (shift > sizeof(limb_type) * CHAR_BIT - 3)
                  {
                     // Deal with the bits in val that overflow into the next limb:
                     val >>= (sizeof(limb_type) * CHAR_BIT - shift);
                     if (val)
                     {
                        // If this is the most-significant-limb, we may need to allocate an extra one for the overflow:
                        if (limb + 1 == newsize)
                           result.resize(static_cast<unsigned>(newsize + 1), static_cast<unsigned>(newsize + 1));
                        if (result.size() > limb + 1)
                        {
                           result.limbs()[limb + 1] |= val;
                        }
                     }
                  }
               }
               ++s;
               bitcount -= 3;
            }
            result.normalize();
         }
         else
         {
            // Base 10, we extract blocks of size 10^9 at a time, that way
            // the number of multiplications is kept to a minimum:
            limb_type block_mult = max_block_10;
            while (*s)
            {
               limb_type block = 0;
               for (unsigned i = 0; i < digits_per_block_10; ++i)
               {
                  limb_type val;
                  if (*s >= '0' && *s <= '9')
                     val = static_cast<limb_type>(*s - '0');
                  else
                  {
                     #if defined(BOOST_NO_EXCEPTIONS)
                     val = static_cast<unsigned>('0');
                     #endif

                     BOOST_MP_THROW_EXCEPTION(std::runtime_error("Unexpected character encountered in input."));
                  }
                  block *= 10;
                  block += val;
                  if (!*++s)
                  {
                     block_mult = block_multiplier(i);
                     break;
                  }
               }
               eval_multiply(result, block_mult);
               eval_add(result, block);
            }
         }
      }
      if (isneg)
         result.negate();
      result.swap(*this);
   }

 public:
   cpp_int_backend& operator=(const char* s)
   {
      do_assign_string(s, trivial_tag());
      return *this;
   }
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void swap(cpp_int_backend& o) noexcept
   {
      this->do_swap(o);
   }

 private:
   std::string do_get_trivial_string(std::ios_base::fmtflags f, const std::integral_constant<bool, false>&) const
   {
      using io_type = typename std::conditional<sizeof(typename base_type::local_limb_type) == 1, unsigned, typename base_type::local_limb_type>::type;
      if (this->sign() && (((f & std::ios_base::hex) == std::ios_base::hex) || ((f & std::ios_base::oct) == std::ios_base::oct)))
         BOOST_MP_THROW_EXCEPTION(std::runtime_error("Base 8 or 16 printing of negative numbers is not supported."));
      std::stringstream ss;
      ss.flags(f & ~std::ios_base::showpos);
      ss << static_cast<io_type>(*this->limbs());
      std::string result;
      if (this->sign())
         result += '-';
      else if (f & std::ios_base::showpos)
         result += '+';
      result += ss.str();
      return result;
   }
   std::string do_get_trivial_string(std::ios_base::fmtflags f, const std::integral_constant<bool, true>&) const
   {
      // Even though we have only one limb, we can't do IO on it :-(
      int base = 10;
      if ((f & std::ios_base::oct) == std::ios_base::oct)
         base = 8;
      else if ((f & std::ios_base::hex) == std::ios_base::hex)
         base = 16;
      std::string result;

      std::size_t Bits = sizeof(typename base_type::local_limb_type) * CHAR_BIT;

      if (base == 8 || base == 16)
      {
         if (this->sign())
            BOOST_MP_THROW_EXCEPTION(std::runtime_error("Base 8 or 16 printing of negative numbers is not supported."));
         limb_type                           shift = base == 8 ? 3 : 4;
         limb_type                           mask  = static_cast<limb_type>((1u << shift) - 1);
         typename base_type::local_limb_type v     = *this->limbs();
         result.assign(Bits / shift + (Bits % shift ? 1 : 0), '0');
         std::string::difference_type pos      = static_cast<std::string::difference_type>(result.size() - 1u);
         char                         letter_a = f & std::ios_base::uppercase ? 'A' : 'a';
         for (std::size_t i = 0; i < Bits / shift; ++i)
         {
            char c = static_cast<char>('0' + static_cast<char>(v & mask));
            if (c > '9')
               c = static_cast<char>(c + letter_a - '9' - 1);
            result[static_cast<std::size_t>(pos)] = c;
            --pos;
            v >>= shift;
         }
         if (Bits % shift)
         {
            mask   = static_cast<limb_type>((1u << (Bits % shift)) - 1);
            char c = static_cast<char>('0' + static_cast<char>(v & mask));
            if (c > '9')
               c = static_cast<char>(c + letter_a - '9');
            result[static_cast<std::size_t>(pos)] = c;
         }
         //
         // Get rid of leading zeros:
         //
         std::string::size_type n = result.find_first_not_of('0');
         if (!result.empty() && (n == std::string::npos))
            n = result.size() - 1;
         result.erase(0, n);
         if (f & std::ios_base::showbase)
         {
            const char* pp = base == 8 ? "0" : (f & std::ios_base::uppercase) ? "0X" : "0x";
            result.insert(static_cast<std::string::size_type>(0), pp);
         }
      }
      else
      {
         result.assign(Bits / 3 + 1, '0');
         std::string::difference_type        pos = static_cast<std::string::difference_type>(result.size() - 1u);
         typename base_type::local_limb_type v(*this->limbs());
         bool                                neg = false;
         if (this->sign())
         {
            neg = true;
         }
         while (v)
         {
            result[static_cast<std::string::size_type>(pos)] = static_cast<char>(static_cast<char>(v % 10) + '0');
            --pos;
            v /= 10;
         }
         std::string::size_type n = result.find_first_not_of('0');
         result.erase(0, n);
         if (result.empty())
            result = "0";
         if (neg)
            result.insert(static_cast<std::string::size_type>(0), 1, '-');
         else if (f & std::ios_base::showpos)
            result.insert(static_cast<std::string::size_type>(0), 1, '+');
      }
      return result;
   }
   std::string do_get_string(std::ios_base::fmtflags f, const std::integral_constant<bool, true>&) const
   {
#ifdef BOOST_MP_NO_DOUBLE_LIMB_TYPE_IO
      return do_get_trivial_string(f, std::integral_constant<bool, std::is_same<typename base_type::local_limb_type, double_limb_type>::value>());
#else
      return do_get_trivial_string(f, std::integral_constant<bool, false>());
#endif
   }
   std::string do_get_string(std::ios_base::fmtflags f, const std::integral_constant<bool, false>&) const
   {
      using default_ops::eval_get_sign;
      int base = 10;
      if ((f & std::ios_base::oct) == std::ios_base::oct)
         base = 8;
      else if ((f & std::ios_base::hex) == std::ios_base::hex)
         base = 16;
      std::string result;

      std::size_t Bits = this->size() * base_type::limb_bits;

      if (base == 8 || base == 16)
      {
         if (this->sign())
            BOOST_MP_THROW_EXCEPTION(std::runtime_error("Base 8 or 16 printing of negative numbers is not supported."));
         limb_type       shift = base == 8 ? 3 : 4;
         limb_type       mask  = static_cast<limb_type>((1u << shift) - 1);
         cpp_int_backend t(*this);
         result.assign(Bits / shift + ((Bits % shift) ? 1 : 0), '0');
         std::string::difference_type pos      = static_cast<std::string::difference_type>(result.size() - 1u);
         char                         letter_a = f & std::ios_base::uppercase ? 'A' : 'a';
         for (std::size_t i = 0; i < Bits / shift; ++i)
         {
            char c = static_cast<char>('0' + static_cast<char>(t.limbs()[0] & mask));
            if (c > '9')
               c = static_cast<char>(c + letter_a - '9' - 1);
            result[static_cast<std::size_t>(pos)] = c;
            --pos;
            eval_right_shift(t, shift);
         }
         if (Bits % shift)
         {
            mask   = static_cast<limb_type>((1u << (Bits % shift)) - 1);
            char c = static_cast<char>('0' + static_cast<char>(t.limbs()[0] & mask));
            if (c > '9')
               c = static_cast<char>(c + letter_a - '9');
            result[static_cast<std::size_t>(pos)] = c;
         }
         //
         // Get rid of leading zeros:
         //
         std::string::size_type n = result.find_first_not_of('0');
         if (!result.empty() && (n == std::string::npos))
            n = result.size() - 1;
         result.erase(0, n);
         if (f & std::ios_base::showbase)
         {
            const char* pp = base == 8 ? "0" : (f & std::ios_base::uppercase) ? "0X" : "0x";
            result.insert(static_cast<std::string::size_type>(0), pp);
         }
      }
      else
      {
         result.assign(Bits / 3 + 1, '0');
         std::string::difference_type pos = static_cast<std::string::difference_type>(result.size() - 1u);
         cpp_int_backend              t(*this);
         cpp_int_backend              r;
         bool                         neg = false;
         if (t.sign())
         {
            t.negate();
            neg = true;
         }
         if (this->size() == 1)
         {
            result = std::to_string(t.limbs()[0]);
         }
         else
         {
            cpp_int_backend block10;
            block10 = max_block_10;
            while (eval_get_sign(t) != 0)
            {
               cpp_int_backend t2;
               divide_unsigned_helper(&t2, t, block10, r);
               t           = t2;
               limb_type v = r.limbs()[0];
               for (std::size_t i = 0; i < digits_per_block_10; ++i)
               {
                  char c = static_cast<char>('0' + static_cast<char>(v % 10));
                  v /= 10;
                  result[static_cast<std::size_t>(pos)] = c;
                  if (pos-- == 0u)
                     break;
               }
            }
         }
         std::string::size_type n = result.find_first_not_of('0');
         result.erase(0, n);
         if (result.empty())
            result = std::string(static_cast<std::size_t>(1u), '0');
         if (neg)
            result.insert(static_cast<std::string::size_type>(0), 1, '-');
         else if (f & std::ios_base::showpos)
            result.insert(static_cast<std::string::size_type>(0), 1, '+');
      }
      return result;
   }

 public:
   std::string str(std::streamsize /*digits*/, std::ios_base::fmtflags f) const
   {
      return do_get_string(f, trivial_tag());
   }

 private:
   template <class Container>
   void construct_from_container(const Container& c, const std::integral_constant<bool, false>&)
   {
      //
      // We assume that c is a sequence of (unsigned) bytes with the most significant byte first:
      //
      std::size_t newsize = static_cast<unsigned>(c.size() / sizeof(limb_type));
      if (c.size() % sizeof(limb_type))
      {
         ++newsize;
      }
      if (newsize)
      {
         this->resize(newsize, newsize); // May throw
         std::memset(this->limbs(), 0, this->size());
         typename Container::const_iterator i(c.begin()), j(c.end());
         std::size_t                           byte_location = static_cast<unsigned>(c.size() - 1);
         while (i != j)
         {
            std::size_t limb  = byte_location / sizeof(limb_type);
            std::size_t shift = (byte_location % sizeof(limb_type)) * CHAR_BIT;
            if (this->size() > limb)
               this->limbs()[limb] |= static_cast<limb_type>(static_cast<unsigned char>(*i)) << shift;
            ++i;
            --byte_location;
         }
      }
   }
   template <class Container>
   BOOST_MP_CXX14_CONSTEXPR void construct_from_container(const Container& c, const std::integral_constant<bool, true>&)
   {
      //
      // We assume that c is a sequence of (unsigned) bytes with the most significant byte first:
      //
      using local_limb_type = typename base_type::local_limb_type;
      *this->limbs() = 0;
      if (c.size())
      {
         typename Container::const_iterator i(c.begin()), j(c.end());
         std::size_t                           byte_location = static_cast<unsigned>(c.size() - 1);
         while (i != j)
         {
            std::size_t limb  = byte_location / sizeof(local_limb_type);
            std::size_t shift = (byte_location % sizeof(local_limb_type)) * CHAR_BIT;
            if (limb == 0)
               this->limbs()[0] |= static_cast<limb_type>(static_cast<unsigned char>(*i)) << shift;
            ++i;
            --byte_location;
         }
      }
   }

 public:
   template <class Container>
   BOOST_MP_CXX14_CONSTEXPR cpp_int_backend(const Container& c, typename std::enable_if<boost::multiprecision::detail::is_byte_container<Container>::value>::type const* = nullptr)
   {
      //
      // We assume that c is a sequence of (unsigned) bytes with the most significant byte first:
      //
      construct_from_container(c, trivial_tag());
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o, const std::integral_constant<bool, false>&, const std::integral_constant<bool, false>&) const noexcept
   {
      if (this->sign() != o.sign())
         return this->sign() ? -1 : 1;

      // Only do the compare if the same sign:
      int result = compare_unsigned(o);

      if (this->sign())
         result = -result;
      return result;
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o, const std::integral_constant<bool, true>&, const std::integral_constant<bool, false>&) const
   {
      cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> t(*this);
      return t.compare(o);
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o, const std::integral_constant<bool, false>&, const std::integral_constant<bool, true>&) const
   {
      cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> t(o);
      return compare(t);
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o, const std::integral_constant<bool, true>&, const std::integral_constant<bool, true>&) const noexcept
   {
      if (this->sign())
      {
         if (o.sign())
         {
            return *this->limbs() < *o.limbs() ? 1 : (*this->limbs() > *o.limbs() ? -1 : 0);
         }
         else
            return -1;
      }
      else
      {
         if (o.sign())
            return 1;
         return *this->limbs() < *o.limbs() ? -1 : (*this->limbs() > *o.limbs() ? 1 : 0);
      }
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR int compare(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) const noexcept
   {
      using t1 = std::integral_constant<bool, is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value>     ;
      using t2 = std::integral_constant<bool, is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value>;
      return compare_imp(o, t1(), t2());
   }
   template <std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
   BOOST_MP_CXX14_CONSTEXPR int compare_unsigned(const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) const noexcept
   {
      if (this->size() != o.size())
      {
         return this->size() > o.size() ? 1 : -1;
      }
      typename base_type::const_limb_pointer pa = this->limbs();
      typename base_type::const_limb_pointer pb = o.limbs();
      for (std::ptrdiff_t i = static_cast<std::ptrdiff_t>(static_cast<std::ptrdiff_t>(this->size()) - 1); i >= 0; --i)
      {
         if (pa[i] != pb[i])
            return pa[i] > pb[i] ? 1 : -1;
      }
      return 0;
   }
   template <class Arithmetic>
   BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_arithmetic<Arithmetic>::value, int>::type compare(Arithmetic i) const
   {
      // braindead version:
      cpp_int_backend t;
      t = i;
      return compare(t);
   }
};

} // namespace backends

namespace default_ops {

template <class Backend>
struct double_precision_type;

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct double_precision_type<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >
{
   using type = typename std::conditional<
       backends::is_fixed_precision<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value,
       backends::cpp_int_backend<
           (std::is_void<Allocator>::value ? 2 * backends::max_precision<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value
                                      : MinBits),
           2 * backends::max_precision<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value,
           SignType,
           Checked,
           Allocator>,
       backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::type;
};

} // namespace default_ops

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator, std::size_t MinBits2, std::size_t MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
struct is_equivalent_number_type<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, backends::cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >
   : public std::integral_constant<bool, std::numeric_limits<number<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, et_on> >::digits == std::numeric_limits<number<backends::cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>, et_on> >::digits>{};

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked>
struct expression_template_default<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, void> >
{
   static constexpr expression_template_option value = et_off;
};

using boost::multiprecision::backends::cpp_int_backend;

template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
struct number_category<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> > : public std::integral_constant<int, number_kind_integer>
{};

using cpp_int = number<cpp_int_backend<> >          ;
using cpp_rational_backend = rational_adaptor<cpp_int_backend<> >;
using cpp_rational = number<cpp_rational_backend>        ;

// Fixed precision unsigned types:
using uint128_t = number<cpp_int_backend<128, 128, unsigned_magnitude, unchecked, void> >  ;
using uint256_t = number<cpp_int_backend<256, 256, unsigned_magnitude, unchecked, void> >  ;
using uint512_t = number<cpp_int_backend<512, 512, unsigned_magnitude, unchecked, void> >  ;
using uint1024_t = number<cpp_int_backend<1024, 1024, unsigned_magnitude, unchecked, void> >;

// Fixed precision signed types:
using int128_t = number<cpp_int_backend<128, 128, signed_magnitude, unchecked, void> >  ;
using int256_t = number<cpp_int_backend<256, 256, signed_magnitude, unchecked, void> >  ;
using int512_t = number<cpp_int_backend<512, 512, signed_magnitude, unchecked, void> >  ;
using int1024_t = number<cpp_int_backend<1024, 1024, signed_magnitude, unchecked, void> >;

// Over again, but with checking enabled this time:
using checked_cpp_int = number<cpp_int_backend<0, 0, signed_magnitude, checked> >          ;
using checked_cpp_rational_backend = rational_adaptor<cpp_int_backend<0, 0, signed_magnitude, checked> >;
using checked_cpp_rational = number<checked_cpp_rational_backend>                               ;
// Fixed precision unsigned types:
using checked_uint128_t = number<cpp_int_backend<128, 128, unsigned_magnitude, checked, void> >  ;
using checked_uint256_t = number<cpp_int_backend<256, 256, unsigned_magnitude, checked, void> >  ;
using checked_uint512_t = number<cpp_int_backend<512, 512, unsigned_magnitude, checked, void> >  ;
using checked_uint1024_t = number<cpp_int_backend<1024, 1024, unsigned_magnitude, checked, void> >;

// Fixed precision signed types:
using checked_int128_t = number<cpp_int_backend<128, 128, signed_magnitude, checked, void> >  ;
using checked_int256_t = number<cpp_int_backend<256, 256, signed_magnitude, checked, void> >  ;
using checked_int512_t = number<cpp_int_backend<512, 512, signed_magnitude, checked, void> >  ;
using checked_int1024_t = number<cpp_int_backend<1024, 1024, signed_magnitude, checked, void> >;

#if defined(__GNUC__) && !defined(__clang__)
// see https://github.com/boostorg/multiprecision/issues/413
// and https://github.com/boostorg/multiprecision/issues/431
#pragma GCC diagnostic pop
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif

}} // namespace boost::multiprecision

//
// Last of all we include the implementations of all the eval_* non member functions:
//
#include <boost/multiprecision/cpp_int/limits.hpp>
#include <boost/multiprecision/cpp_int/comparison.hpp>
#include <boost/multiprecision/cpp_int/add.hpp>
#include <boost/multiprecision/cpp_int/multiply.hpp>
#include <boost/multiprecision/cpp_int/divide.hpp>
#include <boost/multiprecision/cpp_int/bitwise.hpp>
#include <boost/multiprecision/cpp_int/misc.hpp>
#include <boost/multiprecision/cpp_int/literals.hpp>
#include <boost/multiprecision/cpp_int/serialize.hpp>
#include <boost/multiprecision/cpp_int/import_export.hpp>

#endif