Boost logo

Boost-Commit :

From: john_at_[hidden]
Date: 2008-04-20 06:58:21


Author: johnmaddock
Date: 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
New Revision: 44612
URL: http://svn.boost.org/trac/boost/changeset/44612

Log:
Moved real_concept and std_real_concept overloads of the rounding and truncation functions into the same namespace as the classes so that they can be found via ADL.
Updated the tests to cope with the change.
Updated library configuration to cope with the change.
Made sure that the rounding and truncation functions are all correctly forward declared.
Added:
   trunk/boost/math/special_functions/detail/round_fwd.hpp (contents, props changed)
Text files modified:
   trunk/boost/math/concepts/real_concept.hpp | 112 +++++++++++--------------------
   trunk/boost/math/concepts/std_real_concept.hpp | 142 ++++++++++++++++++++--------------------
   trunk/boost/math/special_functions/math_fwd.hpp | 39 +++-------
   trunk/boost/math/tools/config.hpp | 10 ++
   trunk/libs/math/test/compile_test/instantiate.hpp | 30 +++++---
   5 files changed, 152 insertions(+), 181 deletions(-)

Modified: trunk/boost/math/concepts/real_concept.hpp
==============================================================================
--- trunk/boost/math/concepts/real_concept.hpp (original)
+++ trunk/boost/math/concepts/real_concept.hpp 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
@@ -237,6 +237,47 @@
 inline real_concept tanh(real_concept a)
 { return std::tanh(a.value()); }
 
+//
+// Conversion and truncation routines:
+//
+template <class Policy>
+inline int iround(const concepts::real_concept& v, const Policy& pol)
+{ return boost::math::iround(v.value(), pol); }
+inline int iround(const concepts::real_concept& v)
+{ return boost::math::iround(v.value(), policies::policy<>()); }
+template <class Policy>
+inline long lround(const concepts::real_concept& v, const Policy& pol)
+{ return boost::math::lround(v.value(), pol); }
+inline long lround(const concepts::real_concept& v)
+{ return boost::math::lround(v.value(), policies::policy<>()); }
+
+#ifdef BOOST_HAS_LONG_LONG
+template <class Policy>
+inline long long llround(const concepts::real_concept& v, const Policy& pol)
+{ return boost::math::llround(v.value(), pol); }
+inline long long llround(const concepts::real_concept& v)
+{ return boost::math::llround(v.value(), policies::policy<>()); }
+#endif
+
+template <class Policy>
+inline int itrunc(const concepts::real_concept& v, const Policy& pol)
+{ return boost::math::itrunc(v.value(), pol); }
+inline int itrunc(const concepts::real_concept& v)
+{ return boost::math::itrunc(v.value(), policies::policy<>()); }
+template <class Policy>
+inline long ltrunc(const concepts::real_concept& v, const Policy& pol)
+{ return boost::math::ltrunc(v.value(), pol); }
+inline long ltrunc(const concepts::real_concept& v)
+{ return boost::math::ltrunc(v.value(), policies::policy<>()); }
+
+#ifdef BOOST_HAS_LONG_LONG
+template <class Policy>
+inline long long lltrunc(const concepts::real_concept& v, const Policy& pol)
+{ return boost::math::lltrunc(v.value(), pol); }
+inline long long lltrunc(const concepts::real_concept& v)
+{ return boost::math::lltrunc(v.value(), policies::policy<>()); }
+#endif
+
 // Streaming:
 template <class charT, class traits>
 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const real_concept& a)
@@ -324,77 +365,6 @@
 
 } // namespace tools
 
