1 /////////////////////////////////////////////////////////////////////////////// 2 // Copyright 2015 John Maddock. Distributed under the Boost 3 // Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #include <boost/multiprecision/cpp_int.hpp> 7 #include <boost/type_traits/is_nothrow_move_constructible.hpp> 8 #include <boost/type_traits/is_nothrow_move_assignable.hpp> 9 #include <boost/type_traits/has_nothrow_constructor.hpp> 10 #include <boost/type_traits/has_nothrow_assign.hpp> 11 #include <boost/type_traits/has_nothrow_copy.hpp> 12 #include <boost/static_assert.hpp> 13 14 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::int128_t::backend_type> > rat128_t; 15 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::uint128_t::backend_type> > urat128_t; 16 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::int512_t::backend_type> > rat512_t; 17 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::uint512_t::backend_type> > urat512_t; 18 19 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::checked_int128_t::backend_type> > checked_rat128_t; 20 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::checked_uint128_t::backend_type> > checked_urat128_t; 21 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::checked_int512_t::backend_type> > checked_rat512_t; 22 typedef boost::multiprecision::number<boost::multiprecision::rational_adaptor<boost::multiprecision::checked_uint512_t::backend_type> > checked_urat512_t; 23 24 #ifndef BOOST_NO_CXX11_NOEXCEPT 25 26 #if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_IS_NOTHROW_MOVE_CONSTRUCT) 27 // 28 // Move construct: 29 // 30 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<boost::multiprecision::cpp_rational>::value); 31 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<rat128_t>::value); 32 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<checked_rat128_t>::value); 33 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<urat128_t>::value); 34 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<checked_urat128_t>::value); 35 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<rat512_t>::value); 36 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<checked_rat512_t>::value); 37 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<urat512_t>::value); 38 BOOST_STATIC_ASSERT(boost::is_nothrow_move_constructible<checked_urat512_t>::value); 39 40 #endif 41 42 #if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_IS_NOTHROW_MOVE_ASSIGN) 43 // 44 // Move assign: 45 // 46 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<boost::multiprecision::cpp_rational>::value); 47 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<rat128_t>::value); 48 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<checked_rat128_t>::value); 49 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<urat128_t>::value); 50 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<checked_urat128_t>::value); 51 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<rat512_t>::value); 52 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<checked_rat512_t>::value); 53 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<urat512_t>::value); 54 BOOST_STATIC_ASSERT(boost::is_nothrow_move_assignable<checked_urat512_t>::value); 55 56 #endif 57 58 #if 0 59 // 60 // Everything below could/should be made to work, given modifications to Boost.Rational 61 // 62 63 64 // 65 // Construct: 66 // 67 #ifdef BOOST_HAS_NOTHROW_CONSTRUCTOR 68 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<boost::multiprecision::cpp_rational>::value); 69 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<rat128_t>::value); 70 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<checked_rat128_t>::value); 71 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<urat128_t>::value); 72 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<checked_urat128_t>::value); 73 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<rat512_t>::value); 74 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<checked_rat512_t>::value); 75 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<urat512_t>::value); 76 BOOST_STATIC_ASSERT(boost::has_nothrow_constructor<checked_urat512_t>::value); 77 #endif 78 // 79 // Copy construct: 80 // 81 #ifdef BOOST_HAS_NOTHROW_COPY 82 BOOST_STATIC_ASSERT(!boost::has_nothrow_copy<boost::multiprecision::cpp_rational>::value); 83 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<rat128_t>::value); 84 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<checked_rat128_t>::value); 85 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<urat128_t>::value); 86 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<checked_urat128_t>::value); 87 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<rat512_t>::value); 88 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<checked_rat512_t>::value); 89 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<urat512_t>::value); 90 BOOST_STATIC_ASSERT(boost::has_nothrow_copy<checked_urat512_t>::value); 91 #endif 92 // 93 // Assign: 94 // 95 #ifdef BOOST_HAS_NOTHROW_ASSIGN 96 BOOST_STATIC_ASSERT(!boost::has_nothrow_assign<boost::multiprecision::cpp_rational>::value); 97 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<rat128_t>::value); 98 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<checked_rat128_t>::value); 99 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<urat128_t>::value); 100 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<checked_urat128_t>::value); 101 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<rat512_t>::value); 102 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<checked_rat512_t>::value); 103 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<urat512_t>::value); 104 BOOST_STATIC_ASSERT(boost::has_nothrow_assign<checked_urat512_t>::value); 105 #endif 106 // 107 // Construct from int: 108 // 109 BOOST_STATIC_ASSERT(noexcept(boost::multiprecision::cpp_rational(std::declval<boost::multiprecision::signed_limb_type>()))); 110 BOOST_STATIC_ASSERT(noexcept(rat128_t(std::declval<boost::multiprecision::signed_limb_type>()))); 111 BOOST_STATIC_ASSERT(noexcept(checked_rat128_t(std::declval<boost::multiprecision::signed_limb_type>()))); 112 BOOST_STATIC_ASSERT(noexcept(urat128_t(std::declval<boost::multiprecision::signed_limb_type>()))); 113 BOOST_STATIC_ASSERT(!noexcept(checked_urat128_t(std::declval<boost::multiprecision::signed_limb_type>()))); 114 BOOST_STATIC_ASSERT(noexcept(rat512_t(std::declval<boost::multiprecision::signed_limb_type>()))); 115 BOOST_STATIC_ASSERT(noexcept(checked_rat512_t(std::declval<boost::multiprecision::signed_limb_type>()))); 116 BOOST_STATIC_ASSERT(noexcept(urat512_t(std::declval<boost::multiprecision::signed_limb_type>()))); 117 BOOST_STATIC_ASSERT(!noexcept(checked_urat512_t(std::declval<boost::multiprecision::signed_limb_type>()))); 118 // 119 // Construct from unsigned int: 120 // 121 BOOST_STATIC_ASSERT(noexcept(boost::multiprecision::cpp_rational(std::declval<boost::multiprecision::limb_type>()))); 122 BOOST_STATIC_ASSERT(noexcept(rat128_t(std::declval<boost::multiprecision::limb_type>()))); 123 BOOST_STATIC_ASSERT(noexcept(checked_rat128_t(std::declval<boost::multiprecision::limb_type>()))); 124 BOOST_STATIC_ASSERT(noexcept(urat128_t(std::declval<boost::multiprecision::limb_type>()))); 125 BOOST_STATIC_ASSERT(noexcept(checked_urat128_t(std::declval<boost::multiprecision::limb_type>()))); 126 BOOST_STATIC_ASSERT(noexcept(rat512_t(std::declval<boost::multiprecision::limb_type>()))); 127 BOOST_STATIC_ASSERT(noexcept(checked_rat512_t(std::declval<boost::multiprecision::limb_type>()))); 128 BOOST_STATIC_ASSERT(noexcept(urat512_t(std::declval<boost::multiprecision::limb_type>()))); 129 BOOST_STATIC_ASSERT(noexcept(checked_urat512_t(std::declval<boost::multiprecision::limb_type>()))); 130 // 131 // Assign from int: 132 // 133 BOOST_STATIC_ASSERT(noexcept(std::declval<boost::multiprecision::cpp_rational>() = std::declval<boost::multiprecision::signed_limb_type>())); 134 BOOST_STATIC_ASSERT(noexcept(std::declval<rat128_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 135 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat128_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 136 BOOST_STATIC_ASSERT(noexcept(std::declval<urat128_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 137 BOOST_STATIC_ASSERT(!noexcept(std::declval<checked_urat128_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 138 BOOST_STATIC_ASSERT(noexcept(std::declval<rat512_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 139 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat512_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 140 BOOST_STATIC_ASSERT(noexcept(std::declval<urat512_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 141 BOOST_STATIC_ASSERT(!noexcept(std::declval<checked_urat512_t>() = std::declval<boost::multiprecision::signed_limb_type>())); 142 // 143 // Assign from unsigned int: 144 // 145 BOOST_STATIC_ASSERT(noexcept(std::declval<boost::multiprecision::cpp_rational>() = std::declval<boost::multiprecision::limb_type>())); 146 BOOST_STATIC_ASSERT(noexcept(std::declval<rat128_t>() = std::declval<boost::multiprecision::limb_type>())); 147 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat128_t>() = std::declval<boost::multiprecision::limb_type>())); 148 BOOST_STATIC_ASSERT(noexcept(std::declval<urat128_t>() = std::declval<boost::multiprecision::limb_type>())); 149 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_urat128_t>() = std::declval<boost::multiprecision::limb_type>())); 150 BOOST_STATIC_ASSERT(noexcept(std::declval<rat512_t>() = std::declval<boost::multiprecision::limb_type>())); 151 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat512_t>() = std::declval<boost::multiprecision::limb_type>())); 152 BOOST_STATIC_ASSERT(noexcept(std::declval<urat512_t>() = std::declval<boost::multiprecision::limb_type>())); 153 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_urat512_t>() = std::declval<boost::multiprecision::limb_type>())); 154 155 #if defined(BOOST_LITTLE_ENDIAN) 156 // 157 // Construct from int: 158 // 159 BOOST_STATIC_ASSERT(noexcept(boost::multiprecision::cpp_rational(std::declval<boost::multiprecision::signed_double_limb_type>()))); 160 BOOST_STATIC_ASSERT(noexcept(rat128_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 161 BOOST_STATIC_ASSERT(noexcept(checked_rat128_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 162 BOOST_STATIC_ASSERT(noexcept(urat128_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 163 BOOST_STATIC_ASSERT(!noexcept(checked_urat128_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 164 BOOST_STATIC_ASSERT(noexcept(rat512_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 165 BOOST_STATIC_ASSERT(noexcept(checked_rat512_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 166 BOOST_STATIC_ASSERT(noexcept(urat512_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 167 BOOST_STATIC_ASSERT(!noexcept(checked_urat512_t(std::declval<boost::multiprecision::signed_double_limb_type>()))); 168 // 169 // Construct from unsigned int: 170 // 171 BOOST_STATIC_ASSERT(noexcept(boost::multiprecision::cpp_rational(std::declval<boost::multiprecision::double_limb_type>()))); 172 BOOST_STATIC_ASSERT(noexcept(rat128_t(std::declval<boost::multiprecision::double_limb_type>()))); 173 BOOST_STATIC_ASSERT(noexcept(checked_rat128_t(std::declval<boost::multiprecision::double_limb_type>()))); 174 BOOST_STATIC_ASSERT(noexcept(urat128_t(std::declval<boost::multiprecision::double_limb_type>()))); 175 BOOST_STATIC_ASSERT(noexcept(checked_urat128_t(std::declval<boost::multiprecision::double_limb_type>()))); 176 BOOST_STATIC_ASSERT(noexcept(rat512_t(std::declval<boost::multiprecision::double_limb_type>()))); 177 BOOST_STATIC_ASSERT(noexcept(checked_rat512_t(std::declval<boost::multiprecision::double_limb_type>()))); 178 BOOST_STATIC_ASSERT(noexcept(urat512_t(std::declval<boost::multiprecision::double_limb_type>()))); 179 BOOST_STATIC_ASSERT(noexcept(checked_urat512_t(std::declval<boost::multiprecision::double_limb_type>()))); 180 // 181 // Assign from int: 182 // 183 BOOST_STATIC_ASSERT(noexcept(std::declval<boost::multiprecision::cpp_rational>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 184 BOOST_STATIC_ASSERT(noexcept(std::declval<rat128_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 185 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat128_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 186 BOOST_STATIC_ASSERT(noexcept(std::declval<urat128_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 187 BOOST_STATIC_ASSERT(!noexcept(std::declval<checked_urat128_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 188 BOOST_STATIC_ASSERT(noexcept(std::declval<rat512_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 189 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat512_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 190 BOOST_STATIC_ASSERT(noexcept(std::declval<urat512_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 191 BOOST_STATIC_ASSERT(!noexcept(std::declval<checked_urat512_t>() = std::declval<boost::multiprecision::signed_double_limb_type>())); 192 // 193 // Assign from unsigned int: 194 // 195 BOOST_STATIC_ASSERT(noexcept(std::declval<boost::multiprecision::cpp_rational>() = std::declval<boost::multiprecision::double_limb_type>())); 196 BOOST_STATIC_ASSERT(noexcept(std::declval<rat128_t>() = std::declval<boost::multiprecision::double_limb_type>())); 197 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat128_t>() = std::declval<boost::multiprecision::double_limb_type>())); 198 BOOST_STATIC_ASSERT(noexcept(std::declval<urat128_t>() = std::declval<boost::multiprecision::double_limb_type>())); 199 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_urat128_t>() = std::declval<boost::multiprecision::double_limb_type>())); 200 BOOST_STATIC_ASSERT(noexcept(std::declval<rat512_t>() = std::declval<boost::multiprecision::double_limb_type>())); 201 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_rat512_t>() = std::declval<boost::multiprecision::double_limb_type>())); 202 BOOST_STATIC_ASSERT(noexcept(std::declval<urat512_t>() = std::declval<boost::multiprecision::double_limb_type>())); 203 BOOST_STATIC_ASSERT(noexcept(std::declval<checked_urat512_t>() = std::declval<boost::multiprecision::double_limb_type>())); 204 205 #endif 206 #endif // little endian 207 #endif // noexcept 208