Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52904 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: barend.gehrels_at_[hidden]
Date: 2009-05-11 11:06:25


Author: barendgehrels
Date: 2009-05-11 11:06:24 EDT (Mon, 11 May 2009)
New Revision: 52904
URL: http://svn.boost.org/trac/boost/changeset/52904

Log:
Added sin/cos
Adapted to new guidelines
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp | 25 ++++++-
   sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp | 16 ++--
   sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 133 ++++++++++++++++++++++-----------------
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp | 7 ++
   4 files changed, 111 insertions(+), 70 deletions(-)

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-05-11 11:06:24 EDT (Mon, 11 May 2009)
@@ -1,6 +1,6 @@
 // Numeric Adaptor Library
 //
-// Copyright Barend Gehrels 2009, Geodan Holding B.V. Amsterdam, the Netherlands.
+// Copyright Barend Gehrels 2009, Geodan, Amsterdam
 // Copyright Bruno Lalande 2009
 // Use, modification and distribution is subject to the Boost Software License,
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -28,8 +28,8 @@
         mpf_clear(value);
     }
 
- template <typename CT>
- static inline void set(type& value, const CT& v)
+ template <typename OtherType>
+ static inline void set(type& value, const OtherType& v)
     {
         mpf_set_d(value, v);
     }
@@ -64,8 +64,23 @@
         mpf_sqrt(r, a);
     }
 
- template <typename CT>
- static inline CT big_numeric_cast(const type& b)
+ static inline void cos(type& r, const type& a)
+ {
+ // COS is not available.
+ long double d = mpf_get_d(a);
+ mpf_set_d(r, std::cos(d));
+ }
+
+ static inline void sin(type& r, const type& a)
+ {
+ // SIN is not available.
+ long double d = mpf_get_d(a);
+ mpf_set_d(r, std::sin(d));
+ }
+
+
+ template <typename OtherType>
+ static inline OtherType big_numeric_cast(const type& b)
     {
         return mpf_get_d(b);
     }

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-05-11 11:06:24 EDT (Mon, 11 May 2009)
@@ -1,6 +1,6 @@
 // Numeric Adaptor Library
 
-// Copyright Barend Gehrels 2009, Geodan Holding B.V. Amsterdam, the Netherlands.
+// Copyright Barend Gehrels 2009, Geodan, Amsterdam
 // Copyright Bruno Lalande 2009
 // Use, modification and distribution is subject to the Boost Software License,
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -23,8 +23,8 @@
     static inline void init(type& value) {}
     static inline void destruct(type& value) {}
 
- template <typename CT>
- static inline void set (type& value, const CT& v) { value = boost::numeric_cast<T>(v); }
+ template <typename OtherType>
+ static inline void set (type& value, const OtherType& v) { value = boost::numeric_cast<T>(v); }
 
     static inline void copy(const type& source, type& dest) { dest = source; }
 
@@ -33,12 +33,14 @@
     static inline void multiply(type& r, const type& a, const type& b) { r = a * b; }
     static inline void divide(type& r, const type& a, const type& b) { r = a / b; }
 
- static inline void sqrt(type& r, const type& a) { r = ::sqrt(a); }
+ static inline void sqrt(type& r, const type& a) { r = std::sqrt(a); }
+ static inline void cos(type& r, const type& a) { r = std::cos(a); }
+ static inline void sin(type& r, const type& a) { r = std::sin(a); }
 
- template <typename CT>
- static inline CT big_numeric_cast(const type& v)
+ template <typename OtherType>
+ static inline OtherType big_numeric_cast(const type& v)
     {
- return boost::numeric_cast<CT>(v);
+ return boost::numeric_cast<OtherType>(v);
     }
 
     static inline int compare(const type& a, const type& b)

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-05-11 11:06:24 EDT (Mon, 11 May 2009)
@@ -1,6 +1,6 @@
 // Numeric Adaptor Library
 //