-//
-// Conversion and truncation routines:
-//
-template <class Policy>
-inline int iround(const concepts::real_concept& v, const Policy& pol)
-{
- return iround(v.value(), pol);
-}
-inline int iround(const concepts::real_concept& v)
-{
- return iround(v.value(), policies::policy<>());
-}
-
-template <class Policy>
-inline long lround(const concepts::real_concept& v, const Policy& pol)
-{
- return lround(v.value(), pol);
-}
-inline long lround(const concepts::real_concept& v)
-{
- return lround(v.value(), policies::policy<>());
-}
-
-#ifdef BOOST_HAS_LONG_LONG
-
-template <class Policy>
-inline long long llround(const concepts::real_concept& v, const Policy& pol)
-{
- return llround(v.value(), pol);
-}
-inline long long llround(const concepts::real_concept& v)
-{
- return llround(v.value(), policies::policy<>());
-}
-
-#endif
-
-template <class Policy>
-inline int itrunc(const concepts::real_concept& v, const Policy& pol)
-{
- return itrunc(v.value(), pol);
-}
-inline int itrunc(const concepts::real_concept& v)
-{
- return itrunc(v.value(), policies::policy<>());
-}
-
-template <class Policy>
-inline long ltrunc(const concepts::real_concept& v, const Policy& pol)
-{
- return ltrunc(v.value(), pol);
-}
-inline long ltrunc(const concepts::real_concept& v)
-{
- return ltrunc(v.value(), policies::policy<>());
-}
-
-#ifdef BOOST_HAS_LONG_LONG
-
-template <class Policy>
-inline long long lltrunc(const concepts::real_concept& v, const Policy& pol)
-{
- return lltrunc(v.value(), pol);
-}
-inline long long lltrunc(const concepts::real_concept& v)
-{
- return lltrunc(v.value(), policies::policy<>());
-}
-
-#endif
-
 #if defined(__SGI_STL_PORT)
 //
 // We shouldn't really need these type casts any more, but there are some

Modified: trunk/boost/math/concepts/std_real_concept.hpp
==============================================================================
--- trunk/boost/math/concepts/std_real_concept.hpp (original)
+++ trunk/boost/math/concepts/std_real_concept.hpp 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
@@ -223,86 +223,27 @@
 
 namespace boost{ namespace math{ namespace concepts{
 
-// Streaming:
-template <class charT, class traits>
-inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const std_real_concept& a)
-{
- return os << a.value();
-}
-template <class charT, class traits>
-inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, std_real_concept& a)
-{
- std_real_concept_base_type v;
- is >> v;
- a = v;
- return is;
-}
-
-} // namespace concepts
-
-namespace tools
-{
-
-template <>
-inline concepts::std_real_concept max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
-{
- return max_value<concepts::std_real_concept_base_type>();
-}
-
-template <>
-inline concepts::std_real_concept min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
-{
- return min_value<concepts::std_real_concept_base_type>();
-}
-
-template <>
-inline concepts::std_real_concept log_max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
-{
- return log_max_value<concepts::std_real_concept_base_type>();
-}
-
-template <>
-inline concepts::std_real_concept log_min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
-{
- return log_min_value<concepts::std_real_concept_base_type>();
-}
-
-template <>
-inline concepts::std_real_concept epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
-{
- return tools::epsilon<concepts::std_real_concept_base_type>();
-}
-
-template <>
-inline int digits<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
-{ // Assume number of significand bits is same as std_real_concept_base_type,
- // unless std::numeric_limits<T>::is_specialized to provide digits.
- return digits<concepts::std_real_concept_base_type>();
-}
-
-} // namespace tools
-
 //
 // Conversion and truncation routines:
 //
 template <class Policy>
 inline int iround(const concepts::std_real_concept& v, const Policy& pol)
 {
- return iround(v.value(), pol);
+ return boost::math::iround(v.value(), pol);
 }
 inline int iround(const concepts::std_real_concept& v)
 {
- return iround(v.value(), policies::policy<>());
+ return boost::math::iround(v.value(), policies::policy<>());
 }
 
 template <class Policy>
 inline long lround(const concepts::std_real_concept& v, const Policy& pol)
 {
- return lround(v.value(), pol);
+ return boost::math::lround(v.value(), pol);
 }
 inline long lround(const concepts::std_real_concept& v)
 {
- return lround(v.value(), policies::policy<>());
+ return boost::math::lround(v.value(), policies::policy<>());
 }
 
 #ifdef BOOST_HAS_LONG_LONG
