Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74166 - in sandbox/big_number: boost/math boost/math/big_number boost/math/concepts libs/math/test
From: john_at_[hidden]
Date: 2011-08-30 13:00:06


Author: johnmaddock
Date: 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
New Revision: 74166
URL: http://svn.boost.org/trac/boost/changeset/74166

Log:
Change function evaluation calling convention and naming.
Add integer-powers support.
Text files modified:
   sandbox/big_number/boost/math/big_number.hpp | 6 ++--
   sandbox/big_number/boost/math/big_number/default_ops.hpp | 33 ++++++++++++++++++-------------
   sandbox/big_number/boost/math/big_number/e_float.hpp | 9 ++++++-
   sandbox/big_number/boost/math/big_number/gmp.hpp | 42 ++++++++++++++++++++--------------------
   sandbox/big_number/boost/math/big_number/mpfr.hpp | 36 +++++++++++++++++-----------------
   sandbox/big_number/boost/math/concepts/big_number_architypes.hpp | 42 ++++++++++++++++++++++++++++++++++++++++
   sandbox/big_number/libs/math/test/test_arithmetic.cpp | 27 ++++++++++++++++++++++++
   7 files changed, 136 insertions(+), 59 deletions(-)

Modified: sandbox/big_number/boost/math/big_number.hpp
==============================================================================
--- sandbox/big_number/boost/math/big_number.hpp (original)
+++ sandbox/big_number/boost/math/big_number.hpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -979,13 +979,13 @@
    template <class F, class Exp>
    void do_assign_function_1(const F& f, const Exp& val, const proto::tag::terminal&)
    {
- f(&m_backend, canonical_value(proto::value(val)));
+ f(m_backend, canonical_value(proto::value(val)));
    }
    template <class F, class Exp, class Tag>
    void do_assign_function_1(const F& f, const Exp& val, const Tag&)
    {
       big_number t(val);
- f(&m_backend, t.backend());
+ f(m_backend, t.backend());
    }
    template <class Exp>
    void do_assign_function(const Exp& e, const mpl::long_<3>&)
@@ -999,7 +999,7 @@
    template <class F, class Exp1, class Exp2>
    void do_assign_function_2(const F& f, const Exp1& val1, const Exp2& val2, const proto::tag::terminal&, const proto::tag::terminal&)
    {
- f(&m_backend, canonical_value(proto::value(val1)), canonical_value(proto::value(val2)));
+ f(m_backend, canonical_value(proto::value(val1)), canonical_value(proto::value(val2)));
    }
 
    template <class Exp>

Modified: sandbox/big_number/boost/math/big_number/default_ops.hpp
==============================================================================
--- sandbox/big_number/boost/math/big_number/default_ops.hpp (original)
+++ sandbox/big_number/boost/math/big_number/default_ops.hpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -325,7 +325,7 @@
 // Functions:
 //
 template <class T>
-void abs(T* result, const T& arg)
+void eval_abs(T* result, const T& arg)
 {
    typedef typename T::signed_types type_list;
    typedef typename mpl::front<type_list>::type front;
@@ -334,7 +334,7 @@
       result->negate();
 }
 template <class T>
-void fabs(T* result, const T& arg)
+void eval_fabs(T* result, const T& arg)
 {
    typedef typename T::signed_types type_list;
    typedef typename mpl::front<type_list>::type front;
@@ -347,17 +347,21 @@
 // These have to implemented by the backend, declared here so that our macro generated code compiles OK.
 //
 template <class T>
-typename enable_if_c<sizeof(T) == 0>::type floor();
+typename enable_if_c<sizeof(T) == 0>::type eval_floor();
 template <class T>
-typename enable_if_c<sizeof(T) == 0>::type ceil();
+typename enable_if_c<sizeof(T) == 0>::type eval_ceil();
 template <class T>
-typename enable_if_c<sizeof(T) == 0>::type trunc();
+typename enable_if_c<sizeof(T) == 0>::type eval_trunc();
 template <class T>
-typename enable_if_c<sizeof(T) == 0>::type sqrt();
+typename enable_if_c<sizeof(T) == 0>::type eval_sqrt();
 template <class T>
-typename enable_if_c<sizeof(T) == 0>::type ldexp();
+typename enable_if_c<sizeof(T) == 0>::type eval_ldexp();
 template <class T>
-typename enable_if_c<sizeof(T) == 0>::type frexp();
+typename enable_if_c<sizeof(T) == 0>::type eval_frexp();
+//
+// These functions are implemented in separate files, but expanded inline here:
+//
+#include <boost/math/big_number/functions/pow.hpp>
 
 }
 
