|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55006 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-07-17 18:09:31
Author: bruno.lalande
Date: 2009-07-17 18:09:29 EDT (Fri, 17 Jul 2009)
New Revision: 55006
URL: http://svn.boost.org/trac/boost/changeset/55006
Log:
Refactoring continued.
Text files modified:
sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp | 31 +++++++++++++++++++++++
sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp | 52 +++++++++++++++++++++++++++++++++++++++
sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 23 +++++++++++++++++
sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot | 6 ++--
sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp | 33 +++++++++++-------------
5 files changed, 122 insertions(+), 23 deletions(-)
Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp 2009-07-17 18:09:29 EDT (Fri, 17 Jul 2009)
@@ -41,7 +41,7 @@
m_value(v)
{}
- operator double()
+ operator double() const
{
return cln::double_approx(m_value);
}
@@ -110,6 +110,35 @@
return numeric_adaptor::cln_value_type(cln::sqrt(v.m_value));
}
+numeric_adaptor::cln_value_type cos(numeric_adaptor::cln_value_type const& v)
+{
+ return numeric_adaptor::cln_value_type(cln::cos(v.m_value));
+}
+
+numeric_adaptor::cln_value_type sin(numeric_adaptor::cln_value_type const& v)
+{
+ return numeric_adaptor::cln_value_type(cln::sin(v.m_value));
+}
+
+numeric_adaptor::cln_value_type tan(numeric_adaptor::cln_value_type const& v)
+{
+ return numeric_adaptor::cln_value_type(cln::tan(v.m_value));
+}
+
+numeric_adaptor::cln_value_type atan(numeric_adaptor::cln_value_type const& v)
+{
+ return numeric_adaptor::cln_value_type(cln::atan(v.m_value));
+}
+
+numeric_adaptor::cln_value_type hypot(
+ numeric_adaptor::cln_value_type const& a,
+ numeric_adaptor::cln_value_type const& b)
+{
+ return numeric_adaptor::cln_value_type(
+ cln::sqrt(a.m_value*a.m_value + b.m_value*b.m_value)
+ );
+}
+
} // namespace boost
Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp 2009-07-17 18:09:29 EDT (Fri, 17 Jul 2009)
@@ -30,12 +30,24 @@
mpf_set_d(m_value, v);
}
+ gmp_value_type(mpf_t& v)
+ {
+ mpf_init(m_value);
+ mpf_set(m_value, v);
+ }
+
+ gmp_value_type(gmp_value_type const& other)
+ {
+ mpf_init(m_value);
+ mpf_set(m_value, other.m_value);
+ }
+
~gmp_value_type()
{
mpf_clear(m_value);
}
- operator double()
+ operator double() const
{
return mpf_get_d(m_value);
}
@@ -114,6 +126,44 @@
return r;
}
+numeric_adaptor::gmp_value_type cos(numeric_adaptor::gmp_value_type const& v)
+{
+ return numeric_adaptor::gmp_value_type(std::cos(v));
+}
+
+numeric_adaptor::gmp_value_type sin(numeric_adaptor::gmp_value_type const& v)
+{
+ return numeric_adaptor::gmp_value_type(std::sin(v));
+}
+
+numeric_adaptor::gmp_value_type tan(numeric_adaptor::gmp_value_type const& v)
+{
+ return numeric_adaptor::gmp_value_type(std::tan(v));
+}
+
+numeric_adaptor::gmp_value_type atan(numeric_adaptor::gmp_value_type const& v)
+{
+ return numeric_adaptor::gmp_value_type(std::atan(v));
+}
+
+numeric_adaptor::gmp_value_type hypot(
+ numeric_adaptor::gmp_value_type const& a,
+ numeric_adaptor::gmp_value_type const& b)
+{
+ numeric_adaptor::gmp_value_type r;
+ mpf_t aa;
+ mpf_init(aa);
+ mpf_mul(aa, a.m_value, a.m_value);
+ mpf_t bb;
+ mpf_init(bb);
+ mpf_mul(bb, b.m_value, b.m_value);
+ mpf_add(r.m_value, aa, bb);
+ mpf_clear(aa);
+ mpf_clear(bb);
+ mpf_sqrt(r.m_value, r.m_value);
+ return r;
+}
+
} // namespace boost
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 18:09:29 EDT (Fri, 17 Jul 2009)
@@ -14,6 +14,7 @@
#include <cmath>
#include <string>
#include <boost/static_assert.hpp>
+#include <boost/math/special_functions/hypot.hpp>
namespace boost { namespace numeric_adaptor {
@@ -236,10 +237,32 @@
} // namespace numeric_adaptor
+
template <class T>
T sqrt(T value)
{ return std::sqrt(value); }
+template <class T>
+T cos(T value)
+{ return std::cos(value); }
+
+template <class T>
+T sin(T value)
+{ return std::sin(value); }
+
+template <class T>
+T tan(T value)
+{ return std::tan(value); }
+
+template <class T>
+T atan(T value)
+{ return std::atan(value); }
+
+template <class T>
+T hypot(T a, T b)
+{ return boost::math::hypot(a, b); }
+
+
} // namespace boost
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 18:09:29 EDT (Fri, 17 Jul 2009)
@@ -18,7 +18,7 @@
import testing ;
-run test_heron.cpp ;
-run test_arithmetic.cpp ;
-#run test_trig.cpp ;
+#run test_heron.cpp ;
+#run test_arithmetic.cpp ;
+run test_trig.cpp ;
#run test_conversions.cpp ;
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-07-17 18:09:29 EDT (Fri, 17 Jul 2009)
@@ -10,46 +10,43 @@
#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>
void test_all()
{
- typedef boost::numeric_adaptor::numeric_adaptor<Policy> num;
-
// big epsilon since we're testing functionalities, not robustness
double epsilon = 0.1;
- num n1 = 123.0;
- num n2 = 456.0;
- BOOST_CHECK_CLOSE((double)cos(n1), ::cos(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)sin(n1), ::sin(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)tan(n1), ::tan(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)atan(n1), ::atan(123.0), epsilon);
- BOOST_CHECK_CLOSE((double)hypot(n1, n2), ::hypot(123.0, 456.0), epsilon);
+ ValueType n1 = 123.0;
+ ValueType n2 = 456.0;
+ BOOST_CHECK_CLOSE((double)boost::cos(n1), ::cos(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::sin(n1), ::sin(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::tan(n1), ::tan(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::atan(n1), ::atan(123.0), epsilon);
+ BOOST_CHECK_CLOSE((double)boost::hypot(n1, n2), ::hypot(123.0, 456.0), epsilon);
}
int test_main(int, char*[])
{
- test_all<boost::numeric_adaptor::ieee_policy<float> >();
- test_all<boost::numeric_adaptor::ieee_policy<double> >();
- test_all<boost::numeric_adaptor::ieee_policy<long double> >();
+ test_all<float>();
+ test_all<double>();
+ test_all<long double>();
#if defined(HAVE_GMP)
- test_all<boost::numeric_adaptor::gmp_policy>();
+ test_all<boost::numeric_adaptor::gmp_value_type>();
#endif
#if defined(HAVE_CLN)
- test_all<boost::numeric_adaptor::cln_policy>();
+ test_all<boost::numeric_adaptor::cln_value_type>();
#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