Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74479 - in sandbox/big_number: boost/math boost/math/big_number boost/math/concepts libs/math/test
From: john_at_[hidden]
Date: 2011-09-20 08:36:25


Author: johnmaddock
Date: 2011-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
New Revision: 74479
URL: http://svn.boost.org/trac/boost/changeset/74479

Log:
Optimise comparison to zero.
Remove unnecessary static asserts - even floats are incrementable.
Fix some of the default function methods, and add fmod.
Add mpq comparison and conversion routines.
Add mpfr lanczos support.
Add std lib function support for big_number_architype.
Update comparison tests.
Text files modified:
   sandbox/big_number/boost/math/big_number.hpp | 7 +--
   sandbox/big_number/boost/math/big_number/default_ops.hpp | 25 ++++++++++++++-
   sandbox/big_number/boost/math/big_number/gmp.hpp | 22 +++++++++++++
   sandbox/big_number/boost/math/big_number/mpfr.hpp | 24 ++++++++++++++
   sandbox/big_number/boost/math/concepts/big_number_architypes.hpp | 65 ++++++++++++++++++++++++++++++++++++++++
   sandbox/big_number/libs/math/test/test_arithmetic.cpp | 24 ++++++++++++++
   6 files changed, 161 insertions(+), 6 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-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
@@ -224,7 +224,6 @@
    //
    big_number& operator++()
    {
- BOOST_STATIC_ASSERT_MSG(is_extended_integer<Backend>::value, "The increment operation is only valid for integer types");
       using big_num_default_ops::increment;
       increment(m_backend);
       return *this;
@@ -232,7 +231,6 @@
 
    big_number& operator--()
    {
- BOOST_STATIC_ASSERT_MSG(is_extended_integer<Backend>::value, "The increment operation is only valid for integer types");
       using big_num_default_ops::decrement;
       decrement(m_backend);
       return *this;
@@ -240,7 +238,6 @@
 
    big_number operator++(int)
    {
- BOOST_STATIC_ASSERT_MSG(is_extended_integer<Backend>::value, "The increment operation is only valid for integer types");
       using big_num_default_ops::increment;
       self_type temp(*this);
       increment(m_backend);
@@ -249,7 +246,6 @@
 
    big_number operator--(int)
    {
- BOOST_STATIC_ASSERT_MSG(is_extended_integer<Backend>::value, "The increment operation is only valid for integer types");
       using big_num_default_ops::decrement;
       self_type temp(*this);
       decrement(m_backend);
@@ -439,6 +435,8 @@
    template <class V>
    typename enable_if<is_arithmetic<V>, int>::type compare(const V& o)const
    {
+ if(o == 0)
+ return get_sign(m_backend);
       return m_backend.compare(canonical_value(o));
    }
    Backend& backend()
@@ -1380,6 +1378,7 @@
    static const Backend& canonical_value(const self_type& v){ return v.m_backend; }
    static const Backend& canonical_value(const self_type* v){ return v->m_backend; }
    static const Backend& canonical_value(self_type* v){ return v->m_backend; }
+ static const Backend& canonical_value(self_type& v){ return v.m_backend; }
    template <class V>
    static typename detail::canonical<V, Backend>::type canonical_value(const V& v){ return v; }
    static typename detail::canonical<std::string, Backend>::type canonical_value(const std::string& v){ return v.c_str(); }

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-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
@@ -328,7 +328,7 @@
 // Functions:
 //
 template <class T>
-void eval_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;
@@ -337,7 +337,7 @@
       result->negate();
 }
 template <class T>
-void eval_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;
@@ -351,6 +351,26 @@
 {
    return is_zero(arg) ? FP_ZERO : FP_NORMAL;
 }
+
+template <class T>
+inline void eval_fmod(T& result, const T& a, const T& b)
+{
+ if((&result == &a) || (&result == &b))
+ {
+ T temp;
+ eval_fmod(temp, a, b);
+ result = temp;
+ }
+ T n;
+ divide(result, a, b);
+ if(get_sign(a) < 0)
+ eval_ceil(n, result);
+ else
+ eval_floor(n, result);
+ multiply(n, b);
+ subtract(result, a, n);
+}
+
 //
 // These have to implemented by the backend, declared here so that our macro generated code compiles OK.
 //
@@ -828,6 +848,7 @@
 HETERO_BINARY_OP_FUNCTOR(ldexp, int)
 HETERO_BINARY_OP_FUNCTOR(frexp, int*)
 BINARY_OP_FUNCTOR(pow)
+BINARY_OP_FUNCTOR(fmod)
 
 #undef BINARY_OP_FUNCTOR
 #undef UNARY_OP_FUNCTOR

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-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
@@ -1225,6 +1225,14 @@
       d = v;
       return compare(d);
    }
+ int compare(unsigned long v)
+ {
+ return mpq_cmp_ui(m_data, v, 1);
+ }
+ int compare(long v)
+ {
+ return mpq_cmp_si(m_data, v, 1);
+ }
    mpq_t& data() { return m_data; }
    const mpq_t& data()const { return m_data; }
 protected:
@@ -1277,6 +1285,20 @@
    *result = mpq_get_d(val.data());
 }
 
+inline void convert_to(long* result, const gmp_rational& val)
+{
+ double r;
+ convert_to(&r, val);
+ *result = r;
+}
+
+inline void convert_to(unsigned long* result, const gmp_rational& val)
+{
+ double r;
+ convert_to(&r, val);
+ *result = r;
+}
+
 inline void eval_abs(gmp_rational& result, const gmp_rational& val)
 {
    mpq_abs(result.data(), val.data());

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-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
@@ -10,6 +10,7 @@
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/math/bindings/detail/big_lanczos.hpp>
 #include <mpfr.h>
 #include <cmath>
 #include <algorithm>
@@ -739,6 +740,29 @@
 typedef big_number<mpfr_real_backend<1000> > mpfr_real_1000;
 typedef big_number<mpfr_real_backend<0> > mpfr_real;
 
+namespace lanczos{
+
+template<unsigned Digits10, class Policy>
+struct lanczos<big_number<mpfr_real_backend<Digits10> >, Policy>
+{
+ typedef typename mpl::if_c<
+ Digits10 <= 36,
+ lanczos22UDT,
+ typename mpl::if_c<
+ Digits10 <= 50,
+ lanczos31UDT,
+ typename mpl::if_c<
+ Digits10 <= 110,
+ lanczos61UDT,
+ undefined_lanczos
+ >::type
+ >::type
+ >::type type;
+};
+
+} // namespace lanczos
+
+
 }} // namespaces
 
 namespace std{

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-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
@@ -188,6 +188,71 @@
    return boost::math::fpclassify(arg.m_value);
 }
 