@@ -310,11 +251,11 @@
 template <class Policy>
 inline long long llround(const concepts::std_real_concept& v, const Policy& pol)
 {
- return llround(v.value(), pol);
+ return boost::math::llround(v.value(), pol);
 }
 inline long long llround(const concepts::std_real_concept& v)
 {
- return llround(v.value(), policies::policy<>());
+ return boost::math::llround(v.value(), policies::policy<>());
 }
 
 #endif
@@ -322,21 +263,21 @@
 template <class Policy>
 inline int itrunc(const concepts::std_real_concept& v, const Policy& pol)
 {
- return itrunc(v.value(), pol);
+ return boost::math::itrunc(v.value(), pol);
 }
 inline int itrunc(const concepts::std_real_concept& v)
 {
- return itrunc(v.value(), policies::policy<>());
+ return boost::math::itrunc(v.value(), policies::policy<>());
 }
 
 template <class Policy>
 inline long ltrunc(const concepts::std_real_concept& v, const Policy& pol)
 {
- return ltrunc(v.value(), pol);
+ return boost::math::ltrunc(v.value(), pol);
 }
 inline long ltrunc(const concepts::std_real_concept& v)
 {
- return ltrunc(v.value(), policies::policy<>());
+ return boost::math::ltrunc(v.value(), policies::policy<>());
 }
 
 #ifdef BOOST_HAS_LONG_LONG
@@ -344,15 +285,74 @@
 template <class Policy>
 inline long long lltrunc(const concepts::std_real_concept& v, const Policy& pol)
 {
- return lltrunc(v.value(), pol);
+ return boost::math::lltrunc(v.value(), pol);
 }
 inline long long lltrunc(const concepts::std_real_concept& v)
 {
- return lltrunc(v.value(), policies::policy<>());
+ return boost::math::lltrunc(v.value(), policies::policy<>());
 }
 
 #endif
 
+// Streaming:
+template <class charT, class traits>
+inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const std_real_concept& a)
+{
+ return os << a.value();
+}
+template <class charT, class traits>
+inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, std_real_concept& a)
+{
+ std_real_concept_base_type v;
+ is >> v;
+ a = v;
+ return is;
+}
+
+} // namespace concepts
+
+namespace tools
+{
+
+template <>
+inline concepts::std_real_concept max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{
+ return max_value<concepts::std_real_concept_base_type>();
+}
+
+template <>
+inline concepts::std_real_concept min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{
+ return min_value<concepts::std_real_concept_base_type>();
+}
+
+template <>
+inline concepts::std_real_concept log_max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{
+ return log_max_value<concepts::std_real_concept_base_type>();
+}
+
+template <>
+inline concepts::std_real_concept log_min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{
+ return log_min_value<concepts::std_real_concept_base_type>();
+}
+
+template <>
+inline concepts::std_real_concept epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{
+ return tools::epsilon<concepts::std_real_concept_base_type>();
+}
+
+template <>
+inline int digits<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
+{ // Assume number of significand bits is same as std_real_concept_base_type,
+ // unless std::numeric_limits<T>::is_specialized to provide digits.
+ return digits<concepts::std_real_concept_base_type>();
+}
+
+} // namespace tools
+
 } // namespace math
 } // namespace boost
 

Added: trunk/boost/math/special_functions/detail/round_fwd.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/math/special_functions/detail/round_fwd.hpp 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
@@ -0,0 +1,80 @@
+// Copyright John Maddock 2008.
+
+// Use, modification and distribution are 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)
+
+#ifndef BOOST_MATH_SPECIAL_ROUND_FWD_HPP
+#define BOOST_MATH_SPECIAL_ROUND_FWD_HPP
+
+#include <boost/config.hpp>
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+namespace boost
+{
+ namespace math
+ {
+
+ template <class T, class Policy>
+ T trunc(const T& v, const Policy& pol);
+ template <class T>
+ T trunc(const T& v);
+ template <class T, class Policy>
+ int itrunc(const T& v, const Policy& pol);
+ template <class T>
+ int itrunc(const T& v);
+ template <class T, class Policy>
+ long ltrunc(const T& v, const Policy& pol);
+ template <class T>
+ long ltrunc(const T& v);
+#ifdef BOOST_HAS_LONG_LONG
+ template <class T, class Policy>
+ long long lltrunc(const T& v, const Policy& pol);
+ template <class T>
+ long long lltrunc(const T& v);
+#endif
+ template <class T, class Policy>
+ T round(const T& v, const Policy& pol);
+ template <class T>
+ T round(const T& v);
+ template <class T, class Policy>
+ int iround(const T& v, const Policy& pol);
+ template <class T>
+ int iround(const T& v);
+ template <class T, class Policy>
+ long lround(const T& v, const Policy& pol);
+ template <class T>
+ long lround(const T& v);
+#ifdef BOOST_HAS_LONG_LONG
+ template <class T, class Policy>
+ long long llround(const T& v, const Policy& pol);
+ template <class T>
+ long long llround(const T& v);
+#endif
+ template <class T, class Policy>
+ T modf(const T& v, T* ipart, const Policy& pol);
+ template <class T>
+ T modf(const T& v, T* ipart);
+ template <class T, class Policy>
+ T modf(const T& v, int* ipart, const Policy& pol);
+ template <class T>
+ T modf(const T& v, int* ipart);
+ template <class T, class Policy>
+ T modf(const T& v, long* ipart, const Policy& pol);
+ template <class T>
+ T modf(const T& v, long* ipart);
+#ifdef BOOST_HAS_LONG_LONG
+ template <class T, class Policy>
+ T modf(const T& v, long long* ipart, const Policy& pol);
+ template <class T>
+ T modf(const T& v, long long* ipart);
+#endif
+
+ }
+}
+#endif // BOOST_MATH_SPECIAL_ROUND_FWD_HPP
+

Modified: trunk/boost/math/special_functions/math_fwd.hpp
==============================================================================
--- trunk/boost/math/special_functions/math_fwd.hpp (original)
+++ trunk/boost/math/special_functions/math_fwd.hpp 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
@@ -23,6 +23,7 @@
 #pragma once
 #endif
 
+#include <boost/math/special_functions/detail/round_fwd.hpp>
 #include <boost/math/tools/promotion.hpp> // for argument promotion.
 #include <boost/math/policies/policy.hpp>
 #include <boost/mpl/comparison.hpp>
@@ -656,20 +657,6 @@
    template <class T>
    typename tools::promote_args<T>::type zeta(T s);
 
- template <class T, class Policy>
- T trunc(const T& v, const Policy& pol);
- template <class T>
- T trunc(const T& v);
- template <class T, class Policy>
- int itrunc(const T& v, const Policy& pol);
- template <class T>
- int itrunc(const T& v);
- template <class T, class Policy>
- long ltrunc(const T& v, const Policy& pol);
- template <class T>
- long ltrunc(const T& v);
-
-
     } // namespace math
 } // namespace boost
 
@@ -677,13 +664,13 @@
 #define BOOST_MATH_DETAIL_LL_FUNC(Policy)\
    \
    template <class T>\
