mirror of
https://github.com/boostorg/ratio.git
synced 2025-05-09 23:24:01 +00:00
Implement ratio_gcd (which is, yes, used by Chrono)
This commit is contained in:
parent
00a69ca14d
commit
4d35c901a9
@ -33,20 +33,17 @@ time2_demo contained this comment:
|
|||||||
#define BOOST_RATIO_RATIO_HPP
|
#define BOOST_RATIO_RATIO_HPP
|
||||||
|
|
||||||
#include <boost/ratio/ratio_fwd.hpp>
|
#include <boost/ratio/ratio_fwd.hpp>
|
||||||
|
#include <boost/ratio/detail/gcd_lcm.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
template <class R1, class R2> struct ratio_gcd: ratio<
|
||||||
template <class R1, class R2>
|
ratio_detail::gcd<R1::num, R2::num>::value,
|
||||||
struct ratio_gcd :
|
ratio_detail::lcm<R1::den, R2::den>::value>::type
|
||||||
ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value,
|
|
||||||
mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value>::type
|
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_RATIO_RATIO_HPP
|
#endif // BOOST_RATIO_RATIO_HPP
|
||||||
|
@ -34,6 +34,7 @@ compile ratio_arithmetic/ratio_add_pass.cpp ;
|
|||||||
compile ratio_arithmetic/ratio_subtract_pass.cpp ;
|
compile ratio_arithmetic/ratio_subtract_pass.cpp ;
|
||||||
compile ratio_arithmetic/ratio_multiply_pass.cpp ;
|
compile ratio_arithmetic/ratio_multiply_pass.cpp ;
|
||||||
compile ratio_arithmetic/ratio_divide_pass.cpp ;
|
compile ratio_arithmetic/ratio_divide_pass.cpp ;
|
||||||
|
compile ratio_arithmetic/ratio_gcd_pass.cpp ;
|
||||||
compile-fail ratio_arithmetic/ratio_add_fail.cpp ;
|
compile-fail ratio_arithmetic/ratio_add_fail.cpp ;
|
||||||
compile-fail ratio_arithmetic/ratio_add_2_fail.cpp ;
|
compile-fail ratio_arithmetic/ratio_add_2_fail.cpp ;
|
||||||
#compile-fail ratio_arithmetic/ratio_add_3_fail.cpp ;
|
#compile-fail ratio_arithmetic/ratio_add_3_fail.cpp ;
|
||||||
|
65
test/ratio_arithmetic/ratio_gcd_pass.cpp
Normal file
65
test/ratio_arithmetic/ratio_gcd_pass.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Copyright 2023 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/ratio/ratio.hpp>
|
||||||
|
|
||||||
|
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||||
|
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typedef boost::ratio<1, 1> R1;
|
||||||
|
typedef boost::ratio<1, 1> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<1, 2> R1;
|
||||||
|
typedef boost::ratio<1, 1> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<-1, 2> R1;
|
||||||
|
typedef boost::ratio<1, 1> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<1, -2> R1;
|
||||||
|
typedef boost::ratio<1, 1> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<1, 2> R1;
|
||||||
|
typedef boost::ratio<-1, 1> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<1, 2> R1;
|
||||||
|
typedef boost::ratio<1, -1> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<1, 2> R1;
|
||||||
|
typedef boost::ratio<1, 3> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 6);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<7, 13> R1;
|
||||||
|
typedef boost::ratio<11, 13> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 1 && R::den == 13);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef boost::ratio<21, 55> R1;
|
||||||
|
typedef boost::ratio<14, 25> R2;
|
||||||
|
typedef boost::ratio_gcd<R1, R2> R;
|
||||||
|
STATIC_ASSERT(R::num == 7 && R::den == 275);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user