diff --git a/include/boost/math/common_factor.hpp b/include/boost/integer/common_factor.hpp similarity index 63% rename from include/boost/math/common_factor.hpp rename to include/boost/integer/common_factor.hpp index 21a71e4..fab9199 100644 --- a/include/boost/math/common_factor.hpp +++ b/include/boost/integer/common_factor.hpp @@ -7,10 +7,10 @@ // See http://www.boost.org for updates, documentation, and revision history. -#ifndef BOOST_MATH_COMMON_FACTOR_HPP -#define BOOST_MATH_COMMON_FACTOR_HPP +#ifndef BOOST_INTEGER_COMMON_FACTOR_HPP +#define BOOST_INTEGER_COMMON_FACTOR_HPP -#include -#include +#include +#include -#endif // BOOST_MATH_COMMON_FACTOR_HPP +#endif // BOOST_INTEGER_COMMON_FACTOR_HPP diff --git a/include/boost/math/common_factor_ct.hpp b/include/boost/integer/common_factor_ct.hpp similarity index 69% rename from include/boost/math/common_factor_ct.hpp rename to include/boost/integer/common_factor_ct.hpp index bf58b94..0671d16 100644 --- a/include/boost/math/common_factor_ct.hpp +++ b/include/boost/integer/common_factor_ct.hpp @@ -7,16 +7,15 @@ // See http://www.boost.org for updates, documentation, and revision history. -#ifndef BOOST_MATH_COMMON_FACTOR_CT_HPP -#define BOOST_MATH_COMMON_FACTOR_CT_HPP +#ifndef BOOST_INTEGER_COMMON_FACTOR_CT_HPP +#define BOOST_INTEGER_COMMON_FACTOR_CT_HPP -#include // self include +#include // self include #include // for BOOST_STATIC_CONSTANT, etc. -#include namespace boost { -namespace math +namespace integer { // Implementation details --------------------------------------------------// @@ -76,22 +75,28 @@ namespace detail // Compile-time greatest common divisor evaluator class declaration --------// -template < static_gcd_type Value1, static_gcd_type Value2 > -struct static_gcd : public mpl::integral_c::value) > +template < static_gcd_type Value1, static_gcd_type Value2 > struct static_gcd { -}; // boost::math::static_gcd + BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_gcd_helper_t::value) ); +}; // boost::integer::static_gcd +#if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) +template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_gcd< Value1, Value2 >::value; +#endif // Compile-time least common multiple evaluator class declaration ----------// -template < static_gcd_type Value1, static_gcd_type Value2 > -struct static_lcm : public mpl::integral_c::value) > +template < static_gcd_type Value1, static_gcd_type Value2 > struct static_lcm { -}; // boost::math::static_lcm + BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_lcm_helper_t::value) ); +}; // boost::integer::static_lcm +#if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) +template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_lcm< Value1, Value2 >::value; +#endif -} // namespace math +} // namespace integer } // namespace boost -#endif // BOOST_MATH_COMMON_FACTOR_CT_HPP +#endif // BOOST_INTEGER_COMMON_FACTOR_CT_HPP diff --git a/include/boost/math/common_factor_rt.hpp b/include/boost/integer/common_factor_rt.hpp similarity index 97% rename from include/boost/math/common_factor_rt.hpp rename to include/boost/integer/common_factor_rt.hpp index 10a92eb..c2b54db 100644 --- a/include/boost/math/common_factor_rt.hpp +++ b/include/boost/integer/common_factor_rt.hpp @@ -12,10 +12,10 @@ // See http://www.boost.org for updates, documentation, and revision history. -#ifndef BOOST_MATH_COMMON_FACTOR_RT_HPP -#define BOOST_MATH_COMMON_FACTOR_RT_HPP +#ifndef BOOST_INTEGER_COMMON_FACTOR_RT_HPP +#define BOOST_INTEGER_COMMON_FACTOR_RT_HPP -#include // self include +#include // self include #include // for BOOST_NESTED_TEMPLATE, etc. #include // for std::numeric_limits @@ -29,7 +29,7 @@ namespace boost { -namespace math +namespace integer { @@ -55,7 +55,7 @@ public: result_type operator ()( first_argument_type const &a, second_argument_type const &b ) const; -}; // boost::math::gcd_evaluator +}; // boost::integer::gcd_evaluator // Least common multiple evaluator class declaration -----------------------// @@ -71,7 +71,7 @@ public: result_type operator ()( first_argument_type const &a, second_argument_type const &b ) const; -}; // boost::math::lcm_evaluator +}; // boost::integer::lcm_evaluator // Implementation details --------------------------------------------------// @@ -450,11 +450,11 @@ lcm } -} // namespace math +} // namespace integer } // namespace boost #ifdef BOOST_MSVC #pragma warning(pop) #endif -#endif // BOOST_MATH_COMMON_FACTOR_RT_HPP +#endif // BOOST_INTEGER_COMMON_FACTOR_RT_HPP diff --git a/include/boost/integer_fwd.hpp b/include/boost/integer_fwd.hpp index 20eff2b..10577ae 100644 --- a/include/boost/integer_fwd.hpp +++ b/include/boost/integer_fwd.hpp @@ -158,6 +158,29 @@ template struct static_unsigned_max; + +// From + +#ifdef BOOST_NO_INTEGRAL_INT64_T + typedef unsigned long static_gcd_type; +#else + typedef boost::uintmax_t static_gcd_type; +#endif + +template < static_gcd_type Value1, static_gcd_type Value2 > + struct static_gcd; +template < static_gcd_type Value1, static_gcd_type Value2 > + struct static_lcm; + + +// From + +template < typename IntegerType > + class gcd_evaluator; +template < typename IntegerType > + class lcm_evaluator; + + } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 8a60c36..f94bce9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -25,4 +25,5 @@ test-suite integer [ compile-fail fail_uint_exact.cpp ] [ compile-fail fail_uint_fast.cpp ] [ compile-fail fail_uint_least.cpp ] + [ run common_factor_test.cpp ] ; diff --git a/test/common_factor_test.cpp b/test/common_factor_test.cpp index 11c32a6..81ffc47 100644 --- a/test/common_factor_test.cpp +++ b/test/common_factor_test.cpp @@ -17,12 +17,12 @@ #define BOOST_TEST_MAIN "Boost.Math GCD & LCM unit tests" -#include // for BOOST_MSVC, etc. +#include + +#include // for BOOST_MSVC, etc. #include -#include // for boost::math::gcd, etc. -#include // for boost::mpl::list #include -#include +#include #include // for std::basic_istream #include // for std::numeric_limits @@ -109,23 +109,6 @@ MyUnsigned1 dummy2; MyInt2 dummy3; MyUnsigned2 dummy4; -// Various types to test with each GCD/LCM -typedef ::boost::mpl::list signed_test_types; -typedef ::boost::mpl::list unsigned_test_types; - } // namespace #define BOOST_NO_MACRO_EXPAND /**/ @@ -259,220 +242,232 @@ inline ostream& operator<<(ostream& os, unsigned __int64 i) } // namespace std // GCD tests -BOOST_AUTO_TEST_SUITE( gcd_test_suite ) // GCD on signed integer types -BOOST_AUTO_TEST_CASE_TEMPLATE( gcd_int_test, T, signed_test_types ) +template< class T > void gcd_int_test() // signed_test_types { -#ifndef BOOST_MSVC - using boost::math::gcd; -#else - using namespace boost::math; -#endif + using boost::integer::gcd; // Originally from Boost.Rational tests - BOOST_CHECK_EQUAL( gcd( 1, -1), static_cast( 1) ); - BOOST_CHECK_EQUAL( gcd( -1, 1), static_cast( 1) ); - BOOST_CHECK_EQUAL( gcd( 1, 1), static_cast( 1) ); - BOOST_CHECK_EQUAL( gcd( -1, -1), static_cast( 1) ); - BOOST_CHECK_EQUAL( gcd( 0, 0), static_cast( 0) ); - BOOST_CHECK_EQUAL( gcd( 7, 0), static_cast( 7) ); - BOOST_CHECK_EQUAL( gcd( 0, 9), static_cast( 9) ); - BOOST_CHECK_EQUAL( gcd( -7, 0), static_cast( 7) ); - BOOST_CHECK_EQUAL( gcd( 0, -9), static_cast( 9) ); - BOOST_CHECK_EQUAL( gcd( 42, 30), static_cast( 6) ); - BOOST_CHECK_EQUAL( gcd( 6, -9), static_cast( 3) ); - BOOST_CHECK_EQUAL( gcd(-10, -10), static_cast(10) ); - BOOST_CHECK_EQUAL( gcd(-25, -10), static_cast( 5) ); - BOOST_CHECK_EQUAL( gcd( 3, 7), static_cast( 1) ); - BOOST_CHECK_EQUAL( gcd( 8, 9), static_cast( 1) ); - BOOST_CHECK_EQUAL( gcd( 7, 49), static_cast( 7) ); + BOOST_TEST_EQ( gcd( 1, -1), static_cast( 1) ); + BOOST_TEST_EQ( gcd( -1, 1), static_cast( 1) ); + BOOST_TEST_EQ( gcd( 1, 1), static_cast( 1) ); + BOOST_TEST_EQ( gcd( -1, -1), static_cast( 1) ); + BOOST_TEST_EQ( gcd( 0, 0), static_cast( 0) ); + BOOST_TEST_EQ( gcd( 7, 0), static_cast( 7) ); + BOOST_TEST_EQ( gcd( 0, 9), static_cast( 9) ); + BOOST_TEST_EQ( gcd( -7, 0), static_cast( 7) ); + BOOST_TEST_EQ( gcd( 0, -9), static_cast( 9) ); + BOOST_TEST_EQ( gcd( 42, 30), static_cast( 6) ); + BOOST_TEST_EQ( gcd( 6, -9), static_cast( 3) ); + BOOST_TEST_EQ( gcd(-10, -10), static_cast(10) ); + BOOST_TEST_EQ( gcd(-25, -10), static_cast( 5) ); + BOOST_TEST_EQ( gcd( 3, 7), static_cast( 1) ); + BOOST_TEST_EQ( gcd( 8, 9), static_cast( 1) ); + BOOST_TEST_EQ( gcd( 7, 49), static_cast( 7) ); } // GCD on unmarked signed integer type -BOOST_AUTO_TEST_CASE( gcd_unmarked_int_test ) +void gcd_unmarked_int_test() { -#ifndef BOOST_MSVC - using boost::math::gcd; -#else - using namespace boost::math; -#endif + using boost::integer::gcd; // The regular signed-integer GCD function performs the unsigned version, // then does an absolute-value on the result. Signed types that are not // marked as such (due to no std::numeric_limits specialization) may be off // by a sign. - BOOST_CHECK_EQUAL( abs(gcd( 1, -1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(gcd( -1, 1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(gcd( 1, 1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(gcd( -1, -1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(gcd( 0, 0 )), MyInt2( 0) ); - BOOST_CHECK_EQUAL( abs(gcd( 7, 0 )), MyInt2( 7) ); - BOOST_CHECK_EQUAL( abs(gcd( 0, 9 )), MyInt2( 9) ); - BOOST_CHECK_EQUAL( abs(gcd( -7, 0 )), MyInt2( 7) ); - BOOST_CHECK_EQUAL( abs(gcd( 0, -9 )), MyInt2( 9) ); - BOOST_CHECK_EQUAL( abs(gcd( 42, 30 )), MyInt2( 6) ); - BOOST_CHECK_EQUAL( abs(gcd( 6, -9 )), MyInt2( 3) ); - BOOST_CHECK_EQUAL( abs(gcd( -10, -10 )), MyInt2(10) ); - BOOST_CHECK_EQUAL( abs(gcd( -25, -10 )), MyInt2( 5) ); - BOOST_CHECK_EQUAL( abs(gcd( 3, 7 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(gcd( 8, 9 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(gcd( 7, 49 )), MyInt2( 7) ); + BOOST_TEST_EQ( abs(gcd( 1, -1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(gcd( -1, 1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(gcd( 1, 1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(gcd( -1, -1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(gcd( 0, 0 )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(gcd( 7, 0 )), MyInt2( 7) ); + BOOST_TEST_EQ( abs(gcd( 0, 9 )), MyInt2( 9) ); + BOOST_TEST_EQ( abs(gcd( -7, 0 )), MyInt2( 7) ); + BOOST_TEST_EQ( abs(gcd( 0, -9 )), MyInt2( 9) ); + BOOST_TEST_EQ( abs(gcd( 42, 30 )), MyInt2( 6) ); + BOOST_TEST_EQ( abs(gcd( 6, -9 )), MyInt2( 3) ); + BOOST_TEST_EQ( abs(gcd( -10, -10 )), MyInt2(10) ); + BOOST_TEST_EQ( abs(gcd( -25, -10 )), MyInt2( 5) ); + BOOST_TEST_EQ( abs(gcd( 3, 7 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(gcd( 8, 9 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(gcd( 7, 49 )), MyInt2( 7) ); } // GCD on unsigned integer types -BOOST_AUTO_TEST_CASE_TEMPLATE( gcd_unsigned_test, T, unsigned_test_types ) +template< class T > void gcd_unsigned_test() // unsigned_test_types { -#ifndef BOOST_MSVC - using boost::math::gcd; -#else - using namespace boost::math; -#endif + using boost::integer::gcd; // Note that unmarked types (i.e. have no std::numeric_limits // specialization) are treated like non/unsigned types - BOOST_CHECK_EQUAL( gcd( 1u, 1u), static_cast( 1u) ); - BOOST_CHECK_EQUAL( gcd( 0u, 0u), static_cast( 0u) ); - BOOST_CHECK_EQUAL( gcd( 7u, 0u), static_cast( 7u) ); - BOOST_CHECK_EQUAL( gcd( 0u, 9u), static_cast( 9u) ); - BOOST_CHECK_EQUAL( gcd(42u, 30u), static_cast( 6u) ); - BOOST_CHECK_EQUAL( gcd( 3u, 7u), static_cast( 1u) ); - BOOST_CHECK_EQUAL( gcd( 8u, 9u), static_cast( 1u) ); - BOOST_CHECK_EQUAL( gcd( 7u, 49u), static_cast( 7u) ); + BOOST_TEST_EQ( gcd( 1u, 1u), static_cast( 1u) ); + BOOST_TEST_EQ( gcd( 0u, 0u), static_cast( 0u) ); + BOOST_TEST_EQ( gcd( 7u, 0u), static_cast( 7u) ); + BOOST_TEST_EQ( gcd( 0u, 9u), static_cast( 9u) ); + BOOST_TEST_EQ( gcd(42u, 30u), static_cast( 6u) ); + BOOST_TEST_EQ( gcd( 3u, 7u), static_cast( 1u) ); + BOOST_TEST_EQ( gcd( 8u, 9u), static_cast( 1u) ); + BOOST_TEST_EQ( gcd( 7u, 49u), static_cast( 7u) ); } // GCD at compile-time -BOOST_AUTO_TEST_CASE( gcd_static_test ) +void gcd_static_test() { -#ifndef BOOST_MSVC - using boost::math::static_gcd; -#else - using namespace boost::math; -#endif + using boost::integer::static_gcd; - // Can't use "BOOST_CHECK_EQUAL", otherwise the "value" member will be - // disqualified as compile-time-only constant, needing explicit definition - BOOST_CHECK( (static_gcd< 1, 1>::value) == 1 ); - BOOST_CHECK( (static_gcd< 0, 0>::value) == 0 ); - BOOST_CHECK( (static_gcd< 7, 0>::value) == 7 ); - BOOST_CHECK( (static_gcd< 0, 9>::value) == 9 ); - BOOST_CHECK( (static_gcd<42, 30>::value) == 6 ); - BOOST_CHECK( (static_gcd< 3, 7>::value) == 1 ); - BOOST_CHECK( (static_gcd< 8, 9>::value) == 1 ); - BOOST_CHECK( (static_gcd< 7, 49>::value) == 7 ); + BOOST_TEST_EQ( (static_gcd< 1, 1>::value), 1 ); + BOOST_TEST_EQ( (static_gcd< 0, 0>::value), 0 ); + BOOST_TEST_EQ( (static_gcd< 7, 0>::value), 7 ); + BOOST_TEST_EQ( (static_gcd< 0, 9>::value), 9 ); + BOOST_TEST_EQ( (static_gcd<42, 30>::value), 6 ); + BOOST_TEST_EQ( (static_gcd< 3, 7>::value), 1 ); + BOOST_TEST_EQ( (static_gcd< 8, 9>::value), 1 ); + BOOST_TEST_EQ( (static_gcd< 7, 49>::value), 7 ); } // TODO: non-built-in signed and unsigned integer tests, with and without // numeric_limits specialization; polynominal tests; note any changes if // built-ins switch to binary-GCD algorithm -BOOST_AUTO_TEST_SUITE_END() - // LCM tests -BOOST_AUTO_TEST_SUITE( lcm_test_suite ) // LCM on signed integer types -BOOST_AUTO_TEST_CASE_TEMPLATE( lcm_int_test, T, signed_test_types ) +template< class T > void lcm_int_test() // signed_test_types { -#ifndef BOOST_MSVC - using boost::math::lcm; -#else - using namespace boost::math; -#endif + using boost::integer::lcm; // Originally from Boost.Rational tests - BOOST_CHECK_EQUAL( lcm( 1, -1), static_cast( 1) ); - BOOST_CHECK_EQUAL( lcm( -1, 1), static_cast( 1) ); - BOOST_CHECK_EQUAL( lcm( 1, 1), static_cast( 1) ); - BOOST_CHECK_EQUAL( lcm( -1, -1), static_cast( 1) ); - BOOST_CHECK_EQUAL( lcm( 0, 0), static_cast( 0) ); - BOOST_CHECK_EQUAL( lcm( 6, 0), static_cast( 0) ); - BOOST_CHECK_EQUAL( lcm( 0, 7), static_cast( 0) ); - BOOST_CHECK_EQUAL( lcm( -5, 0), static_cast( 0) ); - BOOST_CHECK_EQUAL( lcm( 0, -4), static_cast( 0) ); - BOOST_CHECK_EQUAL( lcm( 18, 30), static_cast(90) ); - BOOST_CHECK_EQUAL( lcm( -6, 9), static_cast(18) ); - BOOST_CHECK_EQUAL( lcm(-10, -10), static_cast(10) ); - BOOST_CHECK_EQUAL( lcm( 25, -10), static_cast(50) ); - BOOST_CHECK_EQUAL( lcm( 3, 7), static_cast(21) ); - BOOST_CHECK_EQUAL( lcm( 8, 9), static_cast(72) ); - BOOST_CHECK_EQUAL( lcm( 7, 49), static_cast(49) ); + BOOST_TEST_EQ( lcm( 1, -1), static_cast( 1) ); + BOOST_TEST_EQ( lcm( -1, 1), static_cast( 1) ); + BOOST_TEST_EQ( lcm( 1, 1), static_cast( 1) ); + BOOST_TEST_EQ( lcm( -1, -1), static_cast( 1) ); + BOOST_TEST_EQ( lcm( 0, 0), static_cast( 0) ); + BOOST_TEST_EQ( lcm( 6, 0), static_cast( 0) ); + BOOST_TEST_EQ( lcm( 0, 7), static_cast( 0) ); + BOOST_TEST_EQ( lcm( -5, 0), static_cast( 0) ); + BOOST_TEST_EQ( lcm( 0, -4), static_cast( 0) ); + BOOST_TEST_EQ( lcm( 18, 30), static_cast(90) ); + BOOST_TEST_EQ( lcm( -6, 9), static_cast(18) ); + BOOST_TEST_EQ( lcm(-10, -10), static_cast(10) ); + BOOST_TEST_EQ( lcm( 25, -10), static_cast(50) ); + BOOST_TEST_EQ( lcm( 3, 7), static_cast(21) ); + BOOST_TEST_EQ( lcm( 8, 9), static_cast(72) ); + BOOST_TEST_EQ( lcm( 7, 49), static_cast(49) ); } // LCM on unmarked signed integer type -BOOST_AUTO_TEST_CASE( lcm_unmarked_int_test ) +void lcm_unmarked_int_test() { -#ifndef BOOST_MSVC - using boost::math::lcm; -#else - using namespace boost::math; -#endif + using boost::integer::lcm; // The regular signed-integer LCM function performs the unsigned version, // then does an absolute-value on the result. Signed types that are not // marked as such (due to no std::numeric_limits specialization) may be off // by a sign. - BOOST_CHECK_EQUAL( abs(lcm( 1, -1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(lcm( -1, 1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(lcm( 1, 1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(lcm( -1, -1 )), MyInt2( 1) ); - BOOST_CHECK_EQUAL( abs(lcm( 0, 0 )), MyInt2( 0) ); - BOOST_CHECK_EQUAL( abs(lcm( 6, 0 )), MyInt2( 0) ); - BOOST_CHECK_EQUAL( abs(lcm( 0, 7 )), MyInt2( 0) ); - BOOST_CHECK_EQUAL( abs(lcm( -5, 0 )), MyInt2( 0) ); - BOOST_CHECK_EQUAL( abs(lcm( 0, -4 )), MyInt2( 0) ); - BOOST_CHECK_EQUAL( abs(lcm( 18, 30 )), MyInt2(90) ); - BOOST_CHECK_EQUAL( abs(lcm( -6, 9 )), MyInt2(18) ); - BOOST_CHECK_EQUAL( abs(lcm( -10, -10 )), MyInt2(10) ); - BOOST_CHECK_EQUAL( abs(lcm( 25, -10 )), MyInt2(50) ); - BOOST_CHECK_EQUAL( abs(lcm( 3, 7 )), MyInt2(21) ); - BOOST_CHECK_EQUAL( abs(lcm( 8, 9 )), MyInt2(72) ); - BOOST_CHECK_EQUAL( abs(lcm( 7, 49 )), MyInt2(49) ); + BOOST_TEST_EQ( abs(lcm( 1, -1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(lcm( -1, 1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(lcm( 1, 1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(lcm( -1, -1 )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(lcm( 0, 0 )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(lcm( 6, 0 )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(lcm( 0, 7 )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(lcm( -5, 0 )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(lcm( 0, -4 )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(lcm( 18, 30 )), MyInt2(90) ); + BOOST_TEST_EQ( abs(lcm( -6, 9 )), MyInt2(18) ); + BOOST_TEST_EQ( abs(lcm( -10, -10 )), MyInt2(10) ); + BOOST_TEST_EQ( abs(lcm( 25, -10 )), MyInt2(50) ); + BOOST_TEST_EQ( abs(lcm( 3, 7 )), MyInt2(21) ); + BOOST_TEST_EQ( abs(lcm( 8, 9 )), MyInt2(72) ); + BOOST_TEST_EQ( abs(lcm( 7, 49 )), MyInt2(49) ); } // LCM on unsigned integer types -BOOST_AUTO_TEST_CASE_TEMPLATE( lcm_unsigned_test, T, unsigned_test_types ) +template< class T > void lcm_unsigned_test() // unsigned_test_types { -#ifndef BOOST_MSVC - using boost::math::lcm; -#else - using namespace boost::math; -#endif + using boost::integer::lcm; // Note that unmarked types (i.e. have no std::numeric_limits // specialization) are treated like non/unsigned types - BOOST_CHECK_EQUAL( lcm( 1u, 1u), static_cast( 1u) ); - BOOST_CHECK_EQUAL( lcm( 0u, 0u), static_cast( 0u) ); - BOOST_CHECK_EQUAL( lcm( 6u, 0u), static_cast( 0u) ); - BOOST_CHECK_EQUAL( lcm( 0u, 7u), static_cast( 0u) ); - BOOST_CHECK_EQUAL( lcm(18u, 30u), static_cast(90u) ); - BOOST_CHECK_EQUAL( lcm( 3u, 7u), static_cast(21u) ); - BOOST_CHECK_EQUAL( lcm( 8u, 9u), static_cast(72u) ); - BOOST_CHECK_EQUAL( lcm( 7u, 49u), static_cast(49u) ); + BOOST_TEST_EQ( lcm( 1u, 1u), static_cast( 1u) ); + BOOST_TEST_EQ( lcm( 0u, 0u), static_cast( 0u) ); + BOOST_TEST_EQ( lcm( 6u, 0u), static_cast( 0u) ); + BOOST_TEST_EQ( lcm( 0u, 7u), static_cast( 0u) ); + BOOST_TEST_EQ( lcm(18u, 30u), static_cast(90u) ); + BOOST_TEST_EQ( lcm( 3u, 7u), static_cast(21u) ); + BOOST_TEST_EQ( lcm( 8u, 9u), static_cast(72u) ); + BOOST_TEST_EQ( lcm( 7u, 49u), static_cast(49u) ); } // LCM at compile-time -BOOST_AUTO_TEST_CASE( lcm_static_test ) +void lcm_static_test() { -#ifndef BOOST_MSVC - using boost::math::static_lcm; -#else - using namespace boost::math; -#endif + using boost::integer::static_lcm; - // Can't use "BOOST_CHECK_EQUAL", otherwise the "value" member will be - // disqualified as compile-time-only constant, needing explicit definition - BOOST_CHECK( (static_lcm< 1, 1>::value) == 1 ); - BOOST_CHECK( (static_lcm< 0, 0>::value) == 0 ); - BOOST_CHECK( (static_lcm< 6, 0>::value) == 0 ); - BOOST_CHECK( (static_lcm< 0, 7>::value) == 0 ); - BOOST_CHECK( (static_lcm<18, 30>::value) == 90 ); - BOOST_CHECK( (static_lcm< 3, 7>::value) == 21 ); - BOOST_CHECK( (static_lcm< 8, 9>::value) == 72 ); - BOOST_CHECK( (static_lcm< 7, 49>::value) == 49 ); + BOOST_TEST_EQ( (static_lcm< 1, 1>::value), 1 ); + BOOST_TEST_EQ( (static_lcm< 0, 0>::value), 0 ); + BOOST_TEST_EQ( (static_lcm< 6, 0>::value), 0 ); + BOOST_TEST_EQ( (static_lcm< 0, 7>::value), 0 ); + BOOST_TEST_EQ( (static_lcm<18, 30>::value), 90 ); + BOOST_TEST_EQ( (static_lcm< 3, 7>::value), 21 ); + BOOST_TEST_EQ( (static_lcm< 8, 9>::value), 72 ); + BOOST_TEST_EQ( (static_lcm< 7, 49>::value), 49 ); } // TODO: see GCD to-do -BOOST_AUTO_TEST_SUITE_END() +// main + +// Various types to test with each GCD/LCM + +#define TEST_SIGNED_( test ) \ + test(); \ + test(); \ + test(); \ + test(); \ + test(); + +#ifdef BOOST_HAS_LONG_LONG +# define TEST_SIGNED( test ) \ + TEST_SIGNED_( test ) \ + test(); +#elif defined(BOOST_HAS_MS_INT64) +# define TEST_SIGNED( test ) \ + TEST_SIGNED_( test ) \ + test<__int64>(); +#endif + +#define TEST_UNSIGNED_( test ) \ + test(); \ + test(); \ + test(); \ + test(); \ + test(); \ + test(); + +#ifdef BOOST_HAS_LONG_LONG +# define TEST_UNSIGNED( test ) \ + TEST_UNSIGNED_( test ) \ + test(); +#elif defined(BOOST_HAS_MS_INT64) +# define TEST_UNSIGNED( test ) \ + TEST_UNSIGNED_( test ) \ + test(); +#endif + +int main() +{ + TEST_SIGNED( gcd_int_test ) + gcd_unmarked_int_test(); + TEST_UNSIGNED( gcd_unsigned_test ) + gcd_static_test(); + + TEST_SIGNED( lcm_int_test ) + lcm_unmarked_int_test(); + TEST_UNSIGNED( lcm_unsigned_test ) + lcm_static_test(); + + return boost::report_errors(); +}