Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84917 - in trunk: boost/math/distributions libs/math/test/compile_test
From: john_at_[hidden]
Date: 2013-06-30 07:05:21


Author: johnmaddock
Date: 2013-06-30 07:05:21 EDT (Sun, 30 Jun 2013)
New Revision: 84917
URL: http://svn.boost.org/trac/boost/changeset/84917

Log:
Add test for things that are macros in C99 to ensure we call these correctly.
Refs #8732.
Fixes #8733.

Added:
   trunk/libs/math/test/compile_test/poison.hpp (contents, props changed)
Text files modified:
   trunk/boost/math/distributions/non_central_t.hpp | 18 +++---
   trunk/boost/math/distributions/students_t.hpp | 10 ++--
   trunk/libs/math/test/compile_test/poison.hpp | 96 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/math/test/compile_test/std_real_concept_check.cpp | 2
   4 files changed, 112 insertions(+), 14 deletions(-)

Modified: trunk/boost/math/distributions/non_central_t.hpp
==============================================================================
--- trunk/boost/math/distributions/non_central_t.hpp Sun Jun 30 06:51:55 2013 (r84916)
+++ trunk/boost/math/distributions/non_central_t.hpp 2013-06-30 07:05:21 EDT (Sun, 30 Jun 2013) (r84917)
@@ -206,7 +206,7 @@
          T non_central_t_cdf(T v, T delta, T t, bool invert, const Policy& pol)
          {
             BOOST_MATH_STD_USING
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
             { // Infinite degrees of freedom, so use normal distribution located at delta.
                normal_distribution<T, Policy> n(delta, 1);
                return cdf(n, t);
@@ -320,7 +320,7 @@
 
 
             value_type guess = 0;
- if ( (boost::math::isinf(v)) || (v > 1 / boost::math::tools::epsilon<T>()) )
+ if ( ((boost::math::isinf)(v)) || (v > 1 / boost::math::tools::epsilon<T>()) )
             { // Infinite or very large degrees of freedom, so use normal distribution located at delta.
                normal_distribution<T, Policy> n(delta, 1);
                if (p < q)
@@ -447,7 +447,7 @@
          T non_central_t_pdf(T n, T delta, T t, const Policy& pol)
          {
             BOOST_MATH_STD_USING
- if (boost::math::isinf(n))
+ if ((boost::math::isinf)(n))
             { // Infinite degrees of freedom, so use normal distribution located at delta.
                normal_distribution<T, Policy> n(delta, 1);
                return pdf(n, t);
@@ -515,7 +515,7 @@
          template <class T, class Policy>
          T mean(T v, T delta, const Policy& pol)
          {
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
             {
                return delta;
             }
@@ -536,7 +536,7 @@
          template <class T, class Policy>
          T variance(T v, T delta, const Policy& pol)
          {
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
             {
                return 1;
             }
@@ -554,7 +554,7 @@
          T skewness(T v, T delta, const Policy& pol)
          {
             BOOST_MATH_STD_USING
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
             {
                return 0;
             }
@@ -576,7 +576,7 @@
          T kurtosis_excess(T v, T delta, const Policy& pol)
          {
             BOOST_MATH_STD_USING
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
             {
                return 3;
             }
@@ -1097,7 +1097,7 @@
             &r,
             Policy()))
                return (RealType)r;
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
           { // Infinite degrees of freedom, so use normal distribution located at delta.
              normal_distribution<RealType, Policy> n(l, 1);
              cdf(n, x);
@@ -1152,7 +1152,7 @@
             Policy()))
                return (RealType)r;
 
- if (boost::math::isinf(v))
+ if ((boost::math::isinf)(v))
          { // Infinite degrees of freedom, so use normal distribution located at delta.
              normal_distribution<RealType, Policy> n(l, 1);
              return cdf(complement(n, x));

Modified: trunk/boost/math/distributions/students_t.hpp
==============================================================================
--- trunk/boost/math/distributions/students_t.hpp Sun Jun 30 06:51:55 2013 (r84916)
+++ trunk/boost/math/distributions/students_t.hpp 2013-06-30 07:05:21 EDT (Sun, 30 Jun 2013) (r84917)
@@ -93,7 +93,7 @@
       return error_result;
 
    RealType result;
- if (boost::math::isinf(x))
+ if ((boost::math::isinf)(x))
    { // +infinity.
      normal_distribution<RealType, Policy> n(0, 1);
      RealType result = pdf(n, x);
@@ -144,7 +144,7 @@
    { // Special case with exact result.
      return static_cast<RealType>(0.5);
    }
- if (boost::math::isinf(x))
+ if ((boost::math::isinf)(x))
    { // +infinity.
      normal_distribution<RealType, Policy> n(0, 1);
      RealType result = cdf(n, x);
@@ -376,7 +376,7 @@
       df, Policy());
     return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
   }
- if (boost::math::isinf(df))
+ if ((boost::math::isinf)(df))
   { // +infinity.
     return 1;
   }
@@ -422,7 +422,7 @@
         df, Policy());
         return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
    }
- if (boost::math::isinf(df))
+ if ((boost::math::isinf)(df))
    { // +infinity.
      return 3;
    }
@@ -456,7 +456,7 @@
       df, Policy());
      return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
    }
- if (boost::math::isinf(df))
+ if ((boost::math::isinf)(df))
    { // +infinity.
      return 0;
    }

Added: trunk/libs/math/test/compile_test/poison.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/math/test/compile_test/poison.hpp 2013-06-30 07:05:21 EDT (Sun, 30 Jun 2013) (r84917)
@@ -0,0 +1,96 @@
+// 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)
+
+#ifndef BOOST_MATH_COMPILE_POISON_HPP
+#define BOOST_MATH_COMPILE_POISON_HPP
+
+#include <cmath>
+#include <math.h>
+//
+// We have to include this *before* poisoning the macros
+// as it needs to be able to use them!
+//
+#include <boost/math/special_functions/fpclassify.hpp>
+
+//
+// Poison all the function-like macros in C99 so if we accidentally call them
+// in an unsafe manner, we'll get compiler errors. Of course these shouldn't be
+// macros in C++ at all...
+//
+
+#ifdef fpclassify
+#undef fpclassify
+#endif
+
+#define fpclassify(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isfinite
+#undef isfinite
+#endif
+
+#define isfinite(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isinf
+#undef isinf
+#endif
+
+#define isinf(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isnan
+#undef isnan
+#endif
+
+#define isnan(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isnormal
+#undef isnormal
+#endif
+
+#define isnormal(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef signbit
+#undef signbit
+#endif
+
+#define signbit(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isgreater
+#undef isgreater
+#endif
+
+#define isgreater(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isgreaterequal
+#undef isgreaterequal
+#endif
+
+#define isgreaterequal(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isless
+#undef isless
+#endif
+
+#define isless(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef islessequal
+#undef islessequal
+#endif
+
+#define islessequal(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef islessgreater
+#undef islessgreater
+#endif
+
+#define islessgreater(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#ifdef isunordered
+#undef isunordered
+#endif
+
+#define isunordered(x) this_should_not_compile(x)}}}}}}}}}}}}}}}}}}}
+
+#endif
+

Modified: trunk/libs/math/test/compile_test/std_real_concept_check.cpp
==============================================================================
--- trunk/libs/math/test/compile_test/std_real_concept_check.cpp Sun Jun 30 06:51:55 2013 (r84916)
+++ trunk/libs/math/test/compile_test/std_real_concept_check.cpp 2013-06-30 07:05:21 EDT (Sun, 30 Jun 2013) (r84917)
@@ -5,6 +5,8 @@
 
 #define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
 
+#include "poison.hpp"
+
 #include <boost/math/concepts/std_real_concept.hpp>
 #include <boost/math/concepts/distributions.hpp>
 


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