Boost logo

Boost-Commit :

From: john_at_[hidden]
Date: 2008-05-05 07:27:44


Author: johnmaddock
Date: 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
New Revision: 45128
URL: http://svn.boost.org/trac/boost/changeset/45128

Log:
Misc minor fixes.
Text files modified:
   sandbox/interval_math_toolkit/boost/math/bindings/interval.hpp | 10 +++---
   sandbox/interval_math_toolkit/boost/math/bindings/mpfr_interval.hpp | 2
   sandbox/interval_math_toolkit/boost/numeric/interval/detail/test_input.hpp | 10 +++---
   sandbox/interval_math_toolkit/boost/numeric/interval/interval.hpp | 7 ++++
   sandbox/interval_math_toolkit/boost/numeric/interval/rounded_arith.hpp | 35 +++++++++++++++++++++---
   sandbox/interval_math_toolkit/libs/math/test/mpfr_interval_concept_check.cpp | 6 ----
   sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2 | 51 ++++++++++++++++++------------------
   sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp | 55 ++++++++++++++++++++++++++++++++++-----
   8 files changed, 120 insertions(+), 56 deletions(-)

Modified: sandbox/interval_math_toolkit/boost/math/bindings/interval.hpp
==============================================================================
--- sandbox/interval_math_toolkit/boost/math/bindings/interval.hpp (original)
+++ sandbox/interval_math_toolkit/boost/math/bindings/interval.hpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -119,7 +119,7 @@
 template<class T, class Policies, class T2> inline
 bool operator<(const interval<T, Policies>& x, const T2& y)
 {
- if (boost::numeric::interval_lib::detail::test_input(x, y)) throw boost::numeric::interval_lib::comparison_error();
+ if (boost::numeric::interval_lib::detail::test_input(x, static_cast<T>(y))) throw boost::numeric::interval_lib::comparison_error();
   if(x.upper() < y)
      return true;
   if(x.lower() >= y)
@@ -130,7 +130,7 @@
 template<class T, class Policies, class T2> inline
 bool operator<(const T2& x, const interval<T, Policies>& y)
 {
- if (boost::numeric::interval_lib::detail::test_input(x, y)) throw boost::numeric::interval_lib::comparison_error();
+ if (boost::numeric::interval_lib::detail::test_input(static_cast<T>(x), y)) throw boost::numeric::interval_lib::comparison_error();
   if(x < y.lower())
      return true;
   if(x >= y.upper())
@@ -152,7 +152,7 @@
 template<class T, class Policies, class T2> inline
 bool operator<=(const interval<T, Policies>& x, const T2& y)
 {
- if (boost::numeric::interval_lib::detail::test_input(x, y)) throw boost::numeric::interval_lib::comparison_error();
+ if (boost::numeric::interval_lib::detail::test_input(x, static_cast<T>(y))) throw boost::numeric::interval_lib::comparison_error();
   if(x.upper() <= y)
      return true;
   if(x.lower() > y)
@@ -163,7 +163,7 @@
 template<class T, class Policies, class T2> inline
 bool operator<=(const T2& x, const interval<T, Policies>& y)
 {
- if (boost::numeric::interval_lib::detail::test_input(x, y)) throw boost::numeric::interval_lib::comparison_error();
+ if (boost::numeric::interval_lib::detail::test_input(static_cast<T>(x), y)) throw boost::numeric::interval_lib::comparison_error();
   if(x <= y.lower())
      return true;
   if(x > y.upper())
@@ -217,7 +217,7 @@
 template<class T, class Policies, class T2> inline
 bool operator==(const interval<T, Policies>& x, const T2& y)
 {
- if (boost::numeric::interval_lib::detail::test_input(x, y)) throw boost::numeric::interval_lib::comparison_error();
+ if (boost::numeric::interval_lib::detail::test_input(x, static_cast<T>(y))) throw boost::numeric::interval_lib::comparison_error();
   return x.upper() == y && x.lower() == y;
 }
 

Modified: sandbox/interval_math_toolkit/boost/math/bindings/mpfr_interval.hpp
==============================================================================
--- sandbox/interval_math_toolkit/boost/math/bindings/mpfr_interval.hpp (original)
+++ sandbox/interval_math_toolkit/boost/math/bindings/mpfr_interval.hpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -2187,7 +2187,7 @@
    result += log(zgh);
    result += tools::evaluate_polynomial(PD, x) / tools::evaluate_polynomial(P, x);
    result -= tools::evaluate_polynomial(QD, x) / tools::evaluate_polynomial(Q, x);
- result -= 1;
+ result -= mpfr_interval(1);
 
    return result;
 }

Modified: sandbox/interval_math_toolkit/boost/numeric/interval/detail/test_input.hpp
==============================================================================
--- sandbox/interval_math_toolkit/boost/numeric/interval/detail/test_input.hpp (original)
+++ sandbox/interval_math_toolkit/boost/numeric/interval/detail/test_input.hpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -44,14 +44,14 @@
          checking2::is_empty(y.lower(), y.upper());
 }
 
-template<class T2, class T, class Policies> inline
-bool test_input(const T2& x, const interval<T, Policies>& y) {
+template<class T, class Policies> inline
+bool test_input(const T& x, const interval<T, Policies>& y) {
   typedef typename Policies::checking checking;
- return checking::is_nan(static_cast<T>(x)) || checking::is_empty(y.lower(), y.upper());
+ return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper());
 }
 
-template<class T, class Policies, class T2> inline
-bool test_input(const interval<T, Policies>& x, const T2& y) {
+template<class T, class Policies> inline
+bool test_input(const interval<T, Policies>& x, const T& y) {
   typedef typename Policies::checking checking;
   return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y);
 }

Modified: sandbox/interval_math_toolkit/boost/numeric/interval/interval.hpp
==============================================================================
--- sandbox/interval_math_toolkit/boost/numeric/interval/interval.hpp (original)
+++ sandbox/interval_math_toolkit/boost/numeric/interval/interval.hpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -76,7 +76,12 @@
   interval& operator*= (const interval& r);
   interval& operator/= (const T& r);
   interval& operator/= (const interval& r);
-
+ //
+ // We need these additional overloads, in case we are converting
+ // from a type that is convertible to both type T *and* to interval<T>.
+ // The motivating test case is conversion from say 1.0 to interval<mpfr_class>
+ // in which case the operator overloads above are ambiguous.
+ //
   template <class U>
   interval& operator+= (const U& r)
   {

Modified: sandbox/interval_math_toolkit/boost/numeric/interval/rounded_arith.hpp
==============================================================================
--- sandbox/interval_math_toolkit/boost/numeric/interval/rounded_arith.hpp (original)
+++ sandbox/interval_math_toolkit/boost/numeric/interval/rounded_arith.hpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -15,6 +15,7 @@
 #include <boost/cstdint.hpp>
 #include <boost/type_traits/is_unsigned.hpp>
 #include <boost/type_traits/is_integral.hpp>
+#include <boost/type_traits/is_same.hpp>
 #include <boost/mpl/eval_if.hpp>
 #include <boost/mpl/and.hpp>
 #include <boost/mpl/identity.hpp>
@@ -97,13 +98,35 @@
 # define BOOST_UP(EXPR) return this->force_rounding(EXPR)
 # define BOOST_UP_NEG(EXPR) return -this->force_rounding(EXPR)
 private:
- // Downward conversion has two cases:
- template<class U> T conv_down(U const &v, const mpl::true_&)
+ // Downward conversion has five (!) cases:
+ template<class U> T conv_down(U const& v, const mpl::true_&, const mpl::false_&, const mpl::true_&)
    {
- // U is an integer smaller than boost::intmax_t:
+ // Conversion to float has to go via BOOST_DN otherwise it
+ // doesn't produce a valid interval on Intel:
       BOOST_DN(static_cast<T>(v));
    }
- template<class U> T conv_down(U const &v, const mpl::false_&)
+ template<class U> T conv_down(U const& v, const mpl::true_&, const mpl::true_&, const mpl::true_&)
+ {
+ // Conversion to float has to go via BOOST_DN otherwise it
+ // doesn't produce a valid interval on Intel:
+ BOOST_DN(static_cast<T>(v));
+ }
+ template<class U> T conv_down(U const &v, const mpl::true_&, const mpl::true_&, const mpl::false_&)
+ {
+ // U is an integer as wide as boost::intmax_t:
+ if((v > static_cast<U>(std::numeric_limits<boost::intmax_t>::max()))
+ || (v < static_cast<U>(std::numeric_limits<boost::intmax_t>::min())))
+ {
+ BOOST_DN(static_cast<T>(v));
+ }
+ BOOST_UP_NEG(static_cast<T>(-static_cast<boost::intmax_t>(v)));
+ }
+ template<class U> T conv_down(U const &v, const mpl::true_&, const mpl::false_&, const mpl::false_&)
+ {
+ // U is an integer smaller than boost::intmax_t:
+ BOOST_UP_NEG(static_cast<T>(-static_cast<boost::intmax_t>(v)));
+ }
+ template<class U> T conv_down(U const &v, const mpl::false_&, const mpl::false_&, const mpl::false_&)
    {
       // U is not an integer, so it had better be a signed type(!):
       BOOST_UP_NEG(-v);
@@ -112,7 +135,9 @@
   template<class U> T conv_down(U const &v)
   {
      typedef typename boost::is_integral<U>::type t1;
- return conv_down(v, t1());
+ typedef typename mpl::and_<t1, boost::is_unsigned<U>, mpl::bool_<sizeof(U) == sizeof(boost::intmax_t)> >::type t2;
+ typedef typename boost::is_same<T, float>::type t3;
+ return conv_down(v, t1(), t2(), t3());
   }
   template<class U> T conv_up (U const &v) { BOOST_UP(static_cast<T>(v)); }
   T add_down(const T& x, const T& y) { BOOST_UP_NEG((-x) - y); }

Modified: sandbox/interval_math_toolkit/libs/math/test/mpfr_interval_concept_check.cpp
==============================================================================
--- sandbox/interval_math_toolkit/libs/math/test/mpfr_interval_concept_check.cpp (original)
+++ sandbox/interval_math_toolkit/libs/math/test/mpfr_interval_concept_check.cpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -26,12 +26,6 @@
 
 int main()
 {
- BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<double>));
- //BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::numeric::interval<double> >));
    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::math::mpfr_interval>));
-
- boost::math::mpfr_interval v;
- v = 0.5f;
- v -= 0.5f;
 }
 

