|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52751 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-05-03 17:33:36
Author: bruno.lalande
Date: 2009-05-03 17:33:35 EDT (Sun, 03 May 2009)
New Revision: 52751
URL: http://svn.boost.org/trac/boost/changeset/52751
Log:
Reindented everything to reflect the rules now used in the GGL.
Text files modified:
sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp | 16 +-
sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp | 114 +++++++++---------
sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp | 40 +++---
sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 249 +++++++++++++++++++--------------------
sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp | 32 ++--
5 files changed, 225 insertions(+), 226 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-05-03 17:33:35 EDT (Sun, 03 May 2009)
@@ -22,16 +22,16 @@
template <typename ClnType>
struct cln_policy: ieee_policy<ClnType>
{
- static inline void sqrt(ClnType& r, const ClnType& a)
- {
- r = cln::sqrt(a);
- }
+ static inline void sqrt(ClnType& r, const ClnType& a)
+ {
+ r = cln::sqrt(a);
+ }
template <typename CT>
- static inline CT big_numeric_cast(const ClnType& b)
- {
- return cln::double_approx(b);
- }
+ static inline CT big_numeric_cast(const ClnType& b)
+ {
+ return cln::double_approx(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-05-03 17:33:35 EDT (Sun, 03 May 2009)
@@ -16,64 +16,64 @@
struct gmp_policy
{
- typedef mpf_t type;
+ typedef mpf_t type;
- static inline void init(type& value)
- {
- mpf_init(value);
- }
-
- static inline void destruct(type& value)
- {
- mpf_clear(value);
- }
-
- template <typename CT>
- static inline void set(type& value, const CT& v)
- {
- mpf_set_d(value, v);
- }
-
- static inline void copy(const type& source, type& dest)
- {
- mpf_set(dest, source);
- }
-
- static inline void add(type& r, const type& a, const type& b)
- {
- mpf_add(r, a, b);
- }
-
- static inline void subtract(type& r, const type& a, const type& b)
- {
- mpf_sub(r, a, b);
- }
-
- static inline void multiply(type& r, const type& a, const type& b)
- {
- mpf_mul(r, a, b);
- }
-
- static inline void divide(type& r, const type& a, const type& b)
- {
- mpf_div(r, a, b);
- }
-
- static inline void sqrt(type& r, const type& a)
- {
- mpf_sqrt(r, a);
- }
-
- template <typename CT>
- static inline CT big_numeric_cast(const type& b)
- {
- return mpf_get_d(b);
- }
-
- static inline int compare(const type& a, const type& b)
- {
- return mpf_cmp(a, b);
- }
+ static inline void init(type& value)
+ {
+ mpf_init(value);
+ }
+
+ static inline void destruct(type& value)
+ {
+ mpf_clear(value);
+ }
+
+ template <typename CT>
+ static inline void set(type& value, const CT& v)
+ {
+ mpf_set_d(value, v);
+ }
+
+ static inline void copy(const type& source, type& dest)
+ {
+ mpf_set(dest, source);
+ }
+
+ static inline void add(type& r, const type& a, const type& b)
+ {
+ mpf_add(r, a, b);
+ }
+
+ static inline void subtract(type& r, const type& a, const type& b)
+ {
+ mpf_sub(r, a, b);
+ }
+
+ static inline void multiply(type& r, const type& a, const type& b)
+ {
+ mpf_mul(r, a, b);
+ }
+
+ static inline void divide(type& r, const type& a, const type& b)
+ {
+ mpf_div(r, a, b);
+ }
+
+ static inline void sqrt(type& r, const type& a)
+ {
+ mpf_sqrt(r, a);
+ }
+
+ template <typename CT>
+ static inline CT big_numeric_cast(const type& b)
+ {
+ return mpf_get_d(b);
+ }
+
+ static inline int compare(const type& a, const type& b)
+ {
+ return mpf_cmp(a, 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-03 17:33:35 EDT (Sun, 03 May 2009)
@@ -18,33 +18,33 @@
template <typename T>
struct ieee_policy
{
- typedef T type;
+ typedef T type;
- static inline void init(type& value) {}
- static inline void destruct(type& value) {}
+ 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 CT>
+ static inline void set (type& value, const CT& v) { value = boost::numeric_cast<T>(v); }
- static inline void copy(const type& source, type& dest) { dest = source; }
+ static inline void copy(const type& source, type& dest) { dest = source; }
- static inline void add(type& r, const type& a, const type& b) { r = a + b; }
- static inline void subtract(type& r, const type& a, const type& b) { r = a - b; }
- 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 add(type& r, const type& a, const type& b) { r = a + b; }
+ static inline void subtract(type& r, const type& a, const type& b) { r = a - b; }
+ 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 = ::sqrt(a); }
- template <typename CT>
- static inline CT big_numeric_cast(const type& v)
- {
- return boost::numeric_cast<CT>(v);
- }
+ template <typename CT>
+ static inline CT big_numeric_cast(const type& v)
+ {
+ return boost::numeric_cast<CT>(v);
+ }
- static inline int compare(const type& a, const type& b)
- {
- return a < b ? -1 : a > b ? 1 : 0;
- }
+ static inline int compare(const type& a, const type& b)
+ {
+ return a < b ? -1 : a > b ? 1 : 0;
+ }
};
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-03 17:33:35 EDT (Sun, 03 May 2009)
@@ -14,131 +14,130 @@
template <typename POLICY>
struct numeric_adaptor
{
- inline numeric_adaptor()
- {
- POLICY::init(value);
- }
-
- // Copy constructor
- inline numeric_adaptor(const numeric_adaptor<POLICY>& v)
- {
- 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);
- }
-
- virtual ~numeric_adaptor()
- {
- POLICY::destruct(value);
- }
-
- // Assignment from other value
- inline numeric_adaptor<POLICY> operator=(const numeric_adaptor<POLICY>& v)
- {
- POLICY::copy(v.value, this->value);
- return *this;
- }
-
- // Assignment from normal IEEE type
- template <typename T>
- inline numeric_adaptor<POLICY> operator=(const T& v)
- {
- POLICY::template set<T>(this->value, v);
- return *this;
- }
-
- // Cast to normal IEEE type
- template <typename T>
- inline operator T() const
- {
- return POLICY::template big_numeric_cast<T>(value);
- }
-
-
- // Comparisons
- inline bool operator<(const numeric_adaptor<POLICY>& other) const
- {
- return POLICY::compare(value, other.value) < 0;
- }
-
- inline bool operator>(const numeric_adaptor<POLICY>& other) const
- {
- return POLICY::compare(value, other.value) > 0;
- }
-
- inline bool operator==(const numeric_adaptor<POLICY>& other) const
- {
- return POLICY::compare(value, other.value) == 0;
- }
-
- // Operators
- 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);
- }
-
- 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);
- }
-
- 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);
- }
-
- 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);
- }
-
- // Functions
- 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);
- }
-
- private :
- 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)
- {
- POLICY::init(value);
- POLICY::copy(v, value);
- }
-
+ inline numeric_adaptor()
+ {
+ POLICY::init(value);
+ }
+
+ // Copy constructor
+ inline numeric_adaptor(const numeric_adaptor<POLICY>& v)
+ {
+ 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);
+ }
+
+ virtual ~numeric_adaptor()
+ {
+ POLICY::destruct(value);
+ }
+
+ // Assignment from other value
+ inline numeric_adaptor<POLICY> operator=(const numeric_adaptor<POLICY>& v)
+ {
+ POLICY::copy(v.value, this->value);
+ return *this;
+ }
+
+ // Assignment from normal IEEE type
+ template <typename T>
+ inline numeric_adaptor<POLICY> operator=(const T& v)
+ {
+ POLICY::template set<T>(this->value, v);
+ return *this;
+ }
+
+ // Cast to normal IEEE type
+ template <typename T>
+ inline operator T() const
+ {
+ return POLICY::template big_numeric_cast<T>(value);
+ }
+
+
+ // Comparisons
+ inline bool operator<(const numeric_adaptor<POLICY>& other) const
+ {
+ return POLICY::compare(value, other.value) < 0;
+ }
+
+ inline bool operator>(const numeric_adaptor<POLICY>& other) const
+ {
+ return POLICY::compare(value, other.value) > 0;
+ }
+
+ inline bool operator==(const numeric_adaptor<POLICY>& other) const
+ {
+ return POLICY::compare(value, other.value) == 0;
+ }
+
+ // Operators
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ // Functions
+ 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);
+ }
+
+private :
+ 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)
+ {
+ 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-03 17:33:35 EDT (Sun, 03 May 2009)
@@ -18,26 +18,26 @@
template <class Policy>
double heron()
{
- typedef numeric_adaptor<Policy> num;
-
- num a = 31622.77662;
- 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));
+ typedef numeric_adaptor<Policy> num;
+
+ num a = 31622.77662;
+ 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));
}
int test_main(int, char*[])
{
- double epsilon = 0.0000001;
+ 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);
- BOOST_CHECK_CLOSE(heron<cln_ff_policy>(), 0.0, epsilon);
- BOOST_CHECK_CLOSE(heron<cln_df_policy>(), 0.32749053277825713, epsilon);
- //TODO cln_lf_policy
- BOOST_CHECK_CLOSE(heron<gmp_policy>(), 0.327490459942623, epsilon);
+ 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);
+ BOOST_CHECK_CLOSE(heron<cln_ff_policy>(), 0.0, epsilon);
+ BOOST_CHECK_CLOSE(heron<cln_df_policy>(), 0.32749053277825713, epsilon);
+ //TODO cln_lf_policy
+ BOOST_CHECK_CLOSE(heron<gmp_policy>(), 0.327490459942623, epsilon);
- return 0;
+ return 0;
};
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