+inline void eval_pow(big_number_backend_real_architype& result, const big_number_backend_real_architype& b, const big_number_backend_real_architype& e)
+{
+ result = std::pow(b.m_value, e.m_value);
+}
+
+inline void eval_pow(big_number_backend_real_architype& result, const big_number_backend_real_architype& b, int e)
+{
+ result = std::pow(b.m_value, e);
+}
+
+inline void eval_exp(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::exp(arg.m_value);
+}
+
+inline void eval_log(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::log(arg.m_value);
+}
+
+inline void eval_sin(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::sin(arg.m_value);
+}
+
+inline void eval_cos(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::cos(arg.m_value);
+}
+
+inline void eval_tan(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::tan(arg.m_value);
+}
+
+inline void eval_asin(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::asin(arg.m_value);
+}
+
+inline void eval_acos(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::acos(arg.m_value);
+}
+
+inline void eval_atan(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::atan(arg.m_value);
+}
+
+inline void eval_sinh(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::sinh(arg.m_value);
+}
+
+inline void eval_cosh(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::cosh(arg.m_value);
+}
+
+inline void eval_tanh(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg)
+{
+ result = std::tanh(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-09-20 08:36:22 EDT (Tue, 20 Sep 2011)
@@ -345,6 +345,18 @@
    Num n3 = 0;
    Num n4 = -20;
    Num n5 = -8;
+ BOOST_TEST((Real(n2) < 0) == true);
+ BOOST_TEST((Real(n2) <= 0) == true);
+ BOOST_TEST((Real(n2) > 0) == false);
+ BOOST_TEST((Real(n2) >= 0) == false);
+ BOOST_TEST((Real(n2) == 0) == false);
+ BOOST_TEST((Real(n2) != 0) == true);
+ BOOST_TEST((Real(n2) == n2) == true);
+ BOOST_TEST((Real(n2) != n2) == false);
+ BOOST_TEST((Real(n2) >= n2) == true);
+ BOOST_TEST((Real(n2) <= n2) == true);
+ BOOST_TEST((Real(n2) > n2) == false);
+ BOOST_TEST((Real(n2) < n2) == false);
    // Default construct:
    BOOST_TEST(Real(n1) == n1);
    BOOST_TEST(Real(n2) == n2);
@@ -425,6 +437,18 @@
    Num n3 = 0;
    Num n4 = 20;
    Num n5 = 8;
+ BOOST_TEST((Real(n2) < 0) == false);
+ BOOST_TEST((Real(n2) <= 0) == false);
+ BOOST_TEST((Real(n2) > 0) == true);
+ BOOST_TEST((Real(n2) >= 0) == true);
+ BOOST_TEST((Real(n2) == 0) == false);
+ BOOST_TEST((Real(n2) != 0) == true);
+ BOOST_TEST((Real(n2) == n2) == true);
+ BOOST_TEST((Real(n2) != n2) == false);
+ BOOST_TEST((Real(n2) >= n2) == true);
+ BOOST_TEST((Real(n2) <= n2) == true);
+ BOOST_TEST((Real(n2) > n2) == false);
+ BOOST_TEST((Real(n2) < n2) == false);
    // Default construct:
    BOOST_TEST(Real(n1) == n1);
    BOOST_TEST(Real(n2) == n2);


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