Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 18, 2024
1 parent 25cd1da commit 28d5b76
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions test/Riemann_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <string>
#include <vector>

using std::max;
using std::size_t;
using namespace primecount;

Expand Down Expand Up @@ -77,53 +76,51 @@ void check(bool OK)

int main()
{
int64_t x = 1;
for (size_t i = 0; i < RiemannR_table.size(); i++)
{
// The accuracy of RiemannR(x) depends on
// the width of the long double type.
if (i >= std::numeric_limits<long double>::digits10)
break;

x *= 10;
int64_t x = ipow(10ll, 1 + (int) i);
std::cout << "RiemannR(" << x << ") = " << RiemannR(x);
check(RiemannR(x) == RiemannR_table[i]);
}

#if defined(HAVE_FLOAT128) && \
defined(HAVE_INT128_T)

int128_t x128 = ipow((int128_t) 10, 19);
for (size_t i = 0; i < RiemannR_f128.size(); i++)
{
int128_t x = ipow((int128_t) 10, 19 + (int) i);
std::ostringstream oss;
oss << RiemannR(x128);
std::cout << "RiemannR(" << x128 << ") = " << oss.str();
oss << RiemannR(x);
std::cout << "RiemannR(" << x << ") = " << oss.str();
check(oss.str() == RiemannR_f128[i]);
x128 *= 10;
}

#endif

x = 1;
for (size_t i = 0; i < RiemannR_table.size(); i++)
{
// The accuracy of RiemannR(x) depends on
// the width of the long double type.
if (i >= std::numeric_limits<long double>::digits10)
break;

x *= 10;
int64_t x = ipow(10ll, 1 + (int) i);
std::cout << "RiemannR_inverse(" << RiemannR_table[i] << ") = " << RiemannR_inverse(RiemannR_table[i]);
check(RiemannR_inverse(RiemannR_table[i]) < x &&
RiemannR_inverse(RiemannR_table[i] + 1) >= x);
}

// Sanity checks for tiny values of RiemannR(x)
int64_t x;
for (x = 0; x < 10000; x++)
{
int64_t rix = RiemannR(x);
double logx = std::log(max((double) x, 2.0));
double logx = std::log(std::max((double) x, 2.0));

if (rix < 0 ||
(x >= 20 && rix < x / logx) ||
Expand All @@ -138,7 +135,7 @@ int main()
for (; x < 100000; x += 101)
{
int64_t rix = RiemannR(x);
double logx = std::log(max((double) x, 2.0));
double logx = std::log(std::max((double) x, 2.0));

if (rix < 0 ||
(x >= 20 && rix < x / logx) ||
Expand Down

0 comments on commit 28d5b76

Please sign in to comment.