Chris@16: // Boost common_factor_ct.hpp header file ----------------------------------// Chris@16: Chris@16: // (C) Copyright Daryle Walker and Stephen Cleary 2001-2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #ifndef BOOST_MATH_COMMON_FACTOR_CT_HPP Chris@16: #define BOOST_MATH_COMMON_FACTOR_CT_HPP Chris@16: Chris@16: #include // self include Chris@16: #include // for BOOST_STATIC_CONSTANT, etc. Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace math Chris@16: { Chris@16: Chris@16: // Implementation details --------------------------------------------------// Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: // Build GCD with Euclid's recursive algorithm Chris@16: template < static_gcd_type Value1, static_gcd_type Value2 > Chris@16: struct static_gcd_helper_t Chris@16: { Chris@16: private: Chris@16: BOOST_STATIC_CONSTANT( static_gcd_type, new_value1 = Value2 ); Chris@16: BOOST_STATIC_CONSTANT( static_gcd_type, new_value2 = Value1 % Value2 ); Chris@16: Chris@16: #ifndef __BORLANDC__ Chris@16: #define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast(Value) Chris@16: #else Chris@16: typedef static_gcd_helper_t self_type; Chris@16: #define BOOST_DETAIL_GCD_HELPER_VAL(Value) (self_type:: Value ) Chris@16: #endif Chris@16: Chris@16: typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1), Chris@16: BOOST_DETAIL_GCD_HELPER_VAL(new_value2) > next_step_type; Chris@16: Chris@16: #undef BOOST_DETAIL_GCD_HELPER_VAL Chris@16: Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT( static_gcd_type, value = next_step_type::value ); Chris@16: }; Chris@16: Chris@16: // Non-recursive case Chris@16: template < static_gcd_type Value1 > Chris@16: struct static_gcd_helper_t< Value1, 0UL > Chris@16: { Chris@16: BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 ); Chris@16: }; Chris@16: Chris@16: // Build the LCM from the GCD Chris@16: template < static_gcd_type Value1, static_gcd_type Value2 > Chris@16: struct static_lcm_helper_t Chris@16: { Chris@16: typedef static_gcd_helper_t gcd_type; Chris@16: Chris@16: BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 / gcd_type::value Chris@16: * Value2 ); Chris@16: }; Chris@16: Chris@16: // Special case for zero-GCD values Chris@16: template < > Chris@16: struct static_lcm_helper_t< 0UL, 0UL > Chris@16: { Chris@16: BOOST_STATIC_CONSTANT( static_gcd_type, value = 0UL ); Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: Chris@16: // Compile-time greatest common divisor evaluator class declaration --------// Chris@16: Chris@16: template < static_gcd_type Value1, static_gcd_type Value2 > Chris@16: struct static_gcd : public mpl::integral_c::value) > Chris@16: { Chris@16: }; // boost::math::static_gcd Chris@16: Chris@16: Chris@16: // Compile-time least common multiple evaluator class declaration ----------// Chris@16: Chris@16: template < static_gcd_type Value1, static_gcd_type Value2 > Chris@16: struct static_lcm : public mpl::integral_c::value) > Chris@16: { Chris@16: }; // boost::math::static_lcm Chris@16: Chris@16: Chris@16: } // namespace math Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_MATH_COMMON_FACTOR_CT_HPP