Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions include/boost/math/quadrature/detail/quadrature_constant.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright John Maddock 2015.
// 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_QUADRATURE_DETAIL_QUADRATURE_CONSTANT_HPP
#define BOOST_MATH_QUADRATURE_DETAIL_QUADRATURE_CONSTANT_HPP

#ifndef BOOST_MATH_BUILD_MODULE
#include <limits>
#include <type_traits>
#endif

namespace boost { namespace math{ namespace quadrature{ namespace detail {

template <class T>
struct quadrature_constant_category
{
static const unsigned value =
(std::numeric_limits<T>::is_specialized == 0) ? 999 :
(std::numeric_limits<T>::radix == 2) ?
(
#ifdef BOOST_HAS_FLOAT128
(std::numeric_limits<T>::digits <= 113) && std::is_constructible<T, __float128>::value ? 0 :
#else
(std::numeric_limits<T>::digits <= std::numeric_limits<long double>::digits) && std::is_constructible<T, long double>::value ? 0 :
#endif
(std::numeric_limits<T>::digits10 <= 110) && std::is_constructible<T, const char*>::value ? 4 : 999
) : (std::numeric_limits<T>::digits10 <= 110) && std::is_constructible<T, const char*>::value ? 4 : 999;

using storage_type =
std::conditional_t<(std::numeric_limits<T>::is_specialized == 0), T,
std::conditional_t<(std::numeric_limits<T>::radix == 2),
std::conditional_t< ((std::numeric_limits<T>::digits <= std::numeric_limits<float>::digits) && std::is_constructible<T, float>::value),
float,
std::conditional_t<((std::numeric_limits<T>::digits <= std::numeric_limits<double>::digits) && std::is_constructible<T, double>::value),
double,
std::conditional_t<((std::numeric_limits<T>::digits <= std::numeric_limits<long double>::digits) && std::is_constructible<T, long double>::value),
long double,
#ifdef BOOST_HAS_FLOAT128
std::conditional_t<((std::numeric_limits<T>::digits <= 113) && std::is_constructible<T, __float128>::value),
__float128,
T
>
>
#else
T
>
#endif
>
>, T
>
>;
};

}
}
}
}

#endif // BOOST_MATH_QUADRATURE_DETAIL_QUADRATURE_CONSTANT_HPP
73 changes: 17 additions & 56 deletions include/boost/math/quadrature/gauss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,14 @@
#endif
#include <boost/math/special_functions/legendre.hpp>
#include <boost/math/constants/constants.hpp>
#include <boost/math/quadrature/detail/quadrature_constant.hpp>

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4127)
#endif

