Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85188 - in trunk: boost/math/special_functions boost/math/tools libs/math/test
From: john_at_[hidden]
Date: 2013-08-02 04:30:05


Author: johnmaddock
Date: 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013)
New Revision: 85188
URL: http://svn.boost.org/trac/boost/changeset/85188

Log:
Made a few core functions usable with long double even when there is no std lib long double support.
Fixes #8940.

Added:
   trunk/libs/math/test/test_ldouble_simple.cpp (contents, props changed)
Text files modified:
   trunk/boost/math/special_functions/fpclassify.hpp | 8 ++++----
   trunk/boost/math/special_functions/math_fwd.hpp | 4 ++--
   trunk/boost/math/special_functions/sign.hpp | 10 +++++-----
   trunk/boost/math/tools/promotion.hpp | 27 ++++++++++++++++++++++++++-
   trunk/libs/math/test/Jamfile.v2 | 1 +
   trunk/libs/math/test/test_ldouble_simple.cpp | 28 ++++++++++++++++++++++++++++
   6 files changed, 66 insertions(+), 12 deletions(-)

Modified: trunk/boost/math/special_functions/fpclassify.hpp
==============================================================================
--- trunk/boost/math/special_functions/fpclassify.hpp Thu Aug 1 18:19:00 2013 (r85187)
+++ trunk/boost/math/special_functions/fpclassify.hpp 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013) (r85188)
@@ -258,7 +258,7 @@
 {
    typedef typename detail::fp_traits<T>::type traits;
    typedef typename traits::method method;
- typedef typename tools::promote_args<T>::type value_type;
+ typedef typename tools::promote_args_permissive<T>::type value_type;
 #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
    if(std::numeric_limits<T>::is_specialized && detail::is_generic_tag_false(static_cast<method*>(0)))
       return detail::fpclassify_imp(static_cast<value_type>(t), detail::generic_tag<true>());
@@ -338,7 +338,7 @@
    typedef typename detail::fp_traits<T>::type traits;
    typedef typename traits::method method;
    // typedef typename boost::is_floating_point<T>::type fp_tag;
- typedef typename tools::promote_args<T>::type value_type;
+ typedef typename tools::promote_args_permissive<T>::type value_type;
    return detail::isfinite_impl(static_cast<value_type>(x), method());
 }
 
@@ -409,7 +409,7 @@
    typedef typename detail::fp_traits<T>::type traits;
    typedef typename traits::method method;
    //typedef typename boost::is_floating_point<T>::type fp_tag;
- typedef typename tools::promote_args<T>::type value_type;
+ typedef typename tools::promote_args_permissive<T>::type value_type;
    return detail::isnormal_impl(static_cast<value_type>(x), method());
 }
 
@@ -498,7 +498,7 @@
    typedef typename detail::fp_traits<T>::type traits;
    typedef typename traits::method method;
    // typedef typename boost::is_floating_point<T>::type fp_tag;
- typedef typename tools::promote_args<T>::type value_type;
+ typedef typename tools::promote_args_permissive<T>::type value_type;
    return detail::isinf_impl(static_cast<value_type>(x), method());
 }
 

Modified: trunk/boost/math/special_functions/math_fwd.hpp
==============================================================================
--- trunk/boost/math/special_functions/math_fwd.hpp Thu Aug 1 18:19:00 2013 (r85187)
+++ trunk/boost/math/special_functions/math_fwd.hpp 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013) (r85188)
@@ -768,10 +768,10 @@
    int sign BOOST_NO_MACRO_EXPAND(const T& z);
 
    template <class T, class U>
- typename tools::promote_args<T, U>::type copysign BOOST_NO_MACRO_EXPAND(const T& x, const U& y);
+ typename tools::promote_args_permissive<T, U>::type copysign BOOST_NO_MACRO_EXPAND(const T& x, const U& y);
 
    template <class T>
- typename tools::promote_args<T>::type changesign BOOST_NO_MACRO_EXPAND(const T& z);
+ typename tools::promote_args_permissive<T>::type changesign BOOST_NO_MACRO_EXPAND(const T& z);
 
    // Exponential integrals:
    namespace detail{

Modified: trunk/boost/math/special_functions/sign.hpp
==============================================================================
--- trunk/boost/math/special_functions/sign.hpp Thu Aug 1 18:19:00 2013 (r85187)
+++ trunk/boost/math/special_functions/sign.hpp 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013) (r85188)
@@ -111,7 +111,7 @@
    typedef typename detail::fp_traits<T>::type traits;
    typedef typename traits::method method;
    // typedef typename boost::is_floating_point<T>::type fp_tag;
- typedef typename tools::promote_args<T>::type result_type;
+ typedef typename tools::promote_args_permissive<T>::type result_type;
    return detail::signbit_impl(static_cast<result_type>(x), method());
 }
 
@@ -121,22 +121,22 @@
    return (z == 0) ? 0 : (boost::math::signbit)(z) ? -1 : 1;
 }
 
