Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83342 - in trunk: boost/math/concepts boost/math/constants boost/math/policies boost/math/special_functions boost/math/tools libs/math/test
From: john_at_[hidden]
Date: 2013-03-07 04:17:10


Author: johnmaddock
Date: 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
New Revision: 83342
URL: http://svn.boost.org/trac/boost/changeset/83342

Log:
Fix a couple of expression template support issues in bessel.hpp.
Add minimal support for __float128 - particularly numeric constant support.
Improve constant test cases.
Fix bug in zeta function tests.
Text files modified:
   trunk/boost/math/concepts/real_concept.hpp | 3 +++
   trunk/boost/math/concepts/std_real_concept.hpp | 3 +++
   trunk/boost/math/constants/constants.hpp | 32 ++++++++++++++++++++++++++++++--
   trunk/boost/math/policies/policy.hpp | 10 ++++++++++
   trunk/boost/math/special_functions/bessel.hpp | 4 ++--
   trunk/boost/math/tools/config.hpp | 7 +++++++
   trunk/libs/math/test/test_constants.cpp | 36 ++++++++++++++++++++++++++++++++++++
   trunk/libs/math/test/test_zeta.hpp | 1 +
   8 files changed, 92 insertions(+), 4 deletions(-)

Modified: trunk/boost/math/concepts/real_concept.hpp
==============================================================================
--- trunk/boost/math/concepts/real_concept.hpp (original)
+++ trunk/boost/math/concepts/real_concept.hpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -84,6 +84,9 @@
    real_concept(float c) : m_value(c){}
    real_concept(double c) : m_value(c){}
    real_concept(long double c) : m_value(c){}
+#ifdef BOOST_MATH_USE_FLOAT128
+ real_concept(__float128 c) : m_value(c){}
+#endif
 
    // Assignment:
    real_concept& operator=(char c) { m_value = c; return *this; }

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 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -67,6 +67,9 @@
    std_real_concept(float c) : m_value(c){}
    std_real_concept(double c) : m_value(c){}
    std_real_concept(long double c) : m_value(c){}
+#ifdef BOOST_MATH_USE_FLOAT128
+ std_real_concept(__float128 c) : m_value(c){}
+#endif
 
    // Assignment:
    std_real_concept& operator=(char c) { m_value = c; return *this; }

Modified: trunk/boost/math/constants/constants.hpp
==============================================================================
--- trunk/boost/math/constants/constants.hpp (original)
+++ trunk/boost/math/constants/constants.hpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -23,6 +23,7 @@
 #include <boost/mpl/int.hpp>
 #include <boost/type_traits/is_convertible.hpp>
 
+
 namespace boost{ namespace math
 {
   namespace constants
@@ -46,7 +47,10 @@
       construct_from_float = 1,
       construct_from_double = 2,
       construct_from_long_double = 3,
- construct_from_string = 4
+ construct_from_string = 4,
+ construct_from_float128 = 5,
+ // Must be the largest value above:
+ construct_max = construct_from_float128
    };
 
    //
@@ -63,6 +67,9 @@
       typedef typename policies::precision<float, Policy>::type t2;
       typedef typename policies::precision<double, Policy>::type t3;
       typedef typename policies::precision<long double, Policy>::type t4;
+#ifdef BOOST_MATH_USE_FLOAT128
+ typedef mpl::int_<FLT128_MANT_DIG> t5;
+#endif
    public:
       typedef typename mpl::if_<
          mpl::and_<boost::is_convertible<float, Real>, mpl::bool_< t1::value <= t2::value>, mpl::bool_<0 != t1::value> >,
@@ -73,11 +80,23 @@
             typename mpl::if_<
                mpl::and_<boost::is_convertible<long double, Real>, mpl::bool_< t1::value <= t4::value>, mpl::bool_<0 != t1::value> >,
                mpl::int_<construct_from_long_double>,
+#ifdef BOOST_MATH_USE_FLOAT128
+ typename mpl::if_<
+ mpl::and_<boost::is_convertible<__float128, Real>, mpl::bool_< t1::value <= t5::value>, mpl::bool_<0 != t1::value> >,
+ mpl::int_<construct_from_float128>,
+ typename mpl::if_<
+ mpl::and_<mpl::bool_< t1::value <= max_string_digits>, mpl::bool_<0 != t1::value> >,
+ mpl::int_<construct_from_string>,
+ mpl::int_<t1::value>
+ >::type
+ >::type
+#else
                typename mpl::if_<
                   mpl::and_<mpl::bool_< t1::value <= max_string_digits>, mpl::bool_<0 != t1::value> >,
                   mpl::int_<construct_from_string>,
                   mpl::int_<t1::value>
>::type
+#endif
>::type
>::type
>::type type;
@@ -98,7 +117,7 @@
       {
          typedef typename construction_traits<Real, Policy>::type construct_type;
          typedef typename mpl::if_c<
- (construct_type::value >= construct_from_string),
+ (construct_type::value == construct_from_string) || (construct_type::value > construct_max),
             const Real&, Real>::type type;
       };
 
@@ -167,6 +186,14 @@
 
    }
 