Modified: sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2
==============================================================================
--- sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2 (original)
+++ sandbox/interval_math_toolkit/libs/numeric/interval/test/Jamfile.v2 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -8,7 +8,6 @@
 
 project
   :
- source-location $(BOOST_ROOT)
   :
   requirements
     # Enable dynamic rounding on Tru64 (Alpha CPU).
@@ -21,30 +20,32 @@
 
 {
   test-suite numeric/interval :
- [ run libs/numeric/interval/test/add.cpp ]
- [ run libs/numeric/interval/test/det.cpp ]
- [ run libs/numeric/interval/test/fmod.cpp ]
- [ run libs/numeric/interval/test/mul.cpp ]
- [ run libs/numeric/interval/test/overflow.cpp ]
- [ run libs/numeric/interval/test/pi.cpp ]
- [ run libs/numeric/interval/test/pow.cpp ]
-
- [ run libs/numeric/interval/test/cmp.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/cmp_exn.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/cmp_exp.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/cmp_lex.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/cmp_set.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/cmp_tribool.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/test_float.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run libs/numeric/interval/test/integer.cpp
- ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run add.cpp ]
+ [ run det.cpp ]
+ [ run fmod.cpp ]
+ [ run mul.cpp ]
+ [ run overflow.cpp ]
+ [ run pi.cpp ]
+ [ run pow.cpp ]
+
+ [ run cmp.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run cmp_exn.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run cmp_exp.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run cmp_lex.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run cmp_set.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run cmp_tribool.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run test_float.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
+ [ run integer.cpp
+ /boost/boost_test_exec_monitor//boost_test_exec_monitor/<link>static ]
   ;
 }
 
+
+

Modified: sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp
==============================================================================
--- sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp (original)
+++ sandbox/interval_math_toolkit/libs/numeric/interval/test/integer.cpp 2008-05-05 07:27:43 EDT (Mon, 05 May 2008)
@@ -18,6 +18,18 @@
 
 typedef boost::numeric::interval<float> I;
 
+template <class T, class U>
+T force_to_nearest(U u)
+{
+ typedef boost::numeric::interval_lib::rounded_arith_std<T> controller;
+ typename controller::rounding_mode m;
+ controller::get_rounding_mode(m);
+ controller::to_nearest();
+ volatile T result = static_cast<T>(u);
+ controller::set_rounding_mode(m);
+ return result;
+}
+
 template <class I, class Int>
 void test_construct_from(I, Int, const char* name, const char* iname)
 {
@@ -27,25 +39,50 @@
    if((i & 1) == 0)
       --i;
    I inter(i);
- BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(static_cast<value_type>(i)));
- BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(static_cast<value_type>(i)));
- Int a = static_cast<Int>(inter.lower());
+ BOOST_CHECK(std::floor(inter.lower()) == std::ceil(inter.lower()));
+ BOOST_CHECK(std::floor(inter.upper()) == std::ceil(inter.upper()));
+ BOOST_CHECK(inter.lower() <= inter.upper());
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(force_to_nearest<value_type>(i)));
+ BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(force_to_nearest<value_type>(i)));
+ Int a = static_cast<Int>(std::floor(inter.lower()));
    BOOST_CHECK_PREDICATE(std::less_equal<Int>(), (a)(i));
