Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74559 - in sandbox/big_number: boost/math boost/math/big_number libs/math/test
From: john_at_[hidden]
Date: 2011-09-25 07:11:19


Author: johnmaddock
Date: 2011-09-25 07:11:14 EDT (Sun, 25 Sep 2011)
New Revision: 74559
URL: http://svn.boost.org/trac/boost/changeset/74559

Log:
Fix coding errors undetected by MSVC, get everything compiling with GCC.
Text files modified:
   sandbox/big_number/boost/math/big_number.hpp | 12 ++++----
   sandbox/big_number/boost/math/big_number/big_number_base.hpp | 13 +++++---
   sandbox/big_number/boost/math/big_number/default_ops.hpp | 54 ++++++++++++++++++++--------------------
   sandbox/big_number/libs/math/test/Jamfile.v2 | 9 +++++
   sandbox/big_number/libs/math/test/test_arithmetic.cpp | 46 +++++++++++++++++++++++----------
   sandbox/big_number/libs/math/test/test_numeric_limits.cpp | 4 ++
   6 files changed, 85 insertions(+), 53 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-25 07:11:14 EDT (Sun, 25 Sep 2011)
@@ -128,7 +128,7 @@
       if(contains_self(e))
       {
          self_type temp(e);
- do_subtract(temp, typename detail_of<self_type>::type());
+ do_subtract(temp, typename self_type::tag_type());
       }
       else
       {
@@ -193,7 +193,7 @@
       if(contains_self(e))
       {
          self_type temp(e);
- do_modulus(temp, typename detail_of<self_type>::type());
+ do_modulus(temp, typename self_type::tag_type());
       }
       else
       {
@@ -280,7 +280,7 @@
       if(contains_self(e))
       {
          self_type temp(e);
- do_divide(detail::big_number_exp<detail::terminal, self_type>(temp), typename detail_of<self_type>::type());
+ do_divide(detail::big_number_exp<detail::terminal, self_type>(temp), typename self_type::tag_type());
       }
       else
       {
@@ -312,7 +312,7 @@
       if(contains_self(e) && !is_self(e))
       {
          self_type temp(e);
- do_bitwise_and(temp, typename detail_of<self_type>::type());
+ do_bitwise_and(temp, typename self_type::tag_type());
       }
       else
       {
@@ -344,7 +344,7 @@
       if(contains_self(e) && !is_self(e))
       {
          self_type temp(e);
- do_bitwise_or(temp, typename detail_of<self_type>::type());
+ do_bitwise_or(temp, typename self_type::tag_type());
       }
       else
       {
@@ -374,7 +374,7 @@
       if(contains_self(e))
       {
          self_type temp(e);
- do_bitwise_xor(temp, typename detail_of<self_type>::type());
+ do_bitwise_xor(temp, typename self_type::tag_type());
       }
       else
       {

Modified: sandbox/big_number/boost/math/big_number/big_number_base.hpp
==============================================================================
--- sandbox/big_number/boost/math/big_number/big_number_base.hpp (original)
+++ sandbox/big_number/boost/math/big_number/big_number_base.hpp 2011-09-25 07:11:14 EDT (Sun, 25 Sep 2011)
@@ -179,7 +179,10 @@
 };
 
 template <class T>
-void unmentionable_proc(){}
+struct unmentionable
+{
+ static void proc(){}
+};
 
 typedef void (*unmentionable_type)();
 
@@ -226,7 +229,7 @@
    operator unmentionable_type()const
    {
       result_type r(*this);
- return r ? unmentionable_proc<void> : 0;
+ return r ? &unmentionable<void>::proc : 0;
    }
 
 private:
@@ -248,7 +251,7 @@
 
    operator unmentionable_type()const
    {
- return arg ? unmentionable_proc<void> : 0;
+ return arg ? &unmentionable<void>::proc : 0;
    }
 
 private:
@@ -276,7 +279,7 @@
    operator unmentionable_type()const
    {
       result_type r(*this);
- return r ? unmentionable_proc<void> : 0;
+ return r ? &unmentionable<void>::proc : 0;
    }
 
    static const unsigned left_depth = left_type::depth + 1;
@@ -315,7 +318,7 @@
    operator unmentionable_type()const
    {
       result_type r(*this);
- return r ? unmentionable_proc<void> : 0;
+ return r ? &unmentionable<void>::proc : 0;
    }
 
    static const unsigned left_depth = left_type::depth + 1;

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-25 07:11:14 EDT (Sun, 25 Sep 2011)
@@ -501,10 +501,10 @@
       return policies::raise_rounding_error("boost::math::itrunc<%1%>(%1%)", 0, v, 0, pol).template convert_to<int>();
    return r.template convert_to<int>();
 }
-template <class T, class Policy>
-inline long ltrunc(const detail::big_number_exp<T>& v, const Policy& pol)
+template <class tag, class A1, class A2, class A3, class Policy>
+inline long ltrunc(const detail::big_number_exp<tag, A1, A2, A3>& v, const Policy& pol)
 {
- typedef typename detail::expression_type<T>::type number_type;
+ typedef typename detail::big_number_exp<tag, A1, A2, A3>::result_result number_type;
    number_type r = trunc(v, pol);
    if(fabs(r) > (std::numeric_limits<long>::max)())
       return policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, v, 0L, pol).template convert_to<long>();
@@ -519,10 +519,10 @@
    return r.template convert_to<long>();
 }
 #ifndef BOOST_NO_LONG_LONG
-template <class T, class Policy>
-inline long long lltrunc(const detail::big_number_exp<T>& v, const Policy& pol)
+template <class tag, class A1, class A2, class A3, class Policy>
+inline long long lltrunc(const detail::big_number_exp<tag, A1, A2, A3>& v, const Policy& pol)
 {
- typedef typename detail::expression_type<T>::type number_type;
+ typedef typename detail::big_number_exp<tag, A1, A2, A3>::result_result number_type;
    number_type r = trunc(v, pol);
    if(fabs(r) > (std::numeric_limits<long long>::max)())
       return policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, 0LL, pol).template convert_to<long long>();
@@ -537,10 +537,10 @@
    return r.template convert_to<long long>();
 }
 #endif
-template <class T, class Policy>
-inline int iround(const detail::big_number_exp<T>& v, const Policy& pol)
+template <class tag, class A1, class A2, class A3, class Policy>
+inline int iround(const detail::big_number_exp<tag, A1, A2, A3>& v, const Policy& pol)
 {
- typedef typename detail::expression_type<T>::type number_type;
+ typedef typename detail::big_number_exp<tag, A1, A2, A3>::result_result number_type;
    number_type r = round(v, pol);
    if(fabs(r) > (std::numeric_limits<int>::max)())
       return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0, pol).template convert_to<int>();
@@ -554,10 +554,10 @@
       return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0, pol).template convert_to<int>();
    return r.template convert_to<int>();
 }
