Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54542 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-06-30 16:41:02


Author: bruno.lalande
Date: 2009-06-30 16:41:01 EDT (Tue, 30 Jun 2009)
New Revision: 54542
URL: http://svn.boost.org/trac/boost/changeset/54542

Log:
Made abs, sqrt, cos, sin, tan, atan and hypot free functions.
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 154 ++++++++++++++++++++++++---------------
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_arithmetic.cpp | 2
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp | 2
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp | 10 +-
   4 files changed, 102 insertions(+), 66 deletions(-)

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp 2009-06-30 16:41:01 EDT (Tue, 30 Jun 2009)
@@ -15,6 +15,7 @@
 
 #include <string>
 
+
 namespace boost { namespace numeric_adaptor {
 
 
@@ -28,10 +29,28 @@
 };
 
 
+template <typename> struct numeric_adaptor;
+
+
+template <typename Policy>
+numeric_adaptor<Policy> abs(numeric_adaptor<Policy> const&);
+template <typename Policy>
+numeric_adaptor<Policy> sqrt(numeric_adaptor<Policy> const&);
+template <typename Policy>
+numeric_adaptor<Policy> sin(numeric_adaptor<Policy> const&);
+template <typename Policy>
+numeric_adaptor<Policy> cos(numeric_adaptor<Policy> const&);
+template <typename Policy>
+numeric_adaptor<Policy> tan(numeric_adaptor<Policy> const&);
+template <typename Policy>
+numeric_adaptor<Policy> atan(numeric_adaptor<Policy> const&);
+template <typename Policy>
+numeric_adaptor<Policy> hypot(numeric_adaptor<Policy> const&,
+ numeric_adaptor<Policy> const&);
 
 
 template <typename Policy>
-struct numeric_adaptor :
+struct numeric_adaptor:
     enable_cast<numeric_adaptor<Policy>, int>,
     enable_cast<numeric_adaptor<Policy>, unsigned int>,
     enable_cast<numeric_adaptor<Policy>, short int>,
@@ -198,77 +217,92 @@
         return numeric_adaptor<Policy>(r, true);
     }
 
- // Functions
- static inline numeric_adaptor<Policy> abs(numeric_adaptor<Policy> const& v)
- {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::abs(r, v.value);
- return numeric_adaptor<Policy>(r, true);
- }
+private :
+ typename Policy::value_type value;
 
- static inline numeric_adaptor<Policy> sqrt(numeric_adaptor<Policy> const& v)
- {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::sqrt(r, v.value);
- return numeric_adaptor<Policy>(r, true);
- }
+ friend numeric_adaptor<Policy> abs<Policy>(numeric_adaptor<Policy> const&);
+ friend numeric_adaptor<Policy> sqrt<Policy>(numeric_adaptor<Policy> const&);
+ friend numeric_adaptor<Policy> cos<Policy>(numeric_adaptor<Policy> const&);
+ friend numeric_adaptor<Policy> sin<Policy>(numeric_adaptor<Policy> const&);
+ friend numeric_adaptor<Policy> tan<Policy>(numeric_adaptor<Policy> const&);
+ friend numeric_adaptor<Policy> atan<Policy>(numeric_adaptor<Policy> const&);
+ friend numeric_adaptor<Policy> hypot<Policy>(numeric_adaptor<Policy> const&,
+ numeric_adaptor<Policy> const&);
 
- static inline numeric_adaptor<Policy> cos(numeric_adaptor<Policy> const& v)
+ // Construct from a policy-type. Bool (or any other signature changing parameter)
+ // is necessary for cases where type == OtherType
+ inline numeric_adaptor<Policy>(typename Policy::value_type const& v, bool)
     {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::cos(r, v.value);
- return numeric_adaptor<Policy>(r, true);
+ Policy::init(value);
+ Policy::copy(v, value);
     }
+};
 
- static inline numeric_adaptor<Policy> sin(numeric_adaptor<Policy> const& v)
- {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::sin(r, v.value);
- return numeric_adaptor<Policy>(r, true);
- }
 