- inline T modf(const T& v, long long* ipart){ return boost::math::modf(v, ipart, Policy()); }\
+ inline T modf(const T& v, long long* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\
    \
    template <class T>\
- inline long long lltrunc(const T& v){ return boost::math::lltrunc(v, Policy()); }\
+ inline long long lltrunc(const T& v){ using boost::math::lltrunc; return lltrunc(v, Policy()); }\
    \
    template <class T>\
- inline long long llround(const T& v){ return boost::math::llround(v, Policy()); }\
+ inline long long llround(const T& v){ using boost::math::llround; return llround(v, Policy()); }\
 
 #else
 #define BOOST_MATH_DETAIL_LL_FUNC(Policy)
@@ -988,31 +975,31 @@
    inline typename boost::math::tools::promote_args<T>::type zeta(T s){ return boost::math::zeta(s, Policy()); }\
    \
    template <class T>\
- inline T round(const T& v){ return boost::math::round(v, Policy()); }\
+ inline T round(const T& v){ using boost::math::round; return round(v, Policy()); }\
    \
    template <class T>\
- inline int iround(const T& v){ return boost::math::iround(v, Policy()); }\
+ inline int iround(const T& v){ using boost::math::iround; return iround(v, Policy()); }\
    \
    template <class T>\
- inline long lround(const T& v){ return boost::math::lround(v, Policy()); }\
+ inline long lround(const T& v){ using boost::math::lround; return lround(v, Policy()); }\
    \
    template <class T>\
- inline T trunc(const T& v){ return boost::math::trunc(v, Policy()); }\
+ inline T trunc(const T& v){ using boost::math::trunc; return trunc(v, Policy()); }\
    \
    template <class T>\
- inline int itrunc(const T& v){ return boost::math::itrunc(v, Policy()); }\
+ inline int itrunc(const T& v){ using boost::math::itrunc; return itrunc(v, Policy()); }\
    \
    template <class T>\
- inline long ltrunc(const T& v){ return boost::math::ltrunc(v, Policy()); }\
+ inline long ltrunc(const T& v){ using boost::math::ltrunc; return ltrunc(v, Policy()); }\
    \
    template <class T>\
- inline T modf(const T& v, T* ipart){ return boost::math::modf(v, ipart, Policy()); }\
+ inline T modf(const T& v, T* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\
    \
    template <class T>\
- inline T modf(const T& v, int* ipart){ return boost::math::modf(v, ipart, Policy()); }\
+ inline T modf(const T& v, int* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\
    \
    template <class T>\
- inline T modf(const T& v, long* ipart){ return boost::math::modf(v, ipart, Policy()); }\
+ inline T modf(const T& v, long* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\
    \
    template <int N, class T>\
    inline typename boost::math::tools::promote_args<T>::type pow(T v){ return boost::math::pow<N>(v, Policy()); }\

Modified: trunk/boost/math/tools/config.hpp
==============================================================================
--- trunk/boost/math/tools/config.hpp (original)
+++ trunk/boost/math/tools/config.hpp 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
@@ -21,6 +21,7 @@
 #endif
 
 #include <boost/math/tools/user.hpp>
+#include <boost/math/special_functions/detail/round_fwd.hpp>
 
 #if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__hppa)
 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
@@ -189,7 +190,14 @@
    using std::ceil;\
    using std::floor;\
    using std::log10;\
- using std::sqrt;
+ using std::sqrt;\
+ using boost::math::round;\
+ using boost::math::iround;\
+ using boost::math::lround;\
+ using boost::math::trunc;\
+ using boost::math::itrunc;\
+ using boost::math::ltrunc;\
+ using boost::math::modf;
 
 
 namespace boost{ namespace math{

Modified: trunk/libs/math/test/compile_test/instantiate.hpp
==============================================================================
--- trunk/libs/math/test/compile_test/instantiate.hpp (original)
+++ trunk/libs/math/test/compile_test/instantiate.hpp 2008-04-20 06:58:20 EDT (Sun, 20 Apr 2008)
@@ -347,19 +347,25 @@
    boost::math::expint(i, i, pol);
    boost::math::zeta(v1, pol);
    boost::math::zeta(i, pol);
- boost::math::trunc(v1, pol);
- boost::math::itrunc(v1, pol);
- boost::math::ltrunc(v1, pol);
- boost::math::round(v1, pol);
- boost::math::iround(v1, pol);
- boost::math::lround(v1, pol);
- boost::math::modf(v1, &v1, pol);
- boost::math::modf(v1, &i, pol);
- boost::math::modf(v1, &l, pol);
+ //
+ // These next functions are intended to be found via ADL:
+ //
+ BOOST_MATH_STD_USING
+ trunc(v1, pol);
+ itrunc(v1, pol);
+ ltrunc(v1, pol);
+ round(v1, pol);
+ iround(v1, pol);
+ lround(v1, pol);
+ modf(v1, &v1, pol);
+ modf(v1, &i, pol);
+ modf(v1, &l, pol);
 #ifdef BOOST_HAS_LONG_LONG
- boost::math::lltrunc(v1, pol);
- boost::math::llround(v1, pol);
- boost::math::modf(v1, &ll, pol);
+ using boost::math::lltrunc;
+ using boost::math::llround;
+ lltrunc(v1, pol);
+ llround(v1, pol);
+ modf(v1, &ll, pol);
 #endif
    boost::math::pow<2>(v1, pol);
    //


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