-template <class T, class Policy>
-inline long lround(const detail::big_number_exp<T>& v, const Policy& pol)
+template <class tag, class A1, class A2, class A3, class Policy>
+inline long lround(const detail::big_number_exp<tag, A1, A2, A3>& v, const Policy& pol)
 {
- typedef typename detail::expression_type<T>::type number_type;
+ typedef typename detail::big_number_exp<tag, A1, A2, A3>::result_result number_type;
    number_type r = round(v, pol);
    if(fabs(r) > (std::numeric_limits<long>::max)())
       return policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", 0, v, 0L, pol).template convert_to<long>();
@@ -572,10 +572,10 @@
    return r.template convert_to<long>();
 }
 #ifndef BOOST_NO_LONG_LONG
-template <class T, class Policy>
-inline long long llround(const detail::big_number_exp<T>& v, const Policy& pol)
+template <class tag, class A1, class A2, class A3, class Policy>
+inline long long llround(const detail::big_number_exp<tag, A1, A2, A3>& v, const Policy& pol)
 {
- typedef typename detail::expression_type<T>::type number_type;
+ typedef typename detail::big_number_exp<tag, A1, A2, A3>::result_result number_type;
    number_type r = round(v, pol);
    if(fabs(r) > (std::numeric_limits<long long>::max)())
       return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0LL, pol).template convert_to<long long>();
@@ -656,14 +656,14 @@
 detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
