Skip to content

Commit

Permalink
Update to latest libprimesieve
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jan 8, 2024
1 parent 456aa22 commit e7658c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/primesieve/include/primesieve/nthPrimeApprox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ uint64_t Li(uint64_t x);
uint64_t Li_inverse(uint64_t x);
uint64_t Ri(uint64_t x);
uint64_t Ri_inverse(uint64_t x);
uint64_t primesApprox(uint64_t x);
uint64_t primePiApprox(uint64_t x);
uint64_t nthPrimeApprox(uint64_t n);

} // namespace
7 changes: 3 additions & 4 deletions lib/primesieve/src/nthPrime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
///

#include <primesieve/iterator.hpp>
#include <primesieve/forward.hpp>
#include <primesieve/PrimeSieve.hpp>
#include <primesieve/macros.hpp>
#include <primesieve/pmath.hpp>
Expand All @@ -27,7 +26,7 @@ namespace {
const uint64_t max_n = 425656284035217743ull;

/// Average prime gap near n
inline uint64_t avgPrimeGap(uint64_t n)
uint64_t avgPrimeGap(uint64_t n)
{
double x = (double) n;
x = std::max(8.0, x);
Expand Down Expand Up @@ -60,7 +59,7 @@ uint64_t PrimeSieve::nthPrime(int64_t n, uint64_t start)

setStart(start);
auto t1 = std::chrono::system_clock::now();
uint64_t nApprox = checkedAdd(primesApprox(start), n);
uint64_t nApprox = checkedAdd(primePiApprox(start), n);
nApprox = std::min(nApprox, max_n);
uint64_t primeApprox = nthPrimeApprox(nApprox);
primeApprox = std::max(primeApprox, start);
Expand Down Expand Up @@ -125,7 +124,7 @@ uint64_t PrimeSieve::negativeNthPrime(int64_t n, uint64_t start)

setStart(start);
auto t1 = std::chrono::system_clock::now();
uint64_t nApprox = checkedSub(primesApprox(start), n);
uint64_t nApprox = checkedSub(primePiApprox(start), n);
nApprox = std::min(nApprox, max_n);
uint64_t primeApprox = nthPrimeApprox(nApprox);
primeApprox = std::min(primeApprox, start);
Expand Down
7 changes: 4 additions & 3 deletions lib/primesieve/src/nthPrimeApprox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <primesieve/Vector.hpp>

#include <stdint.h>
#include <algorithm>
#include <cmath>
#include <limits>

Expand Down Expand Up @@ -254,10 +255,10 @@ uint64_t Ri_inverse(uint64_t x)
return (uint64_t) ::Ri_inverse((long double) x);
}

uint64_t primesApprox(uint64_t x)
uint64_t primePiApprox(uint64_t x)
{
// Li(x) is faster but less accurate than Ri(x).
// For small n speed is more important than accuracy.
// For small x speed is more important than accuracy.
if (x < 1e10)
return Li(x);
else
Expand All @@ -266,7 +267,7 @@ uint64_t primesApprox(uint64_t x)

uint64_t nthPrimeApprox(uint64_t n)
{
// Li_inverse(x) is faster but less accurate than Ri_inverse(x).
// Li_inverse(n) is faster but less accurate than Ri_inverse(n).
// For small n speed is more important than accuracy.
if (n < 1e8)
return Li_inverse(n);
Expand Down

0 comments on commit e7658c1

Please sign in to comment.