Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67574 - in sandbox/chrono/boost/ratio: . detail
From: vicente.botet_at_[hidden]
Date: 2011-01-02 11:07:15


Author: viboes
Date: 2011-01-02 11:07:14 EST (Sun, 02 Jan 2011)
New Revision: 67574
URL: http://svn.boost.org/trac/boost/changeset/67574

Log:
Ratio: update test with BOOST_RATIO_INTMAX_C
Text files modified:
   sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp | 2
   sandbox/chrono/boost/ratio/ratio.hpp | 49 ++++++++++++++++++++++++++++++++-------
   sandbox/chrono/boost/ratio/ratio_fwd.hpp | 36 ++++++++++++++--------------
   3 files changed, 59 insertions(+), 28 deletions(-)

Modified: sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp
==============================================================================
--- sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp (original)
+++ sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp 2011-01-02 11:07:14 EST (Sun, 02 Jan 2011)
@@ -167,7 +167,7 @@
   class br_mul
   {
       static const boost::intmax_t nan =
- (BOOST_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
+ (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
       static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
       static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
 

Modified: sandbox/chrono/boost/ratio/ratio.hpp
==============================================================================
--- sandbox/chrono/boost/ratio/ratio.hpp (original)
+++ sandbox/chrono/boost/ratio/ratio.hpp 2011-01-02 11:07:14 EST (Sun, 02 Jan 2011)
@@ -33,9 +33,6 @@
 #define BOOST_RATIO_RATIO_HPP
 
 #include <boost/config.hpp>
-//~ #include <boost/static_integer/static_abs.hpp>
-//~ #include <boost/static_integer/static_sign.hpp>
-//~ #include <boost/static_integer/static_gcd.hpp>
 #include <boost/mpl/abs.hpp>
 #include <boost/mpl/sign.hpp>
 #include <boost/mpl/gcd.hpp>
@@ -49,6 +46,10 @@
 #include <boost/integer_traits.hpp>
 #include <boost/ratio/ratio_fwd.hpp>
 #include <boost/ratio/detail/overflow_helpers.hpp>
+#ifdef BOOST_RATIO_EXTENSIONS
+#include <boost/rational.hpp>
+#include <boost/ratio/mpl/rational_c_tag.hpp>
+#endif
 
 //
 // We simply cannot include this header on gcc without getting copious warnings of the kind:
@@ -71,7 +72,7 @@
 // 20.6.1 Class template ratio [ratio.ratio] //
 // //
 //----------------------------------------------------------------------------//
-
+
 template <boost::intmax_t N, boost::intmax_t D>
 class ratio
 {
@@ -88,9 +89,13 @@
     BOOST_STATIC_CONSTEXPR boost::intmax_t den = ABS_D / GCD;
 
 #ifdef BOOST_RATIO_EXTENSIONS
+ typedef mpl::rational_c_tag tag;
+ typedef boost::rational<boost::intmax_t> value_type;
+ typedef boost::intmax_t num_type;
+ typedef boost::intmax_t den_type;
     ratio()
     {}
- template <intmax_t _N2, boost::intmax_t _D2>
+ template <boost::intmax_t _N2, boost::intmax_t _D2>
     ratio(const ratio<_N2, _D2>&,
         typename enable_if_c
             <
@@ -99,7 +104,7 @@
>::type* = 0)
     {}
 
- template <intmax_t _N2, boost::intmax_t _D2>
+ template <boost::intmax_t _N2, boost::intmax_t _D2>
         typename enable_if_c
         <
             (ratio<_N2, _D2>::num == num &&
@@ -107,6 +112,9 @@
             ratio&
>::type
     operator=(const ratio<_N2, _D2>&) {return *this;}
+
+ static value_type value() {return value_type(num,den);}
+ value_type operator()() const {return value();}
 #endif
     typedef ratio<num, den> type;
 };
@@ -183,12 +191,35 @@
 {};
 
 template <class R1, class R2>
-struct ratio_gcd
+struct ratio_gcd :
+ ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value,
+ mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value>::type
 {
- typedef ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value,
- mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value> type;
 };
     
+#ifdef BOOST_RATIO_EXTENSIONS
+template <class R>
+struct ratio_negate
+ : ratio<-R::num, R::den>::type
+{
+};
+template <class R>
+struct ratio_abs
+ : ratio<mpl::abs_c<boost::intmax_t, R::num>::value, R::den>::type
+{
+};
+template <class R>
+struct ratio_sign
+ : mpl::sign_c<boost::intmax_t, R::num>
+{
+};
+template <class R1, class R2>
+struct ratio_lcm :
+ ratio<mpl::lcm_c<boost::intmax_t, R1::num, R2::num>::value,
+ mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value>::type
+{
+};
+#endif
 } // namespace boost
 
 

Modified: sandbox/chrono/boost/ratio/ratio_fwd.hpp
==============================================================================
--- sandbox/chrono/boost/ratio/ratio_fwd.hpp (original)
+++ sandbox/chrono/boost/ratio/ratio_fwd.hpp 2011-01-02 11:07:14 EST (Sun, 02 Jan 2011)
@@ -34,9 +34,9 @@
 
 #include <boost/cstdint.hpp>
 #ifdef INTMAX_C
-#define BOOST_INTMAX_C(a) INTMAX_C(a)
+#define BOOST_RATIO_INTMAX_C(a) INTMAX_C(a)
 #else
-#define BOOST_INTMAX_C(a) a##LL
+#define BOOST_RATIO_INTMAX_C(a) a##LL
 #endif
 
 namespace boost
@@ -66,22 +66,22 @@
 template <class R1, class R2> struct ratio_greater_equal;
 
 // convenience SI typedefs
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000000000)> atto;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000000)> femto;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000)> pico;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000)> nano;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000)> micro;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000)> milli;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(100)> centi;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(10)> deci;
-typedef ratio< BOOST_INTMAX_C(10), BOOST_INTMAX_C(1)> deca;
-typedef ratio< BOOST_INTMAX_C(100), BOOST_INTMAX_C(1)> hecto;
-typedef ratio< BOOST_INTMAX_C(1000), BOOST_INTMAX_C(1)> kilo;
-typedef ratio< BOOST_INTMAX_C(1000000), BOOST_INTMAX_C(1)> mega;
-typedef ratio< BOOST_INTMAX_C(1000000000), BOOST_INTMAX_C(1)> giga;
-typedef ratio< BOOST_INTMAX_C(1000000000000), BOOST_INTMAX_C(1)> tera;
-typedef ratio< BOOST_INTMAX_C(1000000000000000), BOOST_INTMAX_C(1)> peta;
-typedef ratio<BOOST_INTMAX_C(1000000000000000000), BOOST_INTMAX_C(1)> exa;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000000000)> atto;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000000)> femto;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000)> pico;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000)> nano;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000)> micro;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000)> milli;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(100)> centi;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(10)> deci;
+typedef ratio< BOOST_RATIO_INTMAX_C(10), BOOST_RATIO_INTMAX_C(1)> deca;
+typedef ratio< BOOST_RATIO_INTMAX_C(100), BOOST_RATIO_INTMAX_C(1)> hecto;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000), BOOST_RATIO_INTMAX_C(1)> kilo;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000), BOOST_RATIO_INTMAX_C(1)> mega;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000000), BOOST_RATIO_INTMAX_C(1)> giga;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000000000), BOOST_RATIO_INTMAX_C(1)> tera;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000000000000), BOOST_RATIO_INTMAX_C(1)> peta;
+typedef ratio<BOOST_RATIO_INTMAX_C(1000000000000000000), BOOST_RATIO_INTMAX_C(1)> exa;
     
 } // namespace boost
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk