Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54461 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-06-28 05:24:54


Author: bruno.lalande
Date: 2009-06-28 05:24:53 EDT (Sun, 28 Jun 2009)
New Revision: 54461
URL: http://svn.boost.org/trac/boost/changeset/54461

Log:
Added a test for trigonometric functions, and added some missing functions in policies.
Added:
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp (contents, props changed)
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp | 10 ++++++++++
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp | 14 ++++++++++++++
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot | 1 +
   3 files changed, 25 insertions(+), 0 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-06-28 05:24:53 EDT (Sun, 28 Jun 2009)
@@ -70,6 +70,16 @@
         r = cln::sin(a);
     }
 
+ static inline void tan(value_type& r, value_type const& a)
+ {
+ r = cln::tan(a);
+ }
+
+ static inline void atan(value_type& r, value_type const& a)
+ {
+ r = cln::atan(a);
+ }
+
     static inline void hypot(value_type& r, value_type const& a, value_type const& b)
     {
         r = cln::sqrt(a * a + b * 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-06-28 05:24:53 EDT (Sun, 28 Jun 2009)
@@ -122,6 +122,20 @@
         mpf_set_d(r, std::sin(d));
     }
 
+ static inline void tan(value_type& r, value_type const& a)
+ {
+ // TAN is not available in GMP
+ long double d = mpf_get_d(a);
+ mpf_set_d(r, std::tan(d));
+ }
+
+ static inline void atan(value_type& r, value_type const& a)
+ {
+ // ATAN is not available in GMP
+ long double d = mpf_get_d(a);
+ mpf_set_d(r, std::atan(d));
+ }
+
     static inline void hypot(value_type& r, value_type const& a, value_type const& b)
     {
         mpf_mul(r, a, a);

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-06-28 05:24:53 EDT (Sun, 28 Jun 2009)
@@ -20,4 +20,5 @@
 
 run test_heron.cpp ;
 run test_arithmetic.cpp ;
+run test_trig.cpp ;
 run test_conversions.cpp ;

Added: sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_trig.cpp 2009-06-28 05:24:53 EDT (Sun, 28 Jun 2009)
@@ -0,0 +1,56 @@
+// Numeric Adaptor Library testing suite
+//
+// Copyright Barend Gehrels 2009, Geodan Holding B.V. Amsterdam, the Netherlands.
+// 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)
+
+
+#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>
+#endif
+
+#if defined(HAVE_CLN)
+# include <boost/numeric_adaptor/cln_policy.hpp>
+#endif
+
+
+template <typename Policy>
+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)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);
+}
+
+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> >();
+
+#if defined(HAVE_GMP)
+ test_all<boost::numeric_adaptor::gmp_policy>();
+#endif
+
+#if defined(HAVE_CLN)
+ test_all<boost::numeric_adaptor::cln_policy>();
+#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