Chris@16
|
1 // Boost common_factor_ct.hpp header file ----------------------------------//
|
Chris@16
|
2
|
Chris@16
|
3 // (C) Copyright Daryle Walker and Stephen Cleary 2001-2002.
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
5 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_MATH_COMMON_FACTOR_CT_HPP
|
Chris@16
|
11 #define BOOST_MATH_COMMON_FACTOR_CT_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/math_fwd.hpp> // self include
|
Chris@16
|
14 #include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
|
Chris@16
|
15 #include <boost/mpl/integral_c.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost
|
Chris@16
|
18 {
|
Chris@16
|
19 namespace math
|
Chris@16
|
20 {
|
Chris@16
|
21
|
Chris@16
|
22 // Implementation details --------------------------------------------------//
|
Chris@16
|
23
|
Chris@16
|
24 namespace detail
|
Chris@16
|
25 {
|
Chris@16
|
26 // Build GCD with Euclid's recursive algorithm
|
Chris@16
|
27 template < static_gcd_type Value1, static_gcd_type Value2 >
|
Chris@16
|
28 struct static_gcd_helper_t
|
Chris@16
|
29 {
|
Chris@16
|
30 private:
|
Chris@16
|
31 BOOST_STATIC_CONSTANT( static_gcd_type, new_value1 = Value2 );
|
Chris@16
|
32 BOOST_STATIC_CONSTANT( static_gcd_type, new_value2 = Value1 % Value2 );
|
Chris@16
|
33
|
Chris@16
|
34 #ifndef __BORLANDC__
|
Chris@16
|
35 #define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast<static_gcd_type>(Value)
|
Chris@16
|
36 #else
|
Chris@16
|
37 typedef static_gcd_helper_t self_type;
|
Chris@16
|
38 #define BOOST_DETAIL_GCD_HELPER_VAL(Value) (self_type:: Value )
|
Chris@16
|
39 #endif
|
Chris@16
|
40
|
Chris@16
|
41 typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1),
|
Chris@16
|
42 BOOST_DETAIL_GCD_HELPER_VAL(new_value2) > next_step_type;
|
Chris@16
|
43
|
Chris@16
|
44 #undef BOOST_DETAIL_GCD_HELPER_VAL
|
Chris@16
|
45
|
Chris@16
|
46 public:
|
Chris@16
|
47 BOOST_STATIC_CONSTANT( static_gcd_type, value = next_step_type::value );
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 // Non-recursive case
|
Chris@16
|
51 template < static_gcd_type Value1 >
|
Chris@16
|
52 struct static_gcd_helper_t< Value1, 0UL >
|
Chris@16
|
53 {
|
Chris@16
|
54 BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 );
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 // Build the LCM from the GCD
|
Chris@16
|
58 template < static_gcd_type Value1, static_gcd_type Value2 >
|
Chris@16
|
59 struct static_lcm_helper_t
|
Chris@16
|
60 {
|
Chris@16
|
61 typedef static_gcd_helper_t<Value1, Value2> gcd_type;
|
Chris@16
|
62
|
Chris@16
|
63 BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 / gcd_type::value
|
Chris@16
|
64 * Value2 );
|
Chris@16
|
65 };
|
Chris@16
|
66
|
Chris@16
|
67 // Special case for zero-GCD values
|
Chris@16
|
68 template < >
|
Chris@16
|
69 struct static_lcm_helper_t< 0UL, 0UL >
|
Chris@16
|
70 {
|
Chris@16
|
71 BOOST_STATIC_CONSTANT( static_gcd_type, value = 0UL );
|
Chris@16
|
72 };
|
Chris@16
|
73
|
Chris@16
|
74 } // namespace detail
|
Chris@16
|
75
|
Chris@16
|
76
|
Chris@16
|
77 // Compile-time greatest common divisor evaluator class declaration --------//
|
Chris@16
|
78
|
Chris@16
|
79 template < static_gcd_type Value1, static_gcd_type Value2 >
|
Chris@16
|
80 struct static_gcd : public mpl::integral_c<static_gcd_type, (detail::static_gcd_helper_t<Value1, Value2>::value) >
|
Chris@16
|
81 {
|
Chris@16
|
82 }; // boost::math::static_gcd
|
Chris@16
|
83
|
Chris@16
|
84
|
Chris@16
|
85 // Compile-time least common multiple evaluator class declaration ----------//
|
Chris@16
|
86
|
Chris@16
|
87 template < static_gcd_type Value1, static_gcd_type Value2 >
|
Chris@16
|
88 struct static_lcm : public mpl::integral_c<static_gcd_type, (detail::static_lcm_helper_t<Value1, Value2>::value) >
|
Chris@16
|
89 {
|
Chris@16
|
90 }; // boost::math::static_lcm
|
Chris@16
|
91
|
Chris@16
|
92
|
Chris@16
|
93 } // namespace math
|
Chris@16
|
94 } // namespace boost
|
Chris@16
|
95
|
Chris@16
|
96
|
Chris@16
|
97 #endif // BOOST_MATH_COMMON_FACTOR_CT_HPP
|