BOOST_MATH_NAMESPACE_BEGIN namespace quadrature{ namespace detail{

template <class T>
struct gauss_constant_category
{
static const unsigned value =
(std::numeric_limits<T>::is_specialized == 0) ? 999 :
(std::numeric_limits<T>::radix == 2) ?
(
#ifdef BOOST_HAS_FLOAT128
(std::numeric_limits<T>::digits <= 113) && std::is_constructible<T, __float128>::value ? 0 :
#else
(std::numeric_limits<T>::digits <= std::numeric_limits<long double>::digits) && std::is_constructible<T, long double>::value ? 0 :
#endif
(std::numeric_limits<T>::digits10 <= 110) && std::is_constructible<T, const char*>::value ? 4 : 999
) : (std::numeric_limits<T>::digits10 <= 110) && std::is_constructible<T, const char*>::value ? 4 : 999;

using storage_type =
std::conditional_t<(std::numeric_limits<T>::is_specialized == 0), T,
std::conditional_t<(std::numeric_limits<T>::radix == 2),
std::conditional_t< ((std::numeric_limits<T>::digits <= std::numeric_limits<float>::digits) && std::is_constructible<T, float>::value),
float,
std::conditional_t<((std::numeric_limits<T>::digits <= std::numeric_limits<double>::digits) && std::is_constructible<T, double>::value),
double,
std::conditional_t<((std::numeric_limits<T>::digits <= std::numeric_limits<long double>::digits) && std::is_constructible<T, long double>::value),
long double,
#ifdef BOOST_HAS_FLOAT128
std::conditional_t<((std::numeric_limits<T>::digits <= 113) && std::is_constructible<T, __float128>::value),
__float128,
T
>
>
#else
T
>
#endif
>
>, T
>
>;
};
namespace boost { namespace math{ namespace quadrature{ namespace detail {

#ifndef BOOST_MATH_GAUSS_NO_COMPUTE_ON_DEMAND

Expand Down Expand Up @@ -103,7 +64,7 @@ class gauss_detail;
template <class T>
class gauss_detail<T, 7, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 4> const & abscissa()
{
Expand All @@ -130,7 +91,7 @@ class gauss_detail<T, 7, 0>
template <class T>
class gauss_detail<T, 7, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 4> const & abscissa()
{
Expand Down Expand Up @@ -183,7 +144,7 @@ class gauss_detail<T, 7, 4>
template <class T>
class gauss_detail<T, 10, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 5> const & abscissa()
{
Expand Down Expand Up @@ -212,7 +173,7 @@ class gauss_detail<T, 10, 0>
template <class T>
class gauss_detail<T, 10, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 5> const & abscissa()
{
Expand Down Expand Up @@ -270,7 +231,7 @@ class gauss_detail<T, 10, 4>
template <class T>
class gauss_detail<T, 15, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 8> const & abscissa()
{
Expand Down Expand Up @@ -305,7 +266,7 @@ class gauss_detail<T, 15, 0>
template <class T>
class gauss_detail<T, 15, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 8> const & abscissa()
{
Expand Down Expand Up @@ -375,7 +336,7 @@ class gauss_detail<T, 15, 4>
template <class T>
class gauss_detail<T, 20, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 10> const & abscissa()
{
Expand Down Expand Up @@ -414,7 +375,7 @@ class gauss_detail<T, 20, 0>
template <class T>
class gauss_detail<T, 20, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 10> const & abscissa()
{
Expand Down Expand Up @@ -492,7 +453,7 @@ class gauss_detail<T, 20, 4>
template <class T>
class gauss_detail<T, 25, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 13> const & abscissa()
{
Expand Down Expand Up @@ -537,7 +498,7 @@ class gauss_detail<T, 25, 0>
template <class T>
class gauss_detail<T, 25, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 13> const & abscissa()
{
Expand Down Expand Up @@ -628,7 +589,7 @@ class gauss_detail<T, 25, 4>
template <class T>
class gauss_detail<T, 30, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 15> const & abscissa()
{
Expand Down Expand Up @@ -677,7 +638,7 @@ class gauss_detail<T, 30, 0>
template <class T>
class gauss_detail<T, 30, 0>
{
using storage_type = typename gauss_constant_category<T>::storage_type;
using storage_type = typename quadrature_constant_category<T>::storage_type;
public:
static std::array<storage_type, 15> const & abscissa()
{
Expand Down Expand Up @@ -773,10 +734,10 @@ class gauss_detail<T, 30, 4>

}

BOOST_MATH_EXPORT template <class Real, unsigned N, class Policy = BOOST_MATH_NAMESPACE::policies::policy<> >
class gauss : public detail::gauss_detail<Real, N, detail::gauss_constant_category<Real>::value>
BOOST_MATH_EXPORT template <class Real, unsigned N, class Policy = boost::math::policies::policy<> >
class gauss : public detail::gauss_detail<Real, N, detail::quadrature_constant_category<Real>::value>
{
typedef detail::gauss_detail<Real, N, detail::gauss_constant_category<Real>::value> base;
typedef detail::gauss_detail<Real, N, detail::quadrature_constant_category<Real>::value> base;
public:

template <class F>
Expand Down
Loading
Loading