Skip to content

Commit

Permalink
Add float128 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 18, 2024
1 parent 4a63e58 commit b194a03
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ file(GLOB files "*.cpp")
foreach(file ${files})
get_filename_component(binary_name ${file} NAME_WE)
add_executable(${binary_name} ${file})
target_compile_definitions(${binary_name} PRIVATE "${DISABLE_INT128}" "${ENABLE_DIV32}" "${ENABLE_ASSERT}")
target_compile_definitions(${binary_name} PRIVATE "${HAVE_FLOAT128}" "${DISABLE_INT128}" "${ENABLE_DIV32}" "${ENABLE_ASSERT}")
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve "${LIB_OPENMP}" "${LIB_ATOMIC}")
add_test(NAME ${binary_name} COMMAND ${binary_name})
endforeach()
Expand Down
49 changes: 43 additions & 6 deletions test/Riemann_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
///

#include <primecount-internal.hpp>
#include <imath.hpp>
#include <int128_t.hpp>

#include <stdint.h>
Expand All @@ -17,6 +18,8 @@
#include <cstdlib>
#include <cmath>
#include <limits>
#include <sstream>
#include <string>
#include <vector>

using std::max;
Expand All @@ -42,10 +45,29 @@ std::vector<int64_t> RiemannR_table =
29844570495886ll, // RiemannR(10^15)
279238341360977ll, // RiemannR(10^16)
2623557157055978ll, // RiemannR(10^17)
24739954284239494ll, // RiemannR(10^18)
234057667300228940ll // RiemannR(10^19)
24739954284239494ll // RiemannR(10^18)
};

#if defined(HAVE_FLOAT128)

std::vector<std::string> RiemannR_f128 =
{
"234057667300228940", // RiemannR(10^19)
"2220819602556027015", // RiemannR(10^20)
"21127269485932299723", // RiemannR(10^21)
"201467286689188773625", // RiemannR(10^22)
"1925320391607837268776", // RiemannR(10^23)
"18435599767347541878146", // RiemannR(10^24)
"176846309399141934626965", // RiemannR(10^25)
"1699246750872419991992147", // RiemannR(10^26)
"16352460426841662910939464", // RiemannR(10^27)
"157589269275973235652219770", // RiemannR(10^28)
"1520698109714271830281953370", // RiemannR(10^29)
"14692398897720432716641650390" // RiemannR(10^30)
};

#endif

void check(bool OK)
{
std::cout << " " << (OK ? "OK" : "ERROR") << "\n";
Expand All @@ -55,31 +77,46 @@ void check(bool OK)

int main()
{
int64_t x = 1;
int64_t x = 10;
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;
std::cout << "RiemannR(" << x << ") = " << RiemannR(x);
check(RiemannR(x) == RiemannR_table[i]);
x *= 10;
}

x = 1;
#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++)
{
std::ostringstream oss;
oss << RiemannR(x128);
std::cout << "RiemannR(" << x128 << ") = " << oss.str();
check(oss.str() == RiemannR_f128[i]);
x128 *= 10;
}

#endif

x = 10;
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;
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);
x *= 10;
}

// Sanity checks for tiny values of RiemannR(x)
Expand Down

0 comments on commit b194a03

Please sign in to comment.