1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/math/common_factor_ct.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,188 @@
1.4 +// Boost common_factor_ct.hpp header file ----------------------------------//
1.5 +
1.6 +// (C) Copyright Daryle Walker and Stephen Cleary 2001-2002.
1.7 +// Distributed under the Boost Software License, Version 1.0. (See
1.8 +// accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +
1.11 +// See http://www.boost.org for updates, documentation, and revision history.
1.12 +
1.13 +#ifndef BOOST_MATH_COMMON_FACTOR_CT_HPP
1.14 +#define BOOST_MATH_COMMON_FACTOR_CT_HPP
1.15 +
1.16 +#include <boost/math_fwd.hpp> // self include
1.17 +
1.18 +#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
1.19 +
1.20 +
1.21 +namespace boost
1.22 +{
1.23 +namespace math
1.24 +{
1.25 +
1.26 +
1.27 +// Implementation details --------------------------------------------------//
1.28 +
1.29 +namespace detail
1.30 +{
1.31 +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.32 + // Build GCD with Euclid's recursive algorithm
1.33 + template < unsigned long Value1, unsigned long Value2 >
1.34 + struct static_gcd_helper_t
1.35 + {
1.36 + private:
1.37 + BOOST_STATIC_CONSTANT( unsigned long, new_value1 = Value2 );
1.38 + BOOST_STATIC_CONSTANT( unsigned long, new_value2 = Value1 % Value2 );
1.39 +
1.40 + #ifndef __BORLANDC__
1.41 + #define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast<unsigned long>(Value)
1.42 + #else
1.43 + typedef static_gcd_helper_t self_type;
1.44 + #define BOOST_DETAIL_GCD_HELPER_VAL(Value) (self_type:: Value )
1.45 + #endif
1.46 +
1.47 + typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1),
1.48 + BOOST_DETAIL_GCD_HELPER_VAL(new_value2) > next_step_type;
1.49 +
1.50 + #undef BOOST_DETAIL_GCD_HELPER_VAL
1.51 +
1.52 + public:
1.53 + BOOST_STATIC_CONSTANT( unsigned long, value = next_step_type::value );
1.54 + };
1.55 +
1.56 + // Non-recursive case
1.57 + template < unsigned long Value1 >
1.58 + struct static_gcd_helper_t< Value1, 0UL >
1.59 + {
1.60 + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 );
1.61 + };
1.62 +#else
1.63 + // Use inner class template workaround from Peter Dimov
1.64 + template < unsigned long Value1 >
1.65 + struct static_gcd_helper2_t
1.66 + {
1.67 + template < unsigned long Value2 >
1.68 + struct helper
1.69 + {
1.70 + BOOST_STATIC_CONSTANT( unsigned long, value
1.71 + = static_gcd_helper2_t<Value2>::BOOST_NESTED_TEMPLATE
1.72 + helper<Value1 % Value2>::value );
1.73 + };
1.74 +
1.75 + template < >
1.76 + struct helper< 0UL >
1.77 + {
1.78 + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 );
1.79 + };
1.80 + };
1.81 +
1.82 + // Special case
1.83 + template < >
1.84 + struct static_gcd_helper2_t< 0UL >
1.85 + {
1.86 + template < unsigned long Value2 >
1.87 + struct helper
1.88 + {
1.89 + BOOST_STATIC_CONSTANT( unsigned long, value = Value2 );
1.90 + };
1.91 + };
1.92 +
1.93 + // Build the GCD from the above template(s)
1.94 + template < unsigned long Value1, unsigned long Value2 >
1.95 + struct static_gcd_helper_t
1.96 + {
1.97 + BOOST_STATIC_CONSTANT( unsigned long, value
1.98 + = static_gcd_helper2_t<Value1>::BOOST_NESTED_TEMPLATE
1.99 + helper<Value2>::value );
1.100 + };
1.101 +#endif
1.102 +
1.103 +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.104 + // Build the LCM from the GCD
1.105 + template < unsigned long Value1, unsigned long Value2 >
1.106 + struct static_lcm_helper_t
1.107 + {
1.108 + typedef static_gcd_helper_t<Value1, Value2> gcd_type;
1.109 +
1.110 + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 / gcd_type::value
1.111 + * Value2 );
1.112 + };
1.113 +
1.114 + // Special case for zero-GCD values
1.115 + template < >
1.116 + struct static_lcm_helper_t< 0UL, 0UL >
1.117 + {
1.118 + BOOST_STATIC_CONSTANT( unsigned long, value = 0UL );
1.119 + };
1.120 +#else
1.121 + // Adapt GCD's inner class template workaround for LCM
1.122 + template < unsigned long Value1 >
1.123 + struct static_lcm_helper2_t
1.124 + {
1.125 + template < unsigned long Value2 >
1.126 + struct helper
1.127 + {
1.128 + typedef static_gcd_helper_t<Value1, Value2> gcd_type;
1.129 +
1.130 + BOOST_STATIC_CONSTANT( unsigned long, value = Value1
1.131 + / gcd_type::value * Value2 );
1.132 + };
1.133 +
1.134 + template < >
1.135 + struct helper< 0UL >
1.136 + {
1.137 + BOOST_STATIC_CONSTANT( unsigned long, value = 0UL );
1.138 + };
1.139 + };
1.140 +
1.141 + // Special case
1.142 + template < >
1.143 + struct static_lcm_helper2_t< 0UL >
1.144 + {
1.145 + template < unsigned long Value2 >
1.146 + struct helper
1.147 + {
1.148 + BOOST_STATIC_CONSTANT( unsigned long, value = 0UL );
1.149 + };
1.150 + };
1.151 +
1.152 + // Build the LCM from the above template(s)
1.153 + template < unsigned long Value1, unsigned long Value2 >
1.154 + struct static_lcm_helper_t
1.155 + {
1.156 + BOOST_STATIC_CONSTANT( unsigned long, value
1.157 + = static_lcm_helper2_t<Value1>::BOOST_NESTED_TEMPLATE
1.158 + helper<Value2>::value );
1.159 + };
1.160 +#endif
1.161 +
1.162 +} // namespace detail
1.163 +
1.164 +
1.165 +// Compile-time greatest common divisor evaluator class declaration --------//
1.166 +
1.167 +template < unsigned long Value1, unsigned long Value2 >
1.168 +struct static_gcd
1.169 +{
1.170 + BOOST_STATIC_CONSTANT( unsigned long, value
1.171 + = (detail::static_gcd_helper_t<Value1, Value2>::value) );
1.172 +
1.173 +}; // boost::math::static_gcd
1.174 +
1.175 +
1.176 +// Compile-time least common multiple evaluator class declaration ----------//
1.177 +
1.178 +template < unsigned long Value1, unsigned long Value2 >
1.179 +struct static_lcm
1.180 +{
1.181 + BOOST_STATIC_CONSTANT( unsigned long, value
1.182 + = (detail::static_lcm_helper_t<Value1, Value2>::value) );
1.183 +
1.184 +}; // boost::math::static_lcm
1.185 +
1.186 +
1.187 +} // namespace math
1.188 +} // namespace boost
1.189 +
1.190 +
1.191 +#endif // BOOST_MATH_COMMON_FACTOR_CT_HPP