2008-11-26 13:17:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef BOOST_MATH_COMMON_FACTOR_RT_HPP
|
|
|
|
#define BOOST_MATH_COMMON_FACTOR_RT_HPP
|
|
|
|
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace math {
|
|
|
|
|
|
|
|
// TODO: use binary GCD for unsigned integers ....
|
|
|
|
template < typename IntegerType >
|
2008-11-29 15:30:50 +00:00
|
|
|
IntegerType gcd( IntegerType a, IntegerType b )
|
2008-11-26 13:17:39 +00:00
|
|
|
{
|
2009-01-08 04:25:35 +00:00
|
|
|
const IntegerType zero = (IntegerType)0;
|
2008-11-26 13:17:39 +00:00
|
|
|
while ( true )
|
|
|
|
{
|
|
|
|
if ( a == zero )
|
|
|
|
return b;
|
|
|
|
b %= a;
|
|
|
|
|
|
|
|
if ( b == zero )
|
|
|
|
return a;
|
|
|
|
a %= b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template < typename IntegerType >
|
2008-11-29 15:30:50 +00:00
|
|
|
IntegerType lcm( IntegerType a, IntegerType b )
|
2008-11-26 13:17:39 +00:00
|
|
|
{
|
2009-01-08 04:25:35 +00:00
|
|
|
const IntegerType t = gcd (a,b);
|
2008-11-26 13:17:39 +00:00
|
|
|
if (!t)return t;
|
|
|
|
return a / t * b;
|
|
|
|
}
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
2009-01-12 22:26:11 +00:00
|
|
|
#endif
|