Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86601 - in trunk: boost/ratio libs/ratio/doc libs/ratio/test libs/ratio/test/ratio_arithmetic
From: vicente.botet_at_[hidden]
Date: 2013-11-09 12:00:41


Author: viboes
Date: 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013)
New Revision: 86601
URL: http://svn.boost.org/trac/boost/changeset/86601

Log:
Ratio: Added some missing templates in ratio_fwd.hpp, some tests and doc of the new features ratio_power and binary prefixes.

Added:
   trunk/libs/ratio/test/ratio_arithmetic/ratio_abs_pass.cpp (contents, props changed)
   trunk/libs/ratio/test/ratio_arithmetic/ratio_negate_pass.cpp (contents, props changed)
   trunk/libs/ratio/test/ratio_arithmetic/ratio_sign_pass.cpp (contents, props changed)
Text files modified:
   trunk/boost/ratio/ratio.hpp | 10 +++
   trunk/boost/ratio/ratio_fwd.hpp | 9 +++
   trunk/libs/ratio/doc/ratio.qbk | 101 +++++++++++++++++++++++++++++++++++++++
   trunk/libs/ratio/test/Jamfile.v2 | 11 ++-
   trunk/libs/ratio/test/ratio_arithmetic/ratio_abs_pass.cpp | 51 ++++++++++++++++++++
   trunk/libs/ratio/test/ratio_arithmetic/ratio_negate_pass.cpp | 51 ++++++++++++++++++++
   trunk/libs/ratio/test/ratio_arithmetic/ratio_sign_pass.cpp | 51 ++++++++++++++++++++
   7 files changed, 276 insertions(+), 8 deletions(-)

Modified: trunk/boost/ratio/ratio.hpp
==============================================================================
--- trunk/boost/ratio/ratio.hpp Sat Nov 9 10:59:41 2013 (r86600)
+++ trunk/boost/ratio/ratio.hpp 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -128,7 +128,7 @@
 
 //----------------------------------------------------------------------------//
 // //
-// 20.6.2 Arithmetic on ratio types [ratio.arithmetic] //
+// 20.6.2 Arithmetic on ratio types [ratio.arithmetic] //
 // //
 //----------------------------------------------------------------------------//
 
@@ -158,7 +158,7 @@
 
 //----------------------------------------------------------------------------//
 // //
-// 20.6.3 Comparasion of ratio types [ratio.comparison] //
+// 20.6.3 Comparision of ratio types [ratio.comparison] //
 // //
 //----------------------------------------------------------------------------//
 
@@ -204,6 +204,12 @@
 {
 };
 
+ //----------------------------------------------------------------------------//
+ // //
+ // More arithmetic on ratio types [ratio.arithmetic] //
+ // //
+ //----------------------------------------------------------------------------//
+
 #ifdef BOOST_RATIO_EXTENSIONS
 template <class R>
 struct ratio_negate

Modified: trunk/boost/ratio/ratio_fwd.hpp
==============================================================================
--- trunk/boost/ratio/ratio_fwd.hpp Sat Nov 9 10:59:41 2013 (r86600)
+++ trunk/boost/ratio/ratio_fwd.hpp 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -51,6 +51,14 @@
 template <class R1, class R2> struct ratio_subtract;
 template <class R1, class R2> struct ratio_multiply;
 template <class R1, class R2> struct ratio_divide;
+#ifdef BOOST_RATIO_EXTENSIONS
+template <class R1, class R2> struct ratio_gcd;
+template <class R1, class R2> struct ratio_lcm;
+template <class R> struct ratio_negate;
+template <class R> struct ratio_abs;
+template <class R> struct ratio_sign;
+template <class R, int P> struct ratio_power;
+#endif
 
 // ratio comparison
 template <class R1, class R2> struct ratio_equal;
@@ -82,6 +90,7 @@
 
 #define BOOST_RATIO_1024 BOOST_RATIO_INTMAX_C(1024)
 
+// convenience IEC typedefs
 typedef ratio< BOOST_RATIO_1024> kibi;
 typedef ratio< BOOST_RATIO_1024*BOOST_RATIO_1024> mebi;
 typedef ratio< BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024> gibi;

Modified: trunk/libs/ratio/doc/ratio.qbk
==============================================================================
--- trunk/libs/ratio/doc/ratio.qbk Sat Nov 9 10:59:41 2013 (r86600)
+++ trunk/libs/ratio/doc/ratio.qbk 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -9,7 +9,7 @@
 
 [library Boost.Ratio
     [quickbook 1.5]
- [version 2.0.0]
+ [version 2.1.0]
     [authors [Hinnant, Howard]]
     [authors [Dawes, Beman]]
     [authors [Botet Escriba, Vicente J.]]
@@ -57,6 +57,7 @@
 [def __ratio_subtract [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_subtract`]]
 [def __ratio_multiply [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_multiply`]]
 [def __ratio_divide [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_divide`]]
+[def __ratio_power [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_power`]]
 [def __ratio_negate [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_negate`]]
 [def __ratio_abs [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_abs`]]
 [def __ratio_sign [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_sign`]]
@@ -91,6 +92,13 @@
 [def __peta [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `peta`]]
 [def __exa [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `exa`]]
 
+[def __kibi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `kibi`]]
+[def __mebi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `mebi`]]
+[def __gibi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `gibi`]]
+[def __tebi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `tebi`]]
+[def __pebi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `pebi`]]
+[def __exbi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `exbi`]]
+
 [template mu[]'''&#x3BC;'''] [/ µ Greek small letter mu]
 
 [def __Rational_Constant [link ratio.reference.mpl.rational_constant Rational Constant]]
@@ -744,11 +752,14 @@
         template <class R1, class R2> struct __ratio_subtract;
         template <class R1, class R2> struct __ratio_multiply;
         template <class R1, class R2> struct __ratio_divide;
+ #ifdef BOOST_RATIO_EXTENSIONS
+ template <class R,int P> struct __ratio_power;
         template <class R> struct __ratio_negate;
         template <class R> struct __ratio_sign;
         template <class R> struct __ratio_abs;
         template <class R1, class R2> struct __ratio_gcd;
         template <class R1, class R2> struct __ratio_lcm;
+ #endif
 
         // ratio comparison
         template <class R1, class R2> struct __ratio_equal;
@@ -775,6 +786,16 @@
         typedef ratio< 1000000000000LL, 1LL> __tera;
         typedef ratio< 1000000000000000LL, 1LL> __peta;
         typedef ratio<1000000000000000000LL, 1LL> __exa;
+
+ #ifdef BOOST_RATIO_EXTENSIONS
+ // convenience IEC typedefs
+ typedef ratio< 1024LL> __kibi;
+ typedef ratio< 1024LL*1024LL> __mebi;
+ typedef ratio< 1024LL*1024LL*1024LL> __gibi;
+ typedef ratio< 1024LL*1024LL*1024LL*1024LL> __tebi;
+ typedef ratio< 1024LL*1024LL*1024LL*1024LL*1024LL> __pebi;
+ typedef ratio<1024LL*1024LL*1024LL*1024LL*1024LL*1024LL> __exbi;
+ #endif
     }
 
 [endsect]
@@ -921,8 +942,20 @@
 
 The nested typedef `type` is a synonym for `__ratio<R1::num * R2::den, R2::num * R1::den>::type`.
 
+[heading `ratio_power<>`]
+
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
+ template <class R, int P> struct ratio_power {
+ typedef [/see below] type;
+ };
+
+The nested typedef `type` is a synonym for `R* *R` P times.
+
 [heading `ratio_negate<>`]
 
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
 This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
 
 
@@ -934,6 +967,8 @@
 
 [heading `ratio_abs<>`]
 
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
 This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
 
         template <class R> struct ratio_abs {
@@ -944,6 +979,8 @@
 
 [heading `ratio_sign<>`]
 
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
 This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
 
         template <class R> struct ratio_sign {
@@ -954,6 +991,8 @@
 
 [heading `ratio_gcd<>`]
 
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
 This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
 
         template <class R1, class R2> struct ratio_gcd {
@@ -964,6 +1003,8 @@
 
 [heading `ratio_lcm<>`]
 
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
 This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
 
         template <class R1, class R2> struct ratio_lcm {
@@ -1038,6 +1079,23 @@
 
 [endsect]
 
+[section:ratio_iec_typedefs IEC typedefs]
+
+Included only if __BOOST_RATIO_EXTENSIONS is defined.
+
+The [@http://http://en.wikipedia.org/wiki/Binary_prefix#Specific_units_of_IEC_60027-2_A.2_and_ISO.2FIEC_80000 Specific units of IEC 60027-2 A.2 and ISO/IEC 80000] specifies height IEC prefixes. __Boost_Ratio defines all except `zebi` and `yobi`
+
+ // convenience ETC typedefs
+ typedef ratio< 1024LL> kibi;
+ typedef ratio< 1024LL*1024LL> mebi;
+ typedef ratio< 1024LL*1024LL*1024LL> gibi;
+ typedef ratio< 1024LL*1024LL*1024LL*1024LL> tebi;
+ typedef ratio< 1024LL*1024LL*1024LL*1024LL*1024LL> pebi;
+ typedef ratio<1024LL*1024LL*1024LL*1024LL*1024LL*1024LL> exbi;
+
+[endsect]
+
+
 
 [section:limitations Limitations]
 
@@ -1151,6 +1209,37 @@
         template <> struct ratio_string<exa, char16_t>;
         template <> struct ratio_string<exa, char32_t>;
         template <> struct ratio_string<exa, wchar_t>;
+
+ template <> struct ratio_string<kibi, char>;
+ template <> struct ratio_string<kibi, char16_t>;
+ template <> struct ratio_string<kibi, char32_t>;
+ template <> struct ratio_string<kibi, wchar_t>;
+
+ template <> struct ratio_string<mebi, char>;
+ template <> struct ratio_string<mebi, char16_t>;
+ template <> struct ratio_string<mebi, char32_t>;
+ template <> struct ratio_string<mebi, wchar_t>;
+
+ template <> struct ratio_string<gibi, char>;
+ template <> struct ratio_string<gibi, char16_t>;
+ template <> struct ratio_string<gibi, char32_t>;
+ template <> struct ratio_string<gibi, wchar_t>;
+
+ template <> struct ratio_string<tebi, char>;
+ template <> struct ratio_string<tebi, char16_t>;
+ template <> struct ratio_string<tebi, char32_t>;
+ template <> struct ratio_string<tebi, wchar_t>;
+
+ template <> struct ratio_string<pebi, char>;
+ template <> struct ratio_string<pebi, char16_t>;
+ template <> struct ratio_string<pebi, char32_t>;
+ template <> struct ratio_string<pebi, wchar_t>;
+
+ template <> struct ratio_string<yobi, char>;
+ template <> struct ratio_string<yobi, char16_t>;
+ template <> struct ratio_string<yobi, char32_t>;
+ template <> struct ratio_string<yobi, wchar_t>;
+
     }
 
 [section:ratio_string Template Class `ratio_string<>`]
@@ -1861,6 +1950,14 @@
 [section:history Appendix A: History]
 [/==================================]
 
+[section [*Version 2.1.0, Febreary 1, 2014 - 1.56] ]
+
+[*New Features:]
+
+* [@http://svn.boost.org/trac/boost/ticket/XXXX #XXXX] Add ratio_power.
+* [@http://svn.boost.org/trac/boost/ticket/XXXX #XXXX] Add IEC binary prefixes.
+
+[endsect]
 [section [*Version 2.0.1, Febreary 1, 2013 - 1.53] ]
 
 [*Fixes:]
@@ -2008,7 +2105,7 @@
                      ((d1 * d2) / gcd(d1,d2))
 
 
-Multipliying and diving by gcd(n1,n2) in numerator
+Multiplying and diving by gcd(n1,n2) in numerator
 
       ( ((gcd(n1,n2)*(n1/gcd(n1,n2))) * (d2/gcd(d1,d2))) +
         ((gcd(n1,n2)*(n2/gcd(n1,n2))) * (d1/gcd(d1,d2)))

Modified: trunk/libs/ratio/test/Jamfile.v2
==============================================================================
--- trunk/libs/ratio/test/Jamfile.v2 Sat Nov 9 10:59:41 2013 (r86600)
+++ trunk/libs/ratio/test/Jamfile.v2 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -54,7 +54,7 @@
         <toolset>intel:<cxxflags>-wd304,1418
     ;
 
- test-suite "ratio.ratio"
+ test-suite "ratio_ratio"
         :
         [ compile typedefs_pass.cpp ]
         [ compile ratio_ratio/ratio_pass.cpp ]
@@ -70,7 +70,7 @@
         [ run ratio_io/ratio_io_pass.cpp ]
         ;
 
- test-suite "ratio.arithmetic"
+ test-suite "ratio_arithmetic"
         :
         [ compile ratio_arithmetic/ratio_add_pass.cpp ]
         [ compile ratio_arithmetic/ratio_subtract_pass.cpp ]
@@ -82,10 +82,13 @@
         [ compile-fail ratio_arithmetic/ratio_subtract_fail.cpp ]
         [ compile-fail ratio_arithmetic/ratio_multiply_fail.cpp ]
         [ compile-fail ratio_arithmetic/ratio_divide_fail.cpp ]
+ [ compile ratio_arithmetic/ratio_negate_pass.cpp ]
+ [ compile ratio_arithmetic/ratio_sign_pass.cpp ]
+ [ compile ratio_arithmetic/ratio_abs_pass.cpp ]
         [ compile ratio_arithmetic/ratio_power_pass.cpp ]
         ;
 
- test-suite "ratio.comparison"
+ test-suite "ratio_comparison"
         :
         [ compile ratio_comparison/ratio_equal_pass.cpp ]
         [ compile ratio_comparison/ratio_not_equal_pass.cpp ]
@@ -101,7 +104,7 @@
         [ run ../example/display_ex.cpp ]
         ;
 
- test-suite "ratio.ext"
+ test-suite "ratio_ext"
         :
         [ run ratio_extensions/ratio_ext_pass.cpp ]
         [ compile ratio_extensions/mpl_plus_pass.cpp ]

Added: trunk/libs/ratio/test/ratio_arithmetic/ratio_abs_pass.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/ratio/test/ratio_arithmetic/ratio_abs_pass.cpp 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// test ratio_abs
+
+#define BOOST_RATIO_EXTENSIONS
+
+#include <boost/ratio/ratio.hpp>
+#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+void test()
+{
+
+ {
+ typedef boost::ratio<0> R1;
+ typedef boost::ratio_abs<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 0 && R::den == 1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, 1> R1;
+ typedef boost::ratio_abs<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, 2> R1;
+ typedef boost::ratio_abs<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<-1, 2> R1;
+ typedef boost::ratio_abs<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, -2> R1;
+ typedef boost::ratio_abs<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
+ }
+}

Added: trunk/libs/ratio/test/ratio_arithmetic/ratio_negate_pass.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/ratio/test/ratio_arithmetic/ratio_negate_pass.cpp 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// test ratio_negate
+
+#define BOOST_RATIO_EXTENSIONS
+
+#include <boost/ratio/ratio.hpp>
+#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+void test()
+{
+
+ {
+ typedef boost::ratio<0> R1;
+ typedef boost::ratio_negate<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 0 && R::den == 1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, 1> R1;
+ typedef boost::ratio_negate<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, 2> R1;
+ typedef boost::ratio_negate<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<-1, 2> R1;
+ typedef boost::ratio_negate<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, -2> R1;
+ typedef boost::ratio_negate<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
+ }
+}

Added: trunk/libs/ratio/test/ratio_arithmetic/ratio_sign_pass.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/ratio/test/ratio_arithmetic/ratio_sign_pass.cpp 2013-11-09 12:00:41 EST (Sat, 09 Nov 2013) (r86601)
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// test ratio_sign
+
+#define BOOST_RATIO_EXTENSIONS
+
+#include <boost/ratio/ratio.hpp>
+#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+void test()
+{
+
+ {
+ typedef boost::ratio<0> R1;
+ typedef boost::ratio_sign<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::value == 0, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, 1> R1;
+ typedef boost::ratio_sign<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::value == 1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, 2> R1;
+ typedef boost::ratio_sign<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::value == 1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<-1, 2> R1;
+ typedef boost::ratio_sign<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::value == -1, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<1, -2> R1;
+ typedef boost::ratio_sign<R1> R;
+ BOOST_RATIO_STATIC_ASSERT(R::value == -1, NOTHING, ());
+ }
+}


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