Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:23

0001 //  Boost common_factor_ct.hpp header file  ----------------------------------//
0002 
0003 //  (C) Copyright Daryle Walker and Stephen Cleary 2001-2002.
0004 //  Distributed under the Boost Software License, Version 1.0. (See
0005 //  accompanying file LICENSE_1_0.txt or copy at
0006 //  https://www.boost.org/LICENSE_1_0.txt)
0007 
0008 //  See https://www.boost.org for updates, documentation, and revision history. 
0009 
0010 #ifndef BOOST_INTEGER_COMMON_FACTOR_CT_HPP
0011 #define BOOST_INTEGER_COMMON_FACTOR_CT_HPP
0012 
0013 #include <boost/integer_fwd.hpp>  // self include
0014 #include <boost/config.hpp>  // for BOOST_STATIC_CONSTANT, etc.
0015 
0016 namespace boost
0017 {
0018 namespace integer
0019 {
0020 
0021 //  Implementation details  --------------------------------------------------//
0022 
0023 namespace detail
0024 {
0025     // Build GCD with Euclid's recursive algorithm
0026     template < static_gcd_type Value1, static_gcd_type Value2 >
0027     struct static_gcd_helper_t
0028     {
0029     private:
0030         BOOST_STATIC_CONSTANT( static_gcd_type, new_value1 = Value2 );
0031         BOOST_STATIC_CONSTANT( static_gcd_type, new_value2 = Value1 % Value2 );
0032 
0033         #ifndef BOOST_BORLANDC
0034         #define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast<static_gcd_type>(Value)
0035         #else
0036         typedef static_gcd_helper_t  self_type;
0037         #define BOOST_DETAIL_GCD_HELPER_VAL(Value)  (self_type:: Value )
0038         #endif
0039 
0040         typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1),
0041          BOOST_DETAIL_GCD_HELPER_VAL(new_value2) >  next_step_type;
0042 
0043         #undef BOOST_DETAIL_GCD_HELPER_VAL
0044 
0045     public:
0046         BOOST_STATIC_CONSTANT( static_gcd_type, value = next_step_type::value );
0047     };
0048 
0049     // Non-recursive case
0050     template < static_gcd_type Value1 >
0051     struct static_gcd_helper_t< Value1, 0UL >
0052     {
0053         BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 );
0054     };
0055 
0056     // Build the LCM from the GCD
0057     template < static_gcd_type Value1, static_gcd_type Value2 >
0058     struct static_lcm_helper_t
0059     {
0060         typedef static_gcd_helper_t<Value1, Value2>  gcd_type;
0061 
0062         BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 / gcd_type::value
0063          * Value2 );
0064     };
0065 
0066     // Special case for zero-GCD values
0067     template < >
0068     struct static_lcm_helper_t< 0UL, 0UL >
0069     {
0070         BOOST_STATIC_CONSTANT( static_gcd_type, value = 0UL );
0071     };
0072 
0073 }  // namespace detail
0074 
0075 
0076 //  Compile-time greatest common divisor evaluator class declaration  --------//
0077 
0078 template < static_gcd_type Value1, static_gcd_type Value2 > struct static_gcd
0079 {
0080     BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_gcd_helper_t<Value1, Value2>::value) );
0081 };  // boost::integer::static_gcd
0082 
0083 #if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
0084 template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_gcd< Value1, Value2 >::value;
0085 #endif
0086 
0087 //  Compile-time least common multiple evaluator class declaration  ----------//
0088 
0089 template < static_gcd_type Value1, static_gcd_type Value2 > struct static_lcm
0090 {
0091     BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_lcm_helper_t<Value1, Value2>::value) );
0092 };  // boost::integer::static_lcm
0093 
0094 #if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
0095 template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_lcm< Value1, Value2 >::value;
0096 #endif
0097 
0098 }  // namespace integer
0099 }  // namespace boost
0100 
0101 
0102 #endif  // BOOST_INTEGER_COMMON_FACTOR_CT_HPP