- , big_number<Backend>\
+ , big_number<Backend> \
> \
 func(const big_number<Backend>& arg)\
 {\
     return detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
- , big_number<Backend>\
+ , big_number<Backend> \
>(\
         detail::BOOST_JOIN(func, _funct)<Backend>() \
       , arg \
@@ -734,15 +734,15 @@
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
   , detail::big_number_exp<tag, A1, A2, A3> \
- , big_number<Backend>\
->\
+ , big_number<Backend> \
+> \
 func(const detail::big_number_exp<tag, A1, A2, A3>& arg, const big_number<Backend>& a)\
 {\
     return detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
   , detail::big_number_exp<tag, A1, A2, A3> \
- , big_number<Backend>\
+ , big_number<Backend> \
>(\
         detail::BOOST_JOIN(func, _funct)<Backend>() \
       , arg,\
@@ -755,7 +755,7 @@
   , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::big_number_exp<tag, A1, A2, A3> >::type> \
   , detail::big_number_exp<tag, A1, A2, A3> \
   , detail::big_number_exp<tagb, A1b, A2b, A3b> \
->\
+> \
 func(const detail::big_number_exp<tag, A1, A2, A3>& arg, const detail::big_number_exp<tagb, A1b, A2b, A3b>& a)\
 {\
     return detail::big_number_exp<\
@@ -775,7 +775,7 @@
    detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
- , big_number<Backend>\
+ , big_number<Backend> \
   , Arithmetic\
> \
>::type \
@@ -784,7 +784,7 @@
     return detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
- , big_number<Backend>\
+ , big_number<Backend> \
   , Arithmetic\
>(\
         detail::BOOST_JOIN(func, _funct)<Backend>() \
@@ -837,7 +837,7 @@
   , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::big_number_exp<tag, A1, A2, A3> >::type> \
   , detail::big_number_exp<tag, A1, A2, A3> \
   , Arg2\
->\
+> \
 func(const detail::big_number_exp<tag, A1, A2, A3>& arg, Arg2 const& a)\
 {\
     return detail::big_number_exp<\
@@ -854,15 +854,15 @@
 detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
- , big_number<Backend>\
+ , big_number<Backend> \
   , Arg2\
->\
+> \
 func(const big_number<Backend>& arg, Arg2 const& a)\
 {\
     return detail::big_number_exp<\
     detail::function\
   , detail::BOOST_JOIN(func, _funct)<Backend> \
- , big_number<Backend>\
+ , big_number<Backend> \
   , Arg2\
>(\
         detail::BOOST_JOIN(func, _funct)<Backend>() \

Modified: sandbox/big_number/libs/math/test/Jamfile.v2
==============================================================================
--- sandbox/big_number/libs/math/test/Jamfile.v2 (original)
+++ sandbox/big_number/libs/math/test/Jamfile.v2 2011-09-25 07:11:14 EDT (Sun, 25 Sep 2011)
@@ -170,6 +170,7 @@
          [ check-target-builds ../config//has_mpfr : : <build>no ]
         : test_numeric_limits_mpfr_50 ;
 
+
 run test_numeric_limits.cpp $(E_FLOAT_SRC)
         : # command line
         : # input files
@@ -178,5 +179,11 @@
          [ check-target-builds ../config//has_e_float : : <build>no ]
         : test_numeric_limits_e_float ;
 
-
+run big_number_concept_check.cpp mpfr
+ : # command line
+ : # input files
+ : # requirements
+ <define>TEST_MPFR_50
+ [ check-target-builds ../config//has_mpfr : : <build>no ]
+ : big_number_concept_check_mpfr_50 ;
 

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-25 07:11:14 EDT (Sun, 25 Sep 2011)
@@ -53,8 +53,25 @@
       BOOST_LIGHTWEIGHT_TEST_OSTREAM << e.what() << std::endl;\
    }
 
-template <class Real, unsigned N>
-void test_integer_ops(const boost::mpl::int_<N>&){}
+bool isfloat(float){ return true; }
+bool isfloat(double){ return true; }
+bool isfloat(long double){ return true; }
+template <class T> bool isfloat(T){ return false; }
+
+#define BOOST_TEST_CLOSE(x, y, tol)\
+ if(x == 0){\
+ BOOST_TEST(y == 0); }\
+ else if(!isfloat(x)){\
+ BOOST_TEST(x == y); }\
+ else if((x != y) && (::fabsl(static_cast<long double>((x-y)/x)) > tol))\
+ {\
+ BOOST_ERROR("Expected tolerance was exceeded: ");\
+ BOOST_LIGHTWEIGHT_TEST_OSTREAM << std::setprecision(34) << "(x-y)/x = " << ::fabsl(static_cast<long double>((x-y)/x)) \
+ << " tolerance = " << tol << std::endl;\
+ }
+
+template <class Real, class T>
+void test_integer_ops(const T&){}
 
 template <class Real>
 void test_integer_ops(const boost::mpl::int_<boost::math::number_kind_integer>&)
@@ -249,8 +266,8 @@
    BOOST_TEST(abs(+a) == 20);
 }
 
-template <class Real, unsigned N>
-void test_real_ops(const boost::mpl::int_<N>&){}
+template <class Real, class T>
+void test_real_ops(const T&){}
 
 template <class Real>
 void test_real_ops(const boost::mpl::int_<boost::math::number_kind_floating_point>&)
@@ -365,10 +382,10 @@
    BOOST_TEST(n2 == Real(n2));
    BOOST_TEST(n3 == Real(n3));
    BOOST_TEST(n4 == Real(n4));
- BOOST_TEST(n1 == boost::lexical_cast<target_type>(Real(n1).str(0, boost::is_floating_point<Num>::value)));
- BOOST_TEST(n2 == boost::lexical_cast<target_type>(Real(n2).str(0, boost::is_floating_point<Num>::value)));
- BOOST_TEST(n3 == boost::lexical_cast<target_type>(Real(n3).str(0, boost::is_floating_point<Num>::value)));
- BOOST_TEST(n4 == boost::lexical_cast<target_type>(Real(n4).str(0, boost::is_floating_point<Num>::value)));
+ BOOST_TEST_CLOSE(n1, boost::lexical_cast<target_type>(Real(n1).str(0, boost::is_floating_point<Num>::value)), 3 * std::numeric_limits<Num>::epsilon());
+ BOOST_TEST_CLOSE(n2, boost::lexical_cast<target_type>(Real(n2).str(0, boost::is_floating_point<Num>::value)), std::numeric_limits<Num>::epsilon());
+ BOOST_TEST_CLOSE(n3, boost::lexical_cast<target_type>(Real(n3).str(0, boost::is_floating_point<Num>::value)), std::numeric_limits<Num>::epsilon());
+ BOOST_TEST_CLOSE(n4, boost::lexical_cast<target_type>(Real(n4).str(0, boost::is_floating_point<Num>::value)), std::numeric_limits<Num>::epsilon());
    // Assignment:
    Real r(0);
    BOOST_TEST(r != n1);
@@ -461,10 +478,11 @@
    BOOST_TEST(n2 == Real(n2));
    BOOST_TEST(n3 == Real(n3));
    BOOST_TEST(n4 == Real(n4));
- BOOST_TEST(n1 == boost::lexical_cast<target_type>(Real(n1).str(0, boost::is_floating_point<Num>::value)));
- BOOST_TEST(n2 == boost::lexical_cast<target_type>(Real(n2).str(0, boost::is_floating_point<Num>::value)));
- BOOST_TEST(n3 == boost::lexical_cast<target_type>(Real(n3).str(0, boost::is_floating_point<Num>::value)));
- BOOST_TEST(n4 == boost::lexical_cast<target_type>(Real(n4).str(0, boost::is_floating_point<Num>::value)));
+ std::cout << Real(n1).str(0, boost::is_floating_point<Num>::value) << std::endl;
+ BOOST_TEST_CLOSE(n1, boost::lexical_cast<target_type>(Real(n1).str(0, boost::is_floating_point<Num>::value)), 3 * std::numeric_limits<Num>::epsilon());
+ BOOST_TEST_CLOSE(n2, boost::lexical_cast<target_type>(Real(n2).str(0, boost::is_floating_point<Num>::value)), std::numeric_limits<Num>::epsilon());
+ BOOST_TEST_CLOSE(n3, boost::lexical_cast<target_type>(Real(n3).str(0, boost::is_floating_point<Num>::value)), std::numeric_limits<Num>::epsilon());
+ BOOST_TEST_CLOSE(n4, boost::lexical_cast<target_type>(Real(n4).str(0, boost::is_floating_point<Num>::value)), std::numeric_limits<Num>::epsilon());
    // Assignment:
    Real r(0);
    BOOST_TEST(r != n1);
@@ -538,11 +556,11 @@
    //
    // Integer only functions:
    //
- test_integer_ops<Real>(boost::math::number_category<Real>());
+ test_integer_ops<Real>(typename boost::math::number_category<Real>::type());
    //
    // Real number only functions:
    //
- test_real_ops<Real>(boost::math::number_category<Real>());
+ test_real_ops<Real>(typename boost::math::number_category<Real>::type());
    //
    // Test basic arithmetic:
    //

Modified: sandbox/big_number/libs/math/test/test_numeric_limits.cpp
==============================================================================
--- sandbox/big_number/libs/math/test/test_numeric_limits.cpp (original)
+++ sandbox/big_number/libs/math/test/test_numeric_limits.cpp 2011-09-25 07:11:14 EDT (Sun, 25 Sep 2011)
@@ -51,10 +51,14 @@
    PRINT(is_specialized);
    PRINT(min());
    PRINT(max());
+#ifndef BOOST_NO_NUMERIC_LIMITS_LOWEST
    PRINT(lowest());
+#endif
    PRINT(digits);
    PRINT(digits10);
+#ifndef BOOST_NO_NUMERIC_LIMITS_LOWEST
    PRINT(max_digits10);
+#endif
    PRINT(is_signed);
    PRINT(is_integer);
    PRINT(is_exact);


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