gcd_constexpr14_test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // (C) Copyright John Maddock 2017.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/integer/common_factor.hpp>
  6. #ifndef BOOST_NO_CXX14_CONSTEXPR
  7. void test_constexpr1()
  8. {
  9. constexpr const boost::int64_t i = 347 * 463 * 727;
  10. constexpr const boost::int64_t j = 191 * 347 * 281;
  11. constexpr const boost::int64_t k = boost::integer::gcd(i, j);
  12. constexpr const boost::int64_t l = boost::integer::lcm(i, j);
  13. static_assert(k == 347, "Expected result not integer in constexpr gcd.");
  14. static_assert(l == 6268802158037, "Expected result not integer in constexpr lcm.");
  15. }
  16. void test_constexpr2()
  17. {
  18. constexpr const boost::uint64_t i = 347 * 463 * 727;
  19. constexpr const boost::uint64_t j = 191 * 347 * 281;
  20. constexpr const boost::uint64_t k = boost::integer::gcd(i, j);
  21. constexpr const boost::uint64_t l = boost::integer::lcm(i, j);
  22. static_assert(k == 347, "Expected result not integer in constexpr gcd.");
  23. static_assert(l == 6268802158037, "Expected result not integer in constexpr lcm.");
  24. }
  25. void test_constexpr3()
  26. {
  27. constexpr const boost::uint64_t i = 347 * 463 * 727;
  28. constexpr const boost::uint64_t j = 191 * 347 * 281;
  29. constexpr const boost::uint64_t k = boost::integer::gcd_detail::Euclid_gcd(i, j);
  30. static_assert(k == 347, "Expected result not integer in constexpr gcd.");
  31. }
  32. void test_constexpr4()
  33. {
  34. constexpr const boost::uint64_t i = 347 * 463 * 727;
  35. constexpr const boost::uint64_t j = 191 * 347 * 281;
  36. constexpr const boost::uint64_t k = boost::integer::gcd_detail::mixed_binary_gcd(i, j);
  37. static_assert(k == 347, "Expected result not integer in constexpr gcd.");
  38. }
  39. void test_constexpr5()
  40. {
  41. constexpr const boost::uint64_t i = 347 * 463 * 727;
  42. constexpr const boost::uint64_t j = 191 * 347 * 281;
  43. constexpr const boost::uint64_t k = boost::integer::gcd_detail::Stein_gcd(i, j);
  44. static_assert(k == 347, "Expected result not integer in constexpr gcd.");
  45. }
  46. #endif