@@ -377,10 +381,10 @@
 template <class Backend>\
 struct BOOST_JOIN(func, _funct)\
 {\
- void operator()(Backend* result, const Backend& arg)const\
+ void operator()(Backend& result, const Backend& arg)const\
    {\
- using big_num_default_ops::func;\
- func(result, arg);\
+ using big_num_default_ops::BOOST_JOIN(eval_,func);\
+ BOOST_JOIN(eval_,func)(result, arg);\
    }\
 };\
 \
@@ -419,10 +423,10 @@
 struct BOOST_JOIN(func, _funct)\
 {\
    template <class A2>\
- void operator()(Backend* result, const Backend& arg, const A2& a)const\
+ void operator()(Backend& result, const Backend& arg, const A2& a)const\
    {\
- using big_num_default_ops::func;\
- func(result, arg, a);\
+ using big_num_default_ops:: BOOST_JOIN(eval_,func);\
+ BOOST_JOIN(eval_,func)(result, arg, a);\
    }\
 };\
 \
@@ -467,6 +471,7 @@
 
 BINARY_OP_FUNCTOR(ldexp)
 BINARY_OP_FUNCTOR(frexp)
+BINARY_OP_FUNCTOR(pow)
 
 #undef BINARY_OP_FUNCTOR
 #undef UNARY_OP_FUNCTOR

Modified: sandbox/big_number/boost/math/big_number/e_float.hpp
==============================================================================
--- sandbox/big_number/boost/math/big_number/e_float.hpp (original)
+++ sandbox/big_number/boost/math/big_number/e_float.hpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -34,9 +34,14 @@
    return result;
 }
 
-inline void abs(arithmetic_backend<efx::e_float>* result, const arithmetic_backend<efx::e_float>& arg)
+inline void eval_abs(arithmetic_backend<efx::e_float>& result, const arithmetic_backend<efx::e_float>& arg)
 {
- result->data() = ef::fabs(arg.data());
+ result.data() = ef::fabs(arg.data());
+}
+
+inline void eval_fabs(arithmetic_backend<efx::e_float>& result, const arithmetic_backend<efx::e_float>& arg)
+{
+ result.data() = ef::fabs(arg.data());
 }
 
 inline bool is_zero(const arithmetic_backend<efx::e_float>& val)

Modified: sandbox/big_number/boost/math/big_number/gmp.hpp
==============================================================================
--- sandbox/big_number/boost/math/big_number/gmp.hpp (original)
+++ sandbox/big_number/boost/math/big_number/gmp.hpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -573,58 +573,58 @@
 // Native non-member operations:
 //
 template <unsigned Digits10>
-inline void sqrt(gmp_real<Digits10>* result, const gmp_real<Digits10>& val)
+inline void eval_sqrt(gmp_real<Digits10>& result, const gmp_real<Digits10>& val)
 {
- mpf_sqrt(result->data(), val.data());
+ mpf_sqrt(result.data(), val.data());
 }
 
 template <unsigned Digits10>
-inline void abs(gmp_real<Digits10>* result, const gmp_real<Digits10>& val)
+inline void eval_abs(gmp_real<Digits10>& result, const gmp_real<Digits10>& val)
 {
- mpf_abs(result->data(), val.data());
+ mpf_abs(result.data(), val.data());
 }
 
 template <unsigned Digits10>