- a = static_cast<Int>(inter.upper());
+ a = static_cast<Int>(std::ceil(inter.upper()));
    BOOST_CHECK_PREDICATE(std::greater_equal<Int>(), (a)(i));
    BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (width(inter) / median(inter)) (std::numeric_limits<value_type>::epsilon()));
    i = (std::numeric_limits<Int>::min)() / 2;
    if((i & 1) == 0)
       ++i;
    inter = I(i);
- BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(static_cast<value_type>(i)));
- BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(static_cast<value_type>(i)));
- a = static_cast<Int>(inter.lower());
+ BOOST_CHECK(std::floor(inter.lower()) == std::ceil(inter.lower()));
+ BOOST_CHECK(std::floor(inter.upper()) == std::ceil(inter.upper()));
+ BOOST_CHECK(inter.lower() <= inter.upper());
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(force_to_nearest<value_type>(i)));
+ BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(force_to_nearest<value_type>(i)));
+ a = static_cast<Int>(std::floor(inter.lower()));
    BOOST_CHECK_PREDICATE(std::less_equal<Int>(), (a)(i));
- a = static_cast<Int>(inter.upper());
+ a = static_cast<Int>(std::ceil(inter.upper()));
    BOOST_CHECK_PREDICATE(std::greater_equal<Int>(), (a)(i));
    if(median(inter) != 0)
       BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (width(inter) / median(inter)) (std::numeric_limits<value_type>::epsilon()));