- static inline numeric_adaptor<Policy> tan(numeric_adaptor<Policy> const& v)
- {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::tan(r, v.value);
- return numeric_adaptor<Policy>(r, true);
- }
+template <typename Policy>
+inline numeric_adaptor<Policy> abs(numeric_adaptor<Policy> const& v)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::abs(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
- static inline numeric_adaptor<Policy> atan(numeric_adaptor<Policy> const& v)
- {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::atan(r, v.value);
- return numeric_adaptor<Policy>(r, true);
- }
+template <typename Policy>
+inline numeric_adaptor<Policy> sqrt(numeric_adaptor<Policy> const& v)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::sqrt(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
+template <typename Policy>
+inline numeric_adaptor<Policy> cos(numeric_adaptor<Policy> const& v)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::cos(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
- static inline numeric_adaptor<Policy> hypot(numeric_adaptor<Policy> const& a,
- numeric_adaptor<Policy> const& b)
- {
- typename Policy::value_type r;
- Policy::init(r);
- Policy::hypot(r, a.value, b.value);
- return numeric_adaptor<Policy>(r, true);
- }
+template <typename Policy>
+inline numeric_adaptor<Policy> sin(numeric_adaptor<Policy> const& v)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::sin(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
+template <typename Policy>
+inline numeric_adaptor<Policy> tan(numeric_adaptor<Policy> const& v)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::tan(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
-private :
- typename Policy::value_type value;
+template <typename Policy>
+inline numeric_adaptor<Policy> atan(numeric_adaptor<Policy> const& v)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::atan(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
- // Construct from a policy-type. Bool (or any other signature changing parameter)
- // is necessary for cases where type == OtherType
- inline numeric_adaptor<Policy>(typename Policy::value_type const& v, bool)
- {
- Policy::init(value);
- Policy::copy(v, value);
- }
-};
+
+template <typename Policy>
+inline numeric_adaptor<Policy> hypot(numeric_adaptor<Policy> const& a,
+ numeric_adaptor<Policy> const& b)
+{
+ typename Policy::value_type r;
+ Policy::init(r);
+ Policy::hypot(r, a.value, b.value);
+ return numeric_adaptor<Policy>(r, true);
+}
 
 
 }} // namespace boost::numeric_adaptor

Modified: sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_arithmetic.cpp
==============================================================================
--- sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_arithmetic.cpp (original)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_arithmetic.cpp 2009-06-30 16:41:01 EDT (Tue, 30 Jun 2009)
@@ -54,6 +54,8 @@
     BOOST_CHECK_EQUAL((double)-n4, -4.0);
     BOOST_CHECK_EQUAL((double)-n5, -56.0);
     BOOST_CHECK_EQUAL((double)-n6, -2.0);
+
+ BOOST_CHECK_EQUAL((double)boost::numeric_adaptor::abs(-n5), 56.0);
 }
 
 int test_main(int, char*[])

Modified: sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp
==============================================================================
--- sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp (original)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp 2009-06-30 16:41:01 EDT (Tue, 30 Jun 2009)
@@ -30,7 +30,7 @@
     num b = 0.000023;
     num c = 31622.77661;
     num s((a + b + c) / num(2.0));
- return num::sqrt(s * (s - a) * (s - b) * (s - c));
+ return boost::numeric_adaptor::sqrt(s * (s - a) * (s - b) * (s - c));
 }
 
 int test_main(int, char*[])

Modified: sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp
==============================================================================
--- sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp (original)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp 2009-06-30 16:41:01 EDT (Tue, 30 Jun 2009)
@@ -31,11 +31,11 @@
 
     num n1 = 123.0;
     num n2 = 456.0;
- BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::numeric_adaptor<Policy>::cos(n1), ::cos(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::numeric_adaptor<Policy>::sin(n1), ::sin(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::numeric_adaptor<Policy>::tan(n1), ::tan(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::numeric_adaptor<Policy>::atan(n1), ::atan(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::numeric_adaptor<Policy>::hypot(n1, n2), ::hypot(123.0, 456.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::cos(n1), ::cos(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::sin(n1), ::sin(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::tan(n1), ::tan(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::atan(n1), ::atan(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::numeric_adaptor::hypot(n1, n2), ::hypot(123.0, 456.0), epsilon);
 }
 
 int test_main(int, char*[])


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