-inline void fabs(gmp_real<Digits10>* result, const gmp_real<Digits10>& val)
+inline void eval_fabs(gmp_real<Digits10>& result, const gmp_real<Digits10>& val)
 {
- mpf_abs(result->data(), val.data());
+ mpf_abs(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void ceil(gmp_real<Digits10>* result, const gmp_real<Digits10>& val)
+inline void eval_ceil(gmp_real<Digits10>& result, const gmp_real<Digits10>& val)
 {
- mpf_ceil(result->data(), val.data());
+ mpf_ceil(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void floor(gmp_real<Digits10>* result, const gmp_real<Digits10>& val)
+inline void eval_floor(gmp_real<Digits10>& result, const gmp_real<Digits10>& val)
 {
- mpf_floor(result->data(), val.data());
+ mpf_floor(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void trunc(gmp_real<Digits10>* result, const gmp_real<Digits10>& val)
+inline void eval_trunc(gmp_real<Digits10>& result, const gmp_real<Digits10>& val)
 {
- mpf_trunc(result->data(), val.data());
+ mpf_trunc(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void ldexp(gmp_real<Digits10>* result, const gmp_real<Digits10>& val, long e)
+inline void eval_ldexp(gmp_real<Digits10>& result, const gmp_real<Digits10>& val, long e)
 {
    if(e > 0)
- mpf_mul_2exp(result->data(), val.data(), e);
+ mpf_mul_2exp(result.data(), val.data(), e);
    else if(e < 0)
- mpf_div_2exp(result->data(), val.data(), -e);
+ mpf_div_2exp(result.data(), val.data(), -e);
 }
 template <unsigned Digits10>
-inline void frexp(gmp_real<Digits10>* result, const gmp_real<Digits10>& val, int* e)
+inline void eval_frexp(gmp_real<Digits10>& result, const gmp_real<Digits10>& val, int* e)
 {
    long v;
    mpf_get_d_2exp(&v, val.data());
    *e = v;
- return ldexp(result, val, -v);
+ eval_ldexp(result, val, -v);
 }
 template <unsigned Digits10>
-inline void frexp(gmp_real<Digits10>* result, const gmp_real<Digits10>& val, long* e)
+inline void eval_frexp(gmp_real<Digits10>& result, const gmp_real<Digits10>& val, long* e)
 {
    mpf_get_d_2exp(e, val.data());
- return ldexp(result, val, -*e);
+ eval_ldexp(result, val, -*e);
 }
 
 struct gmp_int
@@ -1069,9 +1069,9 @@
    *result = mpz_get_d(val.data());
 }
 
-inline void abs(gmp_int* result, const gmp_int& val)
+inline void eval_abs(gmp_int& result, const gmp_int& val)
 {
- mpz_abs(result->data(), val.data());
+ mpz_abs(result.data(), val.data());
 }
 
 template<>

Modified: sandbox/big_number/boost/math/big_number/mpfr.hpp
==============================================================================
--- sandbox/big_number/boost/math/big_number/mpfr.hpp (original)
+++ sandbox/big_number/boost/math/big_number/mpfr.hpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -588,55 +588,55 @@
 // Native non-member operations:
 //
 template <unsigned Digits10>
-inline void sqrt(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val)
+inline void eval_sqrt(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val)
 {
- mpfr_sqrt(result->data(), val.data(), MPFR_RNDN);
+ mpfr_sqrt(result.data(), val.data(), MPFR_RNDN);
 }
 
 template <unsigned Digits10>
-inline void abs(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val)
+inline void eval_abs(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val)
 {
- mpfr_abs(result->data(), val.data(), MPFR_RNDN);
+ mpfr_abs(result.data(), val.data(), MPFR_RNDN);
 }
 
 template <unsigned Digits10>
-inline void fabs(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val)
+inline void eval_fabs(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val)
 {
- mpfr_abs(result->data(), val.data(), MPFR_RNDN);
+ mpfr_abs(result.data(), val.data(), MPFR_RNDN);
 }
 template <unsigned Digits10>
-inline void ceil(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val)
+inline void eval_ceil(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val)
 {
- mpfr_ceil(result->data(), val.data());
+ mpfr_ceil(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void floor(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val)
+inline void eval_floor(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val)
 {
- mpfr_floor(result->data(), val.data());
+ mpfr_floor(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void trunc(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val)
+inline void eval_trunc(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val)
 {
- mpfr_trunc(result->data(), val.data());
+ mpfr_trunc(result.data(), val.data());
 }
 template <unsigned Digits10>
-inline void ldexp(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val, long e)
+inline void eval_ldexp(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val, long e)
 {
    if(e > 0)
- mpfr_mul_2exp(result->data(), val.data(), e, MPFR_RNDN);
+ mpfr_mul_2exp(result.data(), val.data(), e, MPFR_RNDN);
    else if(e < 0)
- mpfr_div_2exp(result->data(), val.data(), -e, MPFR_RNDN);
+ mpfr_div_2exp(result.data(), val.data(), -e, MPFR_RNDN);
 }
 template <unsigned Digits10>
-inline void frexp(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val, int* e)
+inline void eval_frexp(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val, int* e)
 {
    long v;
    mpfr_get_d_2exp(&v, val.data(), MPFR_RNDN);
    *e = v;
- return ldexp(result, val, -v);
+ ldexp(result, val, -v);
 }
 template <unsigned Digits10>
-inline void frexp(mpfr_real_backend<Digits10>* result, const mpfr_real_backend<Digits10>& val, long* e)
+inline void eval_frexp(mpfr_real_backend<Digits10>& result, const mpfr_real_backend<Digits10>& val, long* e)
 {
    mpfr_get_d_2exp(e, val.data(), MPFR_RNDN);
    return ldexp(result, val, -*e);

Modified: sandbox/big_number/boost/math/concepts/big_number_architypes.hpp
==============================================================================
--- sandbox/big_number/boost/math/concepts/big_number_architypes.hpp (original)
+++ sandbox/big_number/boost/math/concepts/big_number_architypes.hpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -8,9 +8,11 @@
 
 #include <iostream>
 #include <iomanip>
+#include <cmath>
 #include <boost/cstdint.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/math/big_number.hpp>
+#include <boost/math/special_functions/trunc.hpp>
 
 namespace boost{
 namespace math{
@@ -141,6 +143,46 @@
    result.m_value /= o.m_value;
 }
 
+inline void eval_frexp(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg, int* exp)
+{
+ result = std::frexp(arg.m_value, exp);
+}
+
+inline void eval_ldexp(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg, int exp)
+{
+ result = std::ldexp(arg.m_value, exp);
+}
+
+inline void eval_floor(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::floor(arg.m_value);
+}
+
+inline void eval_ceil(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::ceil(arg.m_value);
+}
+
+inline void eval_trunc(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = boost::math::trunc(arg.m_value);
+}
+
+inline void eval_sqrt(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::sqrt(arg.m_value);
+}
+
+inline void eval_abs(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::abs(arg.m_value);
+}
+
+inline void eval_fabs(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::fabs(arg.m_value);
+}
+
 typedef boost::math::big_number<big_number_backend_real_architype> big_number_real_architype;
 
 }}} // namespaces

Modified: sandbox/big_number/libs/math/test/test_arithmetic.cpp
==============================================================================
--- sandbox/big_number/libs/math/test/test_arithmetic.cpp (original)
+++ sandbox/big_number/libs/math/test/test_arithmetic.cpp 2011-08-30 13:00:05 EDT (Tue, 30 Aug 2011)
@@ -4,6 +4,7 @@
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
 
 #include <boost/detail/lightweight_test.hpp>
+#include <boost/math/special_functions/pow.hpp>
 
 #if !defined(TEST_MPF50) && !defined(TEST_MPF) && !defined(TEST_BACKEND) && !defined(TEST_MPZ) && !defined(TEST_E_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPFR_50)
 # define TEST_MPF50
@@ -254,7 +255,7 @@
 template <class Real>
 void test_real_ops(const boost::mpl::true_&)
 {
-#if defined(TEST_MPF) || defined(TEST_MPF_50)
+#if defined(TEST_MPF) || defined(TEST_MPF_50) || defined(TEST_BACKEND)
    BOOST_TEST(abs(Real(2)) == 2);
    BOOST_TEST(abs(Real(-2)) == 2);
    BOOST_TEST(fabs(Real(2)) == 2);
@@ -280,6 +281,30 @@
    r = frexp(v, &exp);
    BOOST_TEST(r == 0.5);
    BOOST_TEST(exp == -8);
+ //
+ // pow and exp:
+ //
+ v = 3.25;
+ r = pow(v, 0);
+ BOOST_TEST(r == 1);
+ r = pow(v, 1);
+ BOOST_TEST(r == 3.25);
+ r = pow(v, 2);
+ BOOST_TEST(r == boost::math::pow<2>(3.25));
+ r = pow(v, 3);
+ BOOST_TEST(r == boost::math::pow<3>(3.25));
+ r = pow(v, 4);
+ BOOST_TEST(r == boost::math::pow<4>(3.25));
+ r = pow(v, 5);
+ BOOST_TEST(r == boost::math::pow<5>(3.25));
+ r = pow(v, 6);
+ BOOST_TEST(r == boost::math::pow<6>(3.25));
+ r = pow(v, 25);
+ BOOST_TEST(r == boost::math::pow<25>(Real(3.25)));
+ /*
+ r = pow(v, 56);
+ BOOST_TEST(r == boost::math::pow<56>(Real(3.25)));
+ */
 #endif
 }
 


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