summaryrefslogtreecommitdiff
path: root/boost/math/special_functions/prime.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/math/special_functions/prime.hpp')
-rw-r--r--boost/math/special_functions/prime.hpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/boost/math/special_functions/prime.hpp b/boost/math/special_functions/prime.hpp
index 94c28f9842..858d96d10b 100644
--- a/boost/math/special_functions/prime.hpp
+++ b/boost/math/special_functions/prime.hpp
@@ -8,15 +8,19 @@
#ifndef BOOST_MATH_SF_PRIME_HPP
#define BOOST_MATH_SF_PRIME_HPP
-#include <boost/array.hpp>
#include <boost/cstdint.hpp>
#include <boost/math/policies/error_handling.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
+#ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
+#include <array>
+#else
+#include <boost/array.hpp>
+#endif
namespace boost{ namespace math{
template <class Policy>
- boost::uint32_t prime(unsigned n, const Policy& pol)
+ BOOST_MATH_CONSTEXPR_TABLE_FUNCTION boost::uint32_t prime(unsigned n, const Policy& pol)
{
//
// This is basically three big tables which together
@@ -26,10 +30,17 @@ namespace boost{ namespace math{
// That gives us the first 10000 primes with the largest
// being 104729:
//
+#ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
+ constexpr unsigned b1 = 53;
+ constexpr unsigned b2 = 6541;
+ constexpr unsigned b3 = 10000;
+ constexpr std::array<unsigned char, 54> a1 = {{
+#else
static const unsigned b1 = 53;
static const unsigned b2 = 6541;
static const unsigned b3 = 10000;
static const boost::array<unsigned char, 54> a1 = {{
+#endif
2u, 3u, 5u, 7u, 11u, 13u, 17u, 19u, 23u, 29u, 31u,
37u, 41u, 43u, 47u, 53u, 59u, 61u, 67u, 71u, 73u,
79u, 83u, 89u, 97u, 101u, 103u, 107u, 109u, 113u,
@@ -37,7 +48,11 @@ namespace boost{ namespace math{
167u, 173u, 179u, 181u, 191u, 193u, 197u, 199u,
211u, 223u, 227u, 229u, 233u, 239u, 241u, 251u
}};
+#ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
+ constexpr std::array<boost::uint16_t, 6488> a2 = {{
+#else
static const boost::array<boost::uint16_t, 6488> a2 = {{
+#endif
257u, 263u, 269u, 271u, 277u, 281u, 283u, 293u,
307u, 311u, 313u, 317u, 331u, 337u, 347u, 349u, 353u,
359u, 367u, 373u, 379u, 383u, 389u, 397u, 401u, 409u,
@@ -760,7 +775,11 @@ namespace boost{ namespace math{
65323u, 65327u, 65353u, 65357u, 65371u, 65381u, 65393u, 65407u, 65413u,
65419u, 65423u, 65437u, 65447u, 65449u, 65479u, 65497u, 65519u, 65521u
}};
+#ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
+ constexpr std::array<boost::uint16_t, 3458> a3 = {{
+#else
static const boost::array<boost::uint16_t, 3458> a3 = {{
+#endif
2u, 4u, 8u, 16u, 22u, 28u, 44u,
46u, 52u, 64u, 74u, 82u, 94u, 98u, 112u,
116u, 122u, 142u, 152u, 164u, 166u, 172u, 178u,
@@ -1208,7 +1227,7 @@ namespace boost{ namespace math{
return static_cast<boost::uint32_t>(a3[n - b2 - 1]) + 0xFFFFu;
}
- inline boost::uint32_t prime(unsigned n)
+ inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION boost::uint32_t prime(unsigned n)
{
return boost::math::prime(n, boost::math::policies::policy<>());
}