-// Copyright Barend Gehrels 2009, Geodan Holding B.V. Amsterdam, the Netherlands.
+// Copyright Barend Gehrels 2009, Geodan, Amsterdam
 // Copyright Bruno Lalande 2009
 // Use, modification and distribution is subject to the Boost Software License,
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -11,46 +11,46 @@
 #define NUMERIC_ADAPTOR_NUMERIC_ADAPTOR_HPP_
 
 
-template <typename POLICY>
+template <typename Policy>
 struct numeric_adaptor
 {
     inline numeric_adaptor()
     {
- POLICY::init(value);
+ Policy::init(value);
     }
 
     // Copy constructor
- inline numeric_adaptor(const numeric_adaptor<POLICY>& v)
+ inline numeric_adaptor(const numeric_adaptor<Policy>& v)
     {
- POLICY::init(value);
- POLICY::copy(v.value, value);
+ Policy::init(value);
+ Policy::copy(v.value, value);
     }
 
     // Constructor with a normal IEEE type
     template <typename T>
     inline numeric_adaptor(const T& v)
     {
- POLICY::init(value);
- POLICY::template set<T>(value, v);
+ Policy::init(value);
+ Policy::template set<T>(value, v);
     }
 
     virtual ~numeric_adaptor()
     {
- POLICY::destruct(value);
+ Policy::destruct(value);
     }
 
     // Assignment from other value
- inline numeric_adaptor<POLICY> operator=(const numeric_adaptor<POLICY>& v)
+ inline numeric_adaptor<Policy> operator=(const numeric_adaptor<Policy>& v)
     {
- POLICY::copy(v.value, this->value);
+ Policy::copy(v.value, this->value);
         return *this;
     }
 
     // Assignment from normal IEEE type
     template <typename T>
- inline numeric_adaptor<POLICY> operator=(const T& v)
+ inline numeric_adaptor<Policy> operator=(const T& v)
     {
- POLICY::template set<T>(this->value, v);
+ Policy::template set<T>(this->value, v);
         return *this;
     }
 
@@ -58,85 +58,102 @@
     template <typename T>
     inline operator T() const
     {
- return POLICY::template big_numeric_cast<T>(value);
+ return Policy::template big_numeric_cast<T>(value);
     }
 
 
     // Comparisons
- inline bool operator<(const numeric_adaptor<POLICY>& other) const
+ inline bool operator<(const numeric_adaptor<Policy>& other) const
     {
- return POLICY::compare(value, other.value) < 0;
+ return Policy::compare(value, other.value) < 0;
     }
 
- inline bool operator>(const numeric_adaptor<POLICY>& other) const
+ inline bool operator>(const numeric_adaptor<Policy>& other) const
     {
- return POLICY::compare(value, other.value) > 0;
+ return Policy::compare(value, other.value) > 0;
     }
 
- inline bool operator==(const numeric_adaptor<POLICY>& other) const
+ inline bool operator==(const numeric_adaptor<Policy>& other) const
     {
- return POLICY::compare(value, other.value) == 0;
+ return Policy::compare(value, other.value) == 0;
     }
 
     // Operators
- friend inline numeric_adaptor<POLICY> operator+(
- const numeric_adaptor<POLICY>& a,
- const numeric_adaptor<POLICY>& b)
+ friend inline numeric_adaptor<Policy> operator+(
+ const numeric_adaptor<Policy>& a,
+ const numeric_adaptor<Policy>& b)
     {
- typename POLICY::type r;
- POLICY::init(r);
- POLICY::add(r, a.value, b.value);
- return numeric_adaptor<POLICY>(r, true);
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::add(r, a.value, b.value);
+ return numeric_adaptor<Policy>(r, true);
     }
 
- friend inline numeric_adaptor<POLICY> operator*(
- const numeric_adaptor<POLICY>& a,
- const numeric_adaptor<POLICY>& b)
+ friend inline numeric_adaptor<Policy> operator*(
+ const numeric_adaptor<Policy>& a,
+ const numeric_adaptor<Policy>& b)
     {
- typename POLICY::type r;
- POLICY::init(r);
- POLICY::multiply(r, a.value, b.value);
- return numeric_adaptor<POLICY>(r, true);
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::multiply(r, a.value, b.value);
+ return numeric_adaptor<Policy>(r, true);
     }
 
- friend inline numeric_adaptor<POLICY> operator-(
- const numeric_adaptor<POLICY>& a,
- const numeric_adaptor<POLICY>& b)
+ friend inline numeric_adaptor<Policy> operator-(
+ const numeric_adaptor<Policy>& a,
+ const numeric_adaptor<Policy>& b)
     {
- typename POLICY::type r;
- POLICY::init(r);
- POLICY::subtract(r, a.value, b.value);
- return numeric_adaptor<POLICY>(r, true);
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::subtract(r, a.value, b.value);
+ return numeric_adaptor<Policy>(r, true);
     }
 
- friend inline numeric_adaptor<POLICY> operator/(
- const numeric_adaptor<POLICY>& a,
- const numeric_adaptor<POLICY>& b)
+ friend inline numeric_adaptor<Policy> operator/(
+ const numeric_adaptor<Policy>& a,
+ const numeric_adaptor<Policy>& b)
     {
- typename POLICY::type r;
- POLICY::init(r);
- POLICY::divide(r, a.value, b.value);
- return numeric_adaptor<POLICY>(r, true);
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::divide(r, a.value, b.value);
+ return numeric_adaptor<Policy>(r, true);
     }
 
     // Functions
- static inline numeric_adaptor<POLICY> sqrt(const numeric_adaptor<POLICY>& v)
+ static inline numeric_adaptor<Policy> sqrt(const numeric_adaptor<Policy>& v)
     {
- typename POLICY::type r;
- POLICY::init(r);
- POLICY::sqrt(r, v.value);
- return numeric_adaptor<POLICY>(r, true);
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::sqrt(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
     }
 
+ static inline numeric_adaptor<Policy> cos(const numeric_adaptor<Policy>& v)
+ {
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::cos(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+ }
+
+ static inline numeric_adaptor<Policy> sin(const numeric_adaptor<Policy>& v)
+ {
+ typename Policy::type r;
+ Policy::init(r);
+ Policy::sin(r, v.value);
+ return numeric_adaptor<Policy>(r, true);
+ }
+
+
 private :
- typename POLICY::type value;
+ typename Policy::type value;
 
     // Constructor with a type. Bool (or any other signature changing parameter)
- // is necessary for cases where type == CT
- inline numeric_adaptor<POLICY>(const typename POLICY::type& v, bool)
+ // is necessary for cases where type == OtherType
+ inline numeric_adaptor<Policy>(const typename Policy::type& v, bool)
     {
- POLICY::init(value);
- POLICY::copy(v, value);
+ Policy::init(value);
+ Policy::copy(v, value);
     }
 };
 

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-05-11 11:06:24 EDT (Mon, 11 May 2009)
@@ -11,7 +11,10 @@
 #include <boost/test/floating_point_comparison.hpp>
 #include <boost/numeric_adaptor/numeric_adaptor.hpp>
 #include <boost/numeric_adaptor/ieee_policy.hpp>
+#ifndef NO_CLN
 #include <boost/numeric_adaptor/cln_policy.hpp>
+#endif
+
 #include <boost/numeric_adaptor/gmp_policy.hpp>
 
 
@@ -29,13 +32,17 @@
 
 int test_main(int, char*[])
 {
+ std::cout << sizeof(long double) << std::endl;
+
     double epsilon = 0.0000001;
 
     BOOST_CHECK_CLOSE(heron<ieee_policy<float> >(), 0.0, epsilon);
     BOOST_CHECK_CLOSE(heron<ieee_policy<double> >(), 0.327490532778257, epsilon);
     BOOST_CHECK_CLOSE(heron<ieee_policy<long double> >(), 0.327490459921098, epsilon);
+#ifndef NO_CLN
     BOOST_CHECK_CLOSE(heron<cln_ff_policy>(), 0.0, epsilon);
     BOOST_CHECK_CLOSE(heron<cln_df_policy>(), 0.32749053277825713, epsilon);
+#endif
     //TODO cln_lf_policy
     BOOST_CHECK_CLOSE(heron<gmp_policy>(), 0.327490459942623, epsilon);
 


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