From de1f331ebc93ccf3880c9684e3ba577f87b8b363 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Sat, 26 Sep 2020 22:18:54 -0500 Subject: [PATCH] prime approximation function for a range --- include/boost/math/special_functions/prime_sieve.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/boost/math/special_functions/prime_sieve.hpp b/include/boost/math/special_functions/prime_sieve.hpp index cf6a39dc9..e63adfc21 100644 --- a/include/boost/math/special_functions/prime_sieve.hpp +++ b/include/boost/math/special_functions/prime_sieve.hpp @@ -235,12 +235,18 @@ void sequential_segmented_sieve(Integer lower_bound, Integer upper_bound, Contai } // End namespace detail template -constexpr Integer prime_approximation(Integer upper_bound) +constexpr Integer prime_approximation(const Integer upper_bound) { constexpr auto c = 30 * std::log(113) / 113; // Magic numbers from wikipedia return static_cast(std::floor(c * upper_bound / std::log(static_cast(upper_bound)))); } +template +constexpr Integer prime_approximation(const Integer lower_bound, const Integer upper_bound) +{ + return prime_approximation(upper_bound) - prime_approximation(lower_bound); +} + template constexpr void prime_reserve(Integer upper_bound, std::vector &prime_container) {