Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55004 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-07-17 17:27:11


Author: bruno.lalande
Date: 2009-07-17 17:27:10 EDT (Fri, 17 Jul 2009)
New Revision: 55004
URL: http://svn.boost.org/trac/boost/changeset/55004

Log:
Started rewriting numeric_adaptor a totally different way.
Added:
   sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp (contents, props changed)
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp (contents, props changed)
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 12 +++++++++---
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot | 4 ++--
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_heron.cpp | 29 +++++++++++++----------------
   3 files changed, 24 insertions(+), 21 deletions(-)

Added: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp 2009-07-17 17:27:10 EDT (Fri, 17 Jul 2009)
@@ -0,0 +1,93 @@
+// Numeric Adaptor Library
+//
+// 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
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifndef NUMERIC_ADAPTOR_CLN_VALUE_TYPE_HPP
+#define NUMERIC_ADAPTOR_CLN_VALUE_TYPE_HPP
+
+
+#include <cln/cln.h>
+#include <cln/float.h>
+
+
+namespace boost { namespace numeric_adaptor {
+
+
+/*
+ CLN documentation, 3.2:
+ As a user of CLN, you can forget about the differences between the four
+ Floating-point types and just declare all your Foating-point variables
+ as being of type cl_F.
+
+*/
+struct cln_value_type //: public default_value_type<cln_policy, cln::cl_F>
+{
+ cln_value_type()
+ {}
+
+ cln_value_type(double v)
+ {
+ // Conversions from the C built-in type `double' are provided for the
+ // classes cl_DF, cl_F, cl_R, cl_N and cl_number
+ m_value = cln::cl_float(v, cln::float_format(256));
+ }
+
+ cln_value_type(cln::cl_F const& v):
+ m_value(v)
+ {}
+
+ operator double()
+ {
+ return cln::double_approx(m_value);
+ }
+
+ friend inline cln_value_type operator+(
+ cln_value_type const& a,
+ cln_value_type const& b)
+ {
+ return cln_value_type(a.m_value + b.m_value);
+ }
+
+ friend inline cln_value_type operator-(
+ cln_value_type const& a,
+ cln_value_type const& b)
+ {
+ return cln_value_type(a.m_value - b.m_value);
+ }
+
+ friend inline cln_value_type operator*(
+ cln_value_type const& a,
+ cln_value_type const& b)
+ {
+ return cln_value_type(a.m_value * b.m_value);
+ }
+
+ friend inline cln_value_type operator/(
+ cln_value_type const& a,
+ cln_value_type const& b)
+ {
+ return cln_value_type(a.m_value / b.m_value);
+ }
+
+ cln::cl_F m_value;
+};
+
+
+} // namespace numeric_adaptor
+
+
+numeric_adaptor::cln_value_type sqrt(numeric_adaptor::cln_value_type const& v)
+{
+ return numeric_adaptor::cln_value_type(cln::sqrt(v.m_value));
+}
+
+
+} // namespace boost
+
+
+#endif

Added: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp 2009-07-17 17:27:10 EDT (Fri, 17 Jul 2009)
@@ -0,0 +1,97 @@
+// Numeric Adaptor Library
+//
+// 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
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifndef NUMERIC_ADAPTOR_GMP_VALUE_TYPE_HPP
+#define NUMERIC_ADAPTOR_GMP_VALUE_TYPE_HPP
+
+
+#include <gmp.h>
+
+
+namespace boost { namespace numeric_adaptor {
+
+
+struct gmp_value_type
+{
+ gmp_value_type()
+ {
+ mpf_init(m_value);
+ }
+
+ gmp_value_type(double v)
+ {
+ mpf_init(m_value);
+ mpf_set_d(m_value, v);
+ }
+
+ ~gmp_value_type()
+ {
+ mpf_clear(m_value);
+ }
+
+ operator double()
+ {
+ return mpf_get_d(m_value);
+ }
+
+ friend inline gmp_value_type operator+(
+ gmp_value_type const& a,
+ gmp_value_type const& b)
+ {
+ gmp_value_type r;
+ mpf_add(r.m_value, a.m_value, b.m_value);
+ return r;
+ }
+
+ friend inline gmp_value_type operator-(
+ gmp_value_type const& a,
+ gmp_value_type const& b)
+ {
+ gmp_value_type r;
+ mpf_sub(r.m_value, a.m_value, b.m_value);
+ return r;
+ }
+
+ friend inline gmp_value_type operator*(
+ gmp_value_type const& a,
+ gmp_value_type const& b)
+ {
+ gmp_value_type r;
+ mpf_mul(r.m_value, a.m_value, b.m_value);
+ return r;
+ }
+
+ friend inline gmp_value_type operator/(
+ gmp_value_type const& a,
+ gmp_value_type const& b)
+ {
+ gmp_value_type r;
+ mpf_div(r.m_value, a.m_value, b.m_value);
+ return r;
+ }
+
+ mpf_t m_value;
+};
+
+
+} // namespace numeric_adaptor
+
+
+numeric_adaptor::gmp_value_type sqrt(numeric_adaptor::gmp_value_type const& v)
+{
+ numeric_adaptor::gmp_value_type r;
+ mpf_sqrt(r.m_value, v.m_value);
+ return r;
+}
+
+
+} // namespace boost
+
+
+#endif

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-07-17 17:27:10 EDT (Fri, 17 Jul 2009)
@@ -11,9 +11,9 @@
 #define NUMERIC_ADAPTOR_NUMERIC_ADAPTOR_HPP
 
 
-#include <boost/static_assert.hpp>
-
+#include <cmath>
 #include <string>
+#include <boost/static_assert.hpp>
 
 
 namespace boost { namespace numeric_adaptor {
@@ -234,7 +234,13 @@
 }
 
 
-}} // namespace boost::numeric_adaptor
+} // namespace numeric_adaptor
+
+template <class T>
+T sqrt(T value)
+{ return std::sqrt(value); }
+
+} // namespace boost
 
 
 #endif

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-07-17 17:27:10 EDT (Fri, 17 Jul 2009)
@@ -19,6 +19,6 @@
 import testing ;
 
 run test_heron.cpp ;
-run test_arithmetic.cpp ;
-run test_trig.cpp ;
+#run test_arithmetic.cpp ;
+#run test_trig.cpp ;
 #run test_conversions.cpp ;

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-07-17 17:27:10 EDT (Fri, 17 Jul 2009)
@@ -10,43 +10,40 @@
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/floating_point_comparison.hpp>
 #include <boost/numeric_adaptor/numeric_adaptor.hpp>
-#include <boost/numeric_adaptor/ieee_policy.hpp>
 
 #if defined(HAVE_GMP)
-# include <boost/numeric_adaptor/gmp_policy.hpp>
+# include <boost/numeric_adaptor/gmp_value_type.hpp>
 #endif
 
 #if defined(HAVE_CLN)
-# include <boost/numeric_adaptor/cln_policy.hpp>
+# include <boost/numeric_adaptor/cln_value_type.hpp>
 #endif
 
 
-template <typename Policy>
+template <typename ValueType>
 double heron()
 {
- typedef boost::numeric_adaptor::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 sqrt(s * (s - a) * (s - b) * (s - c));
+ ValueType a = 31622.77662;
+ ValueType b = 0.000023;
+ ValueType c = 31622.77661;
+ ValueType s((a + b + c) / ValueType(2.0));
+ return boost::sqrt(s * (s - a) * (s - b) * (s - c));
 }
 
 int test_main(int, char*[])
 {
     double epsilon = 0.0000001;
 
- BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::ieee_policy<float> >(), 0.0, epsilon);
- BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::ieee_policy<double> >(), 0.327490532778257, epsilon);
- BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::ieee_policy<long double> >(), 0.327490459921098, epsilon);
+ BOOST_CHECK_CLOSE(heron<float>(), 0.0, epsilon);
+ BOOST_CHECK_CLOSE(heron<double>(), 0.32749040502871557, epsilon);
+ BOOST_CHECK_CLOSE(heron<long double>(), 0.327490459921098, epsilon);
 
 #if defined(HAVE_CLN)
- BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::cln_policy>(), 0.32749045994262366, epsilon);
+ BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::cln_value_type>(), 0.32749045994262366, epsilon);
 #endif
 
 #if defined(HAVE_GMP)
- BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::gmp_policy>(), 0.327490459942623, epsilon);
+ BOOST_CHECK_CLOSE(heron<boost::numeric_adaptor::gmp_value_type>(), 0.327490459942623, epsilon);
 #endif
 
     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