-template <class T> typename tools::promote_args<T>::type (changesign)(const T& x)
+template <class T> typename tools::promote_args_permissive<T>::type (changesign)(const T& x)
 { //!< \brief return unchanged binary pattern of x, except for change of sign bit.
    typedef typename detail::fp_traits<T>::sign_change_type traits;
    typedef typename traits::method method;
    // typedef typename boost::is_floating_point<T>::type fp_tag;
- typedef typename tools::promote_args<T>::type result_type;
+ typedef typename tools::promote_args_permissive<T>::type result_type;
 
    return detail::changesign_impl(static_cast<result_type>(x), method());
 }
 
 template <class T, class U>
-inline typename tools::promote_args<T, U>::type
+inline typename tools::promote_args_permissive<T, U>::type
    copysign BOOST_NO_MACRO_EXPAND(const T& x, const U& y)
 {
    BOOST_MATH_STD_USING
- typedef typename tools::promote_args<T, U>::type result_type;
+ typedef typename tools::promote_args_permissive<T, U>::type result_type;
    return (boost::math::signbit)(static_cast<result_type>(x)) != (boost::math::signbit)(static_cast<result_type>(y))
       ? (boost::math::changesign)(static_cast<result_type>(x)) : static_cast<result_type>(x);
 }

Modified: trunk/boost/math/tools/promotion.hpp
==============================================================================
--- trunk/boost/math/tools/promotion.hpp Thu Aug 1 18:19:00 2013 (r85187)
+++ trunk/boost/math/tools/promotion.hpp 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013) (r85188)
@@ -138,10 +138,35 @@
          //
          // Guard against use of long double if it's not supported:
          //
- BOOST_STATIC_ASSERT((0 == ::boost::is_same<type, long double>::value));
+ BOOST_STATIC_ASSERT_MSG((0 == ::boost::is_same<type, long double>::value), "Sorry, but this platform does not have sufficient long double support for the special functions to be reliably implemented.");
 #endif
       };
 
+ //
+ // This struct is the same as above, but has no static assert on long double usage,
+ // it should be used only on functions that can be implemented for long double
+ // even when std lib support is missing or broken for that type.
+ //
+ template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float>
+ struct promote_args_permissive
+ {
+ typedef typename promote_args_2<
+ typename remove_cv<T1>::type,
+ typename promote_args_2<
+ typename remove_cv<T2>::type,
+ typename promote_args_2<
+ typename remove_cv<T3>::type,
+ typename promote_args_2<
+ typename remove_cv<T4>::type,
+ typename promote_args_2<
+ typename remove_cv<T5>::type, typename remove_cv<T6>::type
+ >::type
+ >::type
+ >::type
+ >::type
+ >::type type;
+ };
+
     } // namespace tools
   } // namespace math
 } // namespace boost

Modified: trunk/libs/math/test/Jamfile.v2
==============================================================================
--- trunk/libs/math/test/Jamfile.v2 Thu Aug 1 18:19:00 2013 (r85187)
+++ trunk/libs/math/test/Jamfile.v2 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013) (r85188)
@@ -453,6 +453,7 @@
 run test_inv_hyp.cpp pch ../../test/build//boost_unit_test_framework ;
 run test_laguerre.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ;
 run test_legendre.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ;
+run test_ldouble_simple.cpp ../../test/build//boost_unit_test_framework ;
 run test_logistic_dist.cpp ../../test/build//boost_unit_test_framework ;
 run test_lognormal.cpp ../../test/build//boost_unit_test_framework ;
 run test_minima.cpp pch ../../test/build//boost_unit_test_framework ;

Added: trunk/libs/math/test/test_ldouble_simple.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/math/test/test_ldouble_simple.cpp 2013-08-02 04:30:04 EDT (Fri, 02 Aug 2013) (r85188)
@@ -0,0 +1,28 @@
+// Copyright John Maddock 2013.
+// 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)
+
+#define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp> // Boost.Test
+#include <boost/math/special_functions/sign.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+
+BOOST_AUTO_TEST_CASE( test_main )
+{
+ BOOST_CHECK_EQUAL((boost::math::signbit)(1.0L), 0.0L);
+ BOOST_CHECK_EQUAL((boost::math::signbit)(-1.0L), 1.0L);
+ BOOST_CHECK_EQUAL((boost::math::sign)(1.0L), 1.0L);
+ BOOST_CHECK_EQUAL((boost::math::sign)(-1.0L), -1.0L);
+ BOOST_CHECK_EQUAL((boost::math::changesign)(1.0L), -1.0L);
+ BOOST_CHECK_EQUAL((boost::math::changesign)(-1.0L), 1.0L);
+
+ BOOST_CHECK_EQUAL((boost::math::fpclassify)(1.0L), FP_NORMAL);
+ BOOST_CHECK_EQUAL((boost::math::isnan)(1.0L), false);
+ BOOST_CHECK_EQUAL((boost::math::isinf)(1.0L), false);
+ BOOST_CHECK_EQUAL((boost::math::isnormal)(1.0L), true);
+ BOOST_CHECK_EQUAL((boost::math::isfinite)(1.0L), true);
+} // BOOST_AUTO_TEST_CASE( test_main )
+


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