+#ifdef BOOST_MATH_USE_FLOAT128
+# define BOOST_MATH_FLOAT128_CONSTANT_OVERLOAD(x) \
+ static inline BOOST_CONSTEXPR T get(const mpl::int_<construct_from_float128>&)\
+ { return BOOST_JOIN(x, Q); }
+#else
+# define BOOST_MATH_FLOAT128_CONSTANT_OVERLOAD(x)
+#endif
+
    #define BOOST_DEFINE_MATH_CONSTANT(name, x, y)\
    namespace detail{\
    template <class T> struct BOOST_JOIN(constant_, name){\
@@ -197,6 +224,7 @@
    { return x; }\
    static inline BOOST_CONSTEXPR T get(const mpl::int_<construct_from_long_double>&)\
    { return BOOST_JOIN(x, L); }\
+ BOOST_MATH_FLOAT128_CONSTANT_OVERLOAD(x) \
    template <int N> static inline const T& get(const mpl::int_<N>&)\
    {\
       constant_initializer2<T, N, & BOOST_JOIN(constant_, name)<T>::template get_from_compute<N> >::force_instantiate();\

Modified: trunk/boost/math/policies/policy.hpp
==============================================================================
--- trunk/boost/math/policies/policy.hpp (original)
+++ trunk/boost/math/policies/policy.hpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -813,6 +813,16 @@
 
 #endif
 
+#ifdef BOOST_MATH_USE_FLOAT128
+
+template <class Policy>
+struct precision<__float128, Policy>
+{
+ typedef mpl::int_<FLT128_MANT_DIG> type;
+};
+
+#endif
+
 namespace detail{
 
 template <class T, class Policy>

Modified: trunk/boost/math/special_functions/bessel.hpp
==============================================================================
--- trunk/boost/math/special_functions/bessel.hpp (original)
+++ trunk/boost/math/special_functions/bessel.hpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -378,7 +378,7 @@
 
    // Get the absolute value of the order.
    const bool order_is_negative = (v < 0);
- const T vv((!order_is_negative) ? v : -v);
+ const T vv((!order_is_negative) ? v : T(-v));
 
    // Check if the order is very close to zero or very close to an integer.
    const bool order_is_zero = (vv < half_epsilon);
@@ -460,7 +460,7 @@
 
    // Get the absolute value of the order.
    const bool order_is_negative = (v < 0);
- const T vv((!order_is_negative) ? v : -v);
+ const T vv((!order_is_negative) ? v : T(-v));
 
    const bool order_is_integer = ((vv - floor(vv)) < half_epsilon);
 

Modified: trunk/boost/math/tools/config.hpp
==============================================================================
--- trunk/boost/math/tools/config.hpp (original)
+++ trunk/boost/math/tools/config.hpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -207,6 +207,13 @@
 #ifndef BOOST_MATH_INT_VALUE_SUFFIX
 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
 #endif
+//
+// Test whether to support __float128:
+//
+#ifdef _GLIBCXX_USE_FLOAT128
+# define BOOST_MATH_USE_FLOAT128
+#include <quadmath.h>
+#endif
 
 //
 // Helper macro for controlling the FP behaviour:

Modified: trunk/libs/math/test/test_constants.cpp
==============================================================================
--- trunk/libs/math/test/test_constants.cpp (original)
+++ trunk/libs/math/test/test_constants.cpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -40,7 +40,11 @@
 // Policy with precision +2 (could be any reasonable value),
 // forces the precision of the policy to be greater than
 // that of a long double, and therefore triggers different code (construct from string).
+#ifdef BOOST_MATH_USE_FLOAT128
+typedef boost::math::policies::policy<boost::math::policies::digits2<115> > real_concept_policy_2;
+#else
 typedef boost::math::policies::policy<boost::math::policies::digits2<std::numeric_limits<long double>::digits + 2> > real_concept_policy_2;
+#endif
 // Policy with precision greater than the string representations, forces computation of values (i.e. different code path):
 typedef boost::math::policies::policy<boost::math::policies::digits2<400> > real_concept_policy_3;
 
@@ -752,6 +756,34 @@
 
 } // template <class boost::math::concepts::real_concept>void test_spots(boost::math::concepts::real_concept)
 
+#ifdef BOOST_MATH_USE_FLOAT128
+void test_float128()
+{
+ __float128 p = boost::math::constants::pi<__float128>();
+ __float128 r = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651Q;
+ __float128 err = (p - r) / r;
+ if(err < 0)
+ err = -err;
+ BOOST_CHECK(err < 2 * FLT128_EPSILON);
+}
+#endif
+
+void test_constexpr()
+{
+#ifndef BOOST_NO_CXX11_CONSTEXPR
+ constexpr float f1 = boost::math::constants::pi<float>();
+ constexpr double f2 = boost::math::constants::pi<double>();
+ constexpr long double f3 = boost::math::constants::pi<long double>();
+ (void)f1;
+ (void)f2;
+ (void)f3;
+#ifdef BOOST_MATH_USE_FLOAT128
+ constexpr __float128 f4 = boost::math::constants::pi<__float128>();
+ (void)f4;
+#endif
+#endif
+}
+
 BOOST_AUTO_TEST_CASE( test_main )
 {
    // Basic sanity-check spot values.
@@ -759,6 +791,10 @@
    test_float_spots(); // Test float_constants, like boost::math::float_constants::pi;
    test_double_spots(); // Test double_constants.
    test_long_double_spots(); // Test long_double_constants.
+#ifdef BOOST_MATH_USE_FLOAT128
+ test_float128();
+#endif
+ test_constexpr();
 
    test_real_concept_policy(real_concept_policy_1());
    test_real_concept_policy(real_concept_policy_2()); // Increased precision forcing construction from string.

Modified: trunk/libs/math/test/test_zeta.hpp
==============================================================================
--- trunk/libs/math/test/test_zeta.hpp (original)
+++ trunk/libs/math/test/test_zeta.hpp 2013-03-07 04:17:09 EST (Thu, 07 Mar 2013)
@@ -92,6 +92,7 @@
    // Basic sanity checks, tolerance is either 5 or 10 epsilon
    // expressed as a percentage:
    //
+ BOOST_MATH_STD_USING
    T tolerance = boost::math::tools::epsilon<T>() * 100 *
       (boost::is_floating_point<T>::value ? 5 : 10);
    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(0.125)), static_cast<T>(-0.63277562349869525529352526763564627152686379131122L), tolerance);


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