$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r50449 - sandbox/chrono/boost
From: bdawes_at_[hidden]
Date: 2009-01-03 12:52:29
Author: bemandawes
Date: 2009-01-03 12:52:28 EST (Sat, 03 Jan 2009)
New Revision: 50449
URL: http://svn.boost.org/trac/boost/changeset/50449
Log:
ratio.hpp improvements from Howard. See LWG issue 948 for rationale.
Text files modified: 
   sandbox/chrono/boost/ratio.hpp |    62 +++++++++++++++++++++++++++++++++------ 
   1 files changed, 52 insertions(+), 10 deletions(-)
Modified: sandbox/chrono/boost/ratio.hpp
==============================================================================
--- sandbox/chrono/boost/ratio.hpp	(original)
+++ sandbox/chrono/boost/ratio.hpp	2009-01-03 12:52:28 EST (Sat, 03 Jan 2009)
@@ -288,31 +288,73 @@
 template <class R1, class R2>
 struct ratio_add
 {
-    typedef ratio<detail::ll_add<detail::ll_mul<R1::num, R2::den>::value,
-                  detail::ll_mul<R1::den, R2::num>::value>::value,
-                  detail::ll_mul<R1::den, R2::den>::value> type;
+private:
+   static const boost::intmax_t gcd_n1_n2 = detail::static_gcd<R1::num, R2::num>::value;
+   static const boost::intmax_t gcd_d1_d2 = detail::static_gcd<R1::den, R2::den>::value;
+public:
+   typedef typename ratio_multiply
+       <
+           ratio<gcd_n1_n2, R1::den / gcd_d1_d2>,
+           ratio
+           <
+               detail::ll_add
+               <
+                   detail::ll_mul<R1::num / gcd_n1_n2, R2::den / gcd_d1_d2>::value,
+                   detail::ll_mul<R2::num / gcd_n1_n2, R1::den / gcd_d1_d2>::value
+               >::value,
+               R2::den
+           >
+       >::type type;
 };
 
 template <class R1, class R2>
 struct ratio_subtract
 {
-    typedef ratio<detail::ll_sub<detail::ll_mul<R1::num, R2::den>::value,
-                  detail::ll_mul<R1::den, R2::num>::value>::value,
-                  detail::ll_mul<R1::den, R2::den>::value> type;
+private:
+   static const boost::intmax_t gcd_n1_n2 = detail::static_gcd<R1::num, R2::num>::value;
+   static const boost::intmax_t gcd_d1_d2 = detail::static_gcd<R1::den, R2::den>::value;
+public:
+   typedef typename ratio_multiply
+       <
+           ratio<gcd_n1_n2, R1::den / gcd_d1_d2>,
+           ratio
+           <
+               detail::ll_sub
+               <
+                   detail::ll_mul<R1::num / gcd_n1_n2, R2::den / gcd_d1_d2>::value,
+                   detail::ll_mul<R2::num / gcd_n1_n2, R1::den / gcd_d1_d2>::value
+               >::value,
+               R2::den
+           >
+       >::type type;
 };
 
 template <class R1, class R2>
 struct ratio_multiply
 {
-    typedef ratio<detail::ll_mul<R1::num, R2::num>::value,
-                  detail::ll_mul<R1::den, R2::den>::value> type;
+private:
+   static const boost::intmax_t gcd_n1_d2 = detail::static_gcd<R1::num, R2::den>::value;
+   static const boost::intmax_t gcd_d1_n2 = detail::static_gcd<R1::den, R2::num>::value;
+public:
+   typedef ratio
+       <
+           detail::ll_mul<R1::num / gcd_n1_d2, R2::num / gcd_d1_n2>::value,
+           detail::ll_mul<R2::den / gcd_n1_d2, R1::den / gcd_d1_n2>::value
+       > type;
 };
 
 template <class R1, class R2>
 struct ratio_divide
 {
-    typedef ratio<detail::ll_mul<R1::num, R2::den>::value,
-                  detail::ll_mul<R1::den, R2::num>::value> type;
+private:
+   static const boost::intmax_t gcd_n1_n2 = detail::static_gcd<R1::num, R2::num>::value;
+   static const boost::intmax_t gcd_d1_d2 = detail::static_gcd<R1::den, R2::den>::value;
+public:
+   typedef ratio
+       <
+           detail::ll_mul<R1::num / gcd_n1_n2, R2::den / gcd_d1_d2>::value,
+           detail::ll_mul<R2::num / gcd_n1_n2, R1::den / gcd_d1_d2>::value
+       > type;
 };
 
 // ratio_equal