template <class T>
T get_uniform_random()
{
- static boost::random::uniform_int_distribution<T> minmax(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
+ static boost::random::uniform_int_distribution<T> minmax((std::numeric_limits<T>::min)(), (std::numeric_limits<T>::max)());
return minmax(rng);
}
{
if(u && v)
{
- unsigned shifts = std::min(boost::multiprecision::lsb(u), boost::multiprecision::lsb(v));
+ unsigned shifts = (std::min)(boost::multiprecision::lsb(u), boost::multiprecision::lsb(v));
if(shifts)
{
u >>= shifts;
return u + v;
}
-//
-// The Mixed Binary Euclid Algorithm
-// Sidi Mohamed Sedjelmaci
-// Electronic Notes in Discrete Mathematics 35 (2009) 169\96176
-//
-template <class T>
-T mixed_binary_gcd(T u, T v)
+template <typename Integer>
+inline BOOST_CXX14_CONSTEXPR Integer gcd_default(Integer a, Integer b) BOOST_GCD_NOEXCEPT(Integer)
{
- using std::swap;
- if(u < v)
- swap(u, v);
-
- unsigned shifts = 0;
-
- if(!u)
- return v;
- if(!v)
- return u;
-
- while(even(u) && even(v))
- {
- u >>= 1u;
- v >>= 1u;
- ++shifts;
- }
-
- while(v > 1)
- {
- u %= v;
- v -= u;
- if(!u)
- return v << shifts;
- if(!v)
- return u << shifts;
- while(even(u)) u >>= 1u;
- while(even(v)) v >>= 1u;
- if(u < v)
- swap(u, v);
- }
- return (v == 1 ? v : u) << shifts;
+ using boost::math::gcd;
+ return gcd(a, b);
}
+
template <class T>
void test_type(const char* name)
{
- using namespace boost::math::detail;
+ using namespace boost::math::gcd_detail;
typedef T int_type;
std::vector<pair<int_type, int_type> > data;
row_name += "> (random prime number products)";
typedef pair< function<int_type(int_type, int_type)>, string> f_test;
- array<f_test, 5> test_functions{ {
- { Stein_gcd<int_type>, "Stein_gcd" } ,
+ array<f_test, 6> test_functions{ {
+ { gcd_default<int_type>, "gcd" },
{ Euclid_gcd<int_type>, "Euclid_gcd" },
+ { Stein_gcd<int_type>, "Stein_gcd" } ,
+ { mixed_binary_gcd<int_type>, "mixed_binary_gcd" },
{ binary_textbook<int_type>, "Stein_gcd_textbook" },
{ euclid_textbook<int_type>, "gcd_euclid_textbook" },
- { mixed_binary_gcd<int_type>, "mixed_binary_gcd" }
} };
for_each(begin(test_functions), end(test_functions), test_function_template<int_type>(data, row_name.c_str()));
do m >>= 1; while(even(m));
// m == n
}
- return m << std::min(d_m, d_n);
+ return m << (std::min)(d_m, d_n);
}
+
boost::multiprecision::cpp_int big_gcd(const boost::multiprecision::cpp_int& a, const boost::multiprecision::cpp_int& b)
{
return boost::multiprecision::gcd(a, b);
if(vp->size() <= 2)
{
if(vp->size() == 1)
- *up = mixed_binary_gcd(*vp->limbs(), *up->limbs());
+ *up = boost::math::gcd_detail::mixed_binary_gcd(*vp->limbs(), *up->limbs());
else
{
double_limb_type i, j;
i = vp->limbs()[0] | (static_cast<double_limb_type>(vp->limbs()[1]) << sizeof(limb_type) * CHAR_BIT);
j = (up->size() == 1) ? *up->limbs() : up->limbs()[0] | (static_cast<double_limb_type>(up->limbs()[1]) << sizeof(limb_type) * CHAR_BIT);
- u = mixed_binary_gcd(i, j);
+ u = boost::math::gcd_detail::mixed_binary_gcd(i, j);
}
break;
}
test_n_bits(0, "consecutive first 1000 fibonacci numbers", &fibonacci_numbers_cpp_int_permution_1());
test_n_bits(0, "permutations of first 1000 fibonacci numbers", &fibonacci_numbers_cpp_int_permution_2());
*/
+ return 0;
}