@@ -169,47 +169,7 @@ T binary_textbook(T u, T v)
169169 return u + v;
170170}
171171
172- //
173- // The Mixed Binary Euclid Algorithm
174- // Sidi Mohamed Sedjelmaci
175- // Electronic Notes in Discrete Mathematics 35 (2009) 169–176
176- //
177- template <class T >
178- T mixed_binary_gcd (T u, T v)
179- {
180- using std::swap;
181- if (u < v)
182- swap (u, v);
183-
184- unsigned shifts = 0 ;
185-
186- if (!u)
187- return v;
188- if (!v)
189- return u;
190-
191- while (even (u) && even (v))
192- {
193- u >>= 1u ;
194- v >>= 1u ;
195- ++shifts;
196- }
197172
198- while (v > 1 )
199- {
200- u %= v;
201- v -= u;
202- if (!u)
203- return v << shifts;
204- if (!v)
205- return u << shifts;
206- while (even (u)) u >>= 1u ;
207- while (even (v)) v >>= 1u ;
208- if (u < v)
209- swap (u, v);
210- }
211- return (v == 1 ? v : u) << shifts;
212- }
213173
214174template <class T >
215175void test_type (const char * name)
@@ -220,7 +180,12 @@ void test_type(const char* name)
220180
221181 for (unsigned i = 0 ; i < 1000 ; ++i)
222182 {
223- data.push_back (std::make_pair (get_prime_products<T>(), get_prime_products<T>()));
183+ data.push_back (pair<int_type, int_type>());
184+ do
185+ {
186+ data.back () = std::make_pair (get_prime_products<T>(), get_prime_products<T>());
187+ }
188+ while (data.back ().first == 0 && data.back ().second == 0 );
224189 }
225190 std::string row_name (" gcd<" );
226191 row_name += name;
@@ -342,7 +307,8 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
342307 using default_ops::eval_lsb;
343308 using default_ops::eval_is_zero;
344309 using default_ops::eval_get_sign;
345-
310+ using boost::math::detail::mixed_binary_gcd;
311+
346312 if (a.size () == 1 )
347313 {
348314 eval_gcd (result, b, *a.limbs ());
0 commit comments