+
+ i = (std::numeric_limits<Int>::max)();
+ if((i & 1) == 0)
+ --i;
+ inter = I(i);
+ BOOST_CHECK(std::floor(inter.lower()) == std::ceil(inter.lower()));
+ BOOST_CHECK(std::floor(inter.upper()) == std::ceil(inter.upper()));
+ BOOST_CHECK(inter.lower() <= inter.upper());
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(force_to_nearest<value_type>(i)));
+ BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(force_to_nearest<value_type>(i)));
+ i = (std::numeric_limits<Int>::min)();
+ if((i & 1) == 0)
+ ++i;
+ inter = I(i);
+ BOOST_CHECK(std::floor(inter.lower()) == std::ceil(inter.lower()));
+ BOOST_CHECK(std::floor(inter.upper()) == std::ceil(inter.upper()));
+ BOOST_CHECK(inter.lower() <= inter.upper());
+ BOOST_CHECK_PREDICATE(std::less_equal<value_type>(), (inter.lower())(force_to_nearest<value_type>(i)));
+ BOOST_CHECK_PREDICATE(std::greater_equal<value_type>(), (inter.upper())(force_to_nearest<value_type>(i)));
 }
 
 template <class I>
@@ -75,5 +112,7 @@
   test_construct(interval<float, policies<rounded_arith_opp<float>, checking_no_empty<float> > >(), "interval<float, policies<rounded_arith_opp<float>, checking_no_empty<float> > >");
   test_construct(interval<double, policies<rounded_arith_std<double>, checking_no_empty<double> > >(), "interval<double, policies<rounded_arith_std<double>, checking_no_empty<double> > >");
   test_construct(interval<double, policies<rounded_arith_opp<double>, checking_no_empty<double> > >(), "interval<double, policies<rounded_arith_opp<double>, checking_no_empty<double> > >");
+ test_construct(interval<long double, policies<rounded_arith_std<long double>, checking_no_empty<long double> > >(), "interval<long double, policies<rounded_arith_std<long double>, checking_no_empty<long double> > >");
+ test_construct(interval<long double, policies<rounded_arith_opp<long double>, checking_no_empty<long double> > >(), "interval<long double, policies<rounded_arith_opp<long double>, checking_no_empty<long double> > >");
   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