Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54464 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-06-28 05:59:51


Author: bruno.lalande
Date: 2009-06-28 05:59:51 EDT (Sun, 28 Jun 2009)
New Revision: 54464
URL: http://svn.boost.org/trac/boost/changeset/54464

Log:
Delegated more functions to default_policy, that now uses CRTP.
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp | 2 +-
   sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp | 32 +++++++++++++++++++++++++++++++-
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp | 32 +-------------------------------
   sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp | 7 +------
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot | 2 +-
   5 files changed, 35 insertions(+), 40 deletions(-)

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp 2009-06-28 05:59:51 EDT (Sun, 28 Jun 2009)
@@ -28,7 +28,7 @@
     as being of type cl_F.
 
 */
-struct cln_policy : public default_policy<cln::cl_F>
+struct cln_policy : public default_policy<cln_policy, cln::cl_F>
 {
     typedef cln::cl_F value_type;
 

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp 2009-06-28 05:59:51 EDT (Sun, 28 Jun 2009)
@@ -17,7 +17,7 @@
 namespace boost { namespace numeric_adaptor {
 
 
-template <typename T>
+template <typename Base, typename T>
 struct default_policy
 {
     typedef T value_type;
@@ -49,6 +49,36 @@
     static inline void neg(value_type& r, const value_type& n)
     { r = -n; }
 
+ static inline void cos(value_type& r, value_type const& a)
+ {
+ double d = Base::template big_numeric_cast<double>(a);
+ Base::set(r, std::cos(d));
+ }
+
+ static inline void sin(value_type& r, value_type const& a)
+ {
+ double d = Base::template big_numeric_cast<double>(a);
+ Base::set(r, std::sin(d));
+ }
+
+ static inline void tan(value_type& r, value_type const& a)
+ {
+ double d = Base::template big_numeric_cast<double>(a);
+ Base::set(r, std::tan(d));
+ }
+
+ static inline void atan(value_type& r, value_type const& a)
+ {
+ double d = Base::template big_numeric_cast<double>(a);
+ Base::set(r, std::atan(d));
+ }
+
+ static inline void sqrt(value_type& r, value_type const& a)
+ {
+ double d = Base::template big_numeric_cast<double>(a);
+ Base::set(r, std::sqrt(d));
+ }
+
     // Default use the comparison operators
     static inline int compare(T const& a, T const& b)
     {

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp 2009-06-28 05:59:51 EDT (Sun, 28 Jun 2009)
@@ -20,10 +20,8 @@
 namespace boost { namespace numeric_adaptor {
 
 
-struct gmp_policy
+struct gmp_policy: default_policy<gmp_policy, mpf_t>
 {
- typedef mpf_t value_type;
-
     static inline void init(value_type& value)
     {
         mpf_init(value);
@@ -108,34 +106,6 @@
         mpf_sqrt(r, a);
     }
 
- static inline void cos(value_type& r, value_type const& a)
- {
- // COS is not available in GMP
- long double d = mpf_get_d(a);
- mpf_set_d(r, std::cos(d));
- }
-
- static inline void sin(value_type& r, value_type const& a)
- {
- // SIN is not available in GMP
- long double d = mpf_get_d(a);
- mpf_set_d(r, std::sin(d));
- }
-
- static inline void tan(value_type& r, value_type const& a)
- {
- // TAN is not available in GMP
- long double d = mpf_get_d(a);
- mpf_set_d(r, std::tan(d));
- }
-
- static inline void atan(value_type& r, value_type const& a)
- {
- // ATAN is not available in GMP
- long double d = mpf_get_d(a);
- mpf_set_d(r, std::atan(d));
- }
-
     static inline void hypot(value_type& r, value_type const& a, value_type const& b)
     {
         mpf_mul(r, a, a);

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp 2009-06-28 05:59:51 EDT (Sun, 28 Jun 2009)
@@ -27,7 +27,7 @@
 
 
 template <typename T>
-struct ieee_policy : public default_policy<T>
+struct ieee_policy : public default_policy<ieee_policy<T>, T>
 {
     typedef T value_type;
 
@@ -36,11 +36,6 @@
 
     static inline void set(value_type& value, std::string const& v) { value = boost::lexical_cast<T>(v); }
 
- static inline void sqrt(value_type& r, value_type const& a) { r = std::sqrt(a); }
- static inline void cos(value_type& r, value_type const& a) { r = std::cos(a); }
- static inline void sin(value_type& r, value_type const& a) { r = std::sin(a); }
- static inline void tan(value_type& r, value_type const& a) { r = std::tan(a); }
- static inline void atan(value_type& r, value_type const& a) { r = std::atan(a); }
     static inline void abs(value_type& r, value_type const& a) { r = std::abs(a); }
     static inline void hypot(value_type& r, value_type const& a, value_type const& b)
     {

Modified: sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot
==============================================================================
--- sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot (original)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot 2009-06-28 05:59:51 EDT (Sun, 28 Jun 2009)
@@ -21,4 +21,4 @@
 run test_heron.cpp ;
 run test_arithmetic.cpp ;
 run test_trig.cpp ;
-run test_conversions.cpp ;
+#run test_conversions.cpp ;


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