From 5aacc82282996be0d0c2eedccc29c9bd806ab23f Mon Sep 17 00:00:00 2001 From: Kim Walisch Date: Mon, 17 Jun 2024 18:36:05 +0200 Subject: [PATCH] Rename namespace port to pstd --- ChangeLog | 4 +++ include/FactorTable.hpp | 4 +-- include/FactorTableD.hpp | 4 +-- include/PhiTiny.hpp | 4 +-- include/fast_div.hpp | 20 +++++++-------- include/imath.hpp | 16 ++++++------ include/int128_t.hpp | 30 +++++++++++------------ include/isqrt.hpp | 4 +-- include/min.hpp | 12 ++++----- src/LogarithmicIntegral.cpp | 8 +++--- src/P2.cpp | 2 +- src/PhiTiny.cpp | 2 +- src/RiemannR.cpp | 10 ++++---- src/S1.cpp | 2 +- src/Sieve.cpp | 2 +- src/api.cpp | 8 +++--- src/app/CmdOptions.hpp | 2 +- src/app/main.cpp | 22 ++++++++--------- src/deleglise-rivat/S2_easy.cpp | 2 +- src/deleglise-rivat/S2_easy_libdivide.cpp | 4 +-- src/deleglise-rivat/S2_hard.cpp | 2 +- src/generate.cpp | 2 +- src/gourdon/AC.cpp | 2 +- src/gourdon/AC_libdivide.cpp | 6 ++--- src/gourdon/D.cpp | 2 +- src/gourdon/Phi0.cpp | 2 +- src/util.cpp | 2 +- test/Li.cpp | 8 +++--- test/Riemann_R.cpp | 8 +++--- test/fast_div.cpp | 4 +-- test/gourdon/FactorTableD.cpp | 2 +- test/int128.cpp | 22 ++++++++--------- test/isqrt.cpp | 16 ++++++------ test/isqrt_constexpr.cpp | 20 +++++++-------- test/lmo/FactorTable.cpp | 2 +- 35 files changed, 133 insertions(+), 129 deletions(-) diff --git a/ChangeLog b/ChangeLog index c43829d2..d5fb33ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Changes in primecount-7.14, 2024-06-17 + +* int128_t.hpp: Rename namespace port to pstd (portable std namespace). + Changes in primecount-7.13, 2024-04-15 * Add preliminary MSVC 128-bit support. diff --git a/include/FactorTable.hpp b/include/FactorTable.hpp index 07af0eab..9bfc541e 100644 --- a/include/FactorTable.hpp +++ b/include/FactorTable.hpp @@ -71,7 +71,7 @@ class FactorTable : public BaseFactorTable throw primecount_error("y must be <= FactorTable::max()"); y = std::max(1, y); - T T_MAX = port::numeric_limits::max(); + T T_MAX = pstd::numeric_limits::max(); factor_.resize(to_index(y) + 1); // mu(1) = 1. @@ -189,7 +189,7 @@ class FactorTable : public BaseFactorTable static maxint_t max() { - maxint_t T_MAX = port::numeric_limits::max(); + maxint_t T_MAX = pstd::numeric_limits::max(); return ipow<2>(T_MAX - 1) - 1; } diff --git a/include/FactorTableD.hpp b/include/FactorTableD.hpp index a708e3a5..c59a91fd 100644 --- a/include/FactorTableD.hpp +++ b/include/FactorTableD.hpp @@ -75,7 +75,7 @@ class FactorTableD : public BaseFactorTable throw primecount_error("z must be <= FactorTable::max()"); z = std::max(1, z); - T T_MAX = port::numeric_limits::max(); + T T_MAX = pstd::numeric_limits::max(); factor_.resize(to_index(z) + 1); // mu(1) = 1. @@ -224,7 +224,7 @@ class FactorTableD : public BaseFactorTable static maxint_t max() { - maxint_t T_MAX = port::numeric_limits::max(); + maxint_t T_MAX = pstd::numeric_limits::max(); return ipow<2>(T_MAX - 1) - 1; } diff --git a/include/PhiTiny.hpp b/include/PhiTiny.hpp index 850cc306..01d187c3 100644 --- a/include/PhiTiny.hpp +++ b/include/PhiTiny.hpp @@ -42,7 +42,7 @@ class PhiTiny : public BitSieve240 // Unsigned integer division is usually // faster than signed integer division, // especially for int128_t. - using UT = typename port::make_unsigned::type; + using UT = typename pstd::make_unsigned::type; if (a < max_a()) return phi((UT) x, a); @@ -182,7 +182,7 @@ phi_tiny(T x, uint64_t a) { // If possible use smaller integer type // to speed up integer division. - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return phiTiny.phi_recursive((uint64_t) x, a); else return phiTiny.phi_recursive(x, a); diff --git a/include/fast_div.hpp b/include/fast_div.hpp index af4c64ca..e4de2b3e 100644 --- a/include/fast_div.hpp +++ b/include/fast_div.hpp @@ -44,18 +44,18 @@ fast_div(X x, Y y) #if defined(ENABLE_DIV32) - using UX = typename port::make_unsigned::type; - using UY = typename port::make_unsigned::type; + using UX = typename pstd::make_unsigned::type; + using UY = typename pstd::make_unsigned::type; - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return uint32_t(x) / UY(y); else return UX(x) / UY(y); #else // Unsigned integer division is usually // faster than signed integer division. - using UX = typename port::make_unsigned::type; - using UY = typename port::make_unsigned::type; + using UX = typename pstd::make_unsigned::type; + using UY = typename pstd::make_unsigned::type; return UX(x) / UY(y); #endif } @@ -72,8 +72,8 @@ fast_div(X x, Y y) // Unsigned integer division is usually // faster than signed integer division. - using UX = typename port::make_unsigned::type; - using UY = typename port::make_unsigned::type; + using UX = typename pstd::make_unsigned::type; + using UY = typename pstd::make_unsigned::type; return UX(x) / UY(y); } @@ -89,10 +89,10 @@ fast_div(X x, Y y) // Unsigned integer division is usually // faster than signed integer division. - using UX = typename port::make_unsigned::type; - using UY = typename port::make_unsigned::type; + using UX = typename pstd::make_unsigned::type; + using UY = typename pstd::make_unsigned::type; - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return uint64_t(x) / UY(y); else return UX(x) / UY(y); diff --git a/include/imath.hpp b/include/imath.hpp index 51e2feeb..857a7906 100644 --- a/include/imath.hpp +++ b/include/imath.hpp @@ -43,7 +43,7 @@ template inline T next_power_of_2(T x) { #if __cplusplus >= 202002L - using UT = typename port::make_unsigned::type; + using UT = typename pstd::make_unsigned::type; return std::bit_ceil((UT) x); #elif __has_builtin(__builtin_clzll) @@ -51,7 +51,7 @@ inline T next_power_of_2(T x) return 1; static_assert(sizeof(T) <= sizeof(unsigned long long), "Unsupported type, wider than long long!"); - auto bits = port::numeric_limits::digits; + auto bits = pstd::numeric_limits::digits; auto shift = bits - __builtin_clzll(x - 1); return (T) (1ull << shift); @@ -60,8 +60,8 @@ inline T next_power_of_2(T x) return 1; x--; - using UT = typename port::make_unsigned::type; - T bits = port::numeric_limits::digits; + using UT = typename pstd::make_unsigned::type; + T bits = pstd::numeric_limits::digits; for (T i = 1; i < bits; i += i) x |= (x >> i); @@ -80,14 +80,14 @@ template inline T ilog2(T x) { #if __cplusplus >= 202002L - using UT = typename port::make_unsigned::type; + using UT = typename pstd::make_unsigned::type; auto ux = (UT) x; ux = (ux > 0) ? ux : 1; return std::bit_width(ux) - 1; #elif __has_builtin(__builtin_clzll) static_assert(sizeof(T) <= sizeof(unsigned long long), "Unsupported type, wider than long long!"); - auto bits = port::numeric_limits::digits; + auto bits = pstd::numeric_limits::digits; // Workaround to avoid undefined behavior, // __builtin_clz(0) is undefined. @@ -95,8 +95,8 @@ inline T ilog2(T x) return (T) ((bits - 1) - __builtin_clzll(x)); #else - using UT = typename port::make_unsigned::type; - T bits = port::numeric_limits::digits; + using UT = typename pstd::make_unsigned::type; + T bits = pstd::numeric_limits::digits; T log2 = 0; for (T i = bits / 2; i > 0; i /= 2) diff --git a/include/int128_t.hpp b/include/int128_t.hpp index daf35aa3..c1927340 100644 --- a/include/int128_t.hpp +++ b/include/int128_t.hpp @@ -103,18 +103,18 @@ using std::to_string; // This is required for GCC/Clang if the user compiles with -std=c++* // instead of -std=gnu++* and also for LLVM/Clang on Windows. namespace { -namespace port { +namespace pstd { using namespace primecount; -// port::is_same +// pstd::is_same template struct is_same : std::false_type {}; template struct is_same : std::true_type {}; -// port::conditional +// pstd::conditional template struct conditional { using type = T; @@ -125,7 +125,7 @@ struct conditional { using type = F; }; -// port::is_integral +// pstd::is_integral template struct is_integral { static constexpr bool value = std::is_integral::value; }; @@ -135,7 +135,7 @@ template struct is_integral { template<> struct is_integral : std::true_type {}; #endif -// port::is_floating_point +// pstd::is_floating_point template struct is_floating_point { static constexpr bool value = std::is_floating_point::value; }; @@ -145,7 +145,7 @@ template struct is_floating_point { template<> struct is_floating_point : std::false_type {}; #endif -// port::is_signed +// pstd::is_signed template struct is_signed { static constexpr bool value = std::is_signed::value; }; @@ -155,7 +155,7 @@ template struct is_signed { template<> struct is_signed : std::false_type {}; #endif -// port::is_unsigned +// pstd::is_unsigned template struct is_unsigned { static constexpr bool value = std::is_unsigned::value; }; @@ -165,7 +165,7 @@ template struct is_unsigned { template<> struct is_unsigned : std::true_type {}; #endif -// port::make_unsigned +// pstd::make_unsigned template struct make_unsigned { using type = typename std::make_unsigned::type; }; @@ -175,13 +175,13 @@ template struct make_unsigned { template<> struct make_unsigned { using type = uint128_t; }; #endif -// port::numeric_limits +// pstd::numeric_limits template struct numeric_limits { - static constexpr T min() { return std::numeric_limits::min(); } - static constexpr T max() { return std::numeric_limits::max(); } - static constexpr T infinity() { return std::numeric_limits::infinity(); } - static constexpr T epsilon() { return std::numeric_limits::epsilon(); } - static constexpr int digits = std::numeric_limits::digits; + static constexpr T min() { return std::numeric_limits::min(); } + static constexpr T max() { return std::numeric_limits::max(); } + static constexpr T infinity() { return std::numeric_limits::infinity(); } + static constexpr T epsilon() { return std::numeric_limits::epsilon(); } + static constexpr int digits = std::numeric_limits::digits; }; #if defined(HAVE_INT128_T) @@ -200,7 +200,7 @@ template struct numeric_limits { }; #endif -} // namespace port +} // namespace pstd } // namespace #if defined(HAVE_INT128_T) && \ diff --git a/include/isqrt.hpp b/include/isqrt.hpp index fd6e07e8..27c0a8a5 100644 --- a/include/isqrt.hpp +++ b/include/isqrt.hpp @@ -112,12 +112,12 @@ ALWAYS_INLINE T isqrt(T x) // time in all cases i.e. even if sqrt_max were declared // without constexpr. // - constexpr T sqrt_max = ct_sqrt(port::numeric_limits::max()); + constexpr T sqrt_max = ct_sqrt(pstd::numeric_limits::max()); // For 128-bit integers we use uint64_t as the // result type. For all other types we use the // same result type as the input type. - using R = typename port::conditional::type; + using R = typename pstd::conditional::type; R r = (R) std::min(s, sqrt_max); // In my tests the first corrections were needed above diff --git a/include/min.hpp b/include/min.hpp index ffdcc5e3..6ea9a110 100644 --- a/include/min.hpp +++ b/include/min.hpp @@ -22,9 +22,9 @@ template struct is_comparable { enum { - value = port::is_same::value || ( - port::is_integral::value && - port::is_integral::value && + value = pstd::is_same::value || ( + pstd::is_integral::value && + pstd::is_integral::value && sizeof(A) >= sizeof(B)) }; }; @@ -33,9 +33,9 @@ template struct is_comparable_3 { enum { - value = port::is_integral::value && - port::is_integral::value && - port::is_integral::value && + value = pstd::is_integral::value && + pstd::is_integral::value && + pstd::is_integral::value && sizeof(A) >= sizeof(B) && sizeof(B) >= sizeof(C) }; diff --git a/src/LogarithmicIntegral.cpp b/src/LogarithmicIntegral.cpp index cf32dbe3..cf04c0a0 100644 --- a/src/LogarithmicIntegral.cpp +++ b/src/LogarithmicIntegral.cpp @@ -96,7 +96,7 @@ T li(T x) sum += (p / q) * inner_sum; // Not converging anymore - if (std::abs(sum - old_sum) <= port::numeric_limits::epsilon()) + if (std::abs(sum - old_sum) <= pstd::numeric_limits::epsilon()) break; } @@ -129,7 +129,7 @@ T Li_inverse(T x) return 0; T t = initialNthPrimeApprox(x); - T old_term = port::numeric_limits::infinity(); + T old_term = pstd::numeric_limits::infinity(); // The condition i < ITERS is required in case the computation // does not converge. This happened on Linux i386 where @@ -290,8 +290,8 @@ T Li_inverse_overflow_check(T x) FLOAT res = Li_inverse((FLOAT) x); // Prevent integer overflow - if (res > (FLOAT) port::numeric_limits::max()) - return port::numeric_limits::max(); + if (res > (FLOAT) pstd::numeric_limits::max()) + return pstd::numeric_limits::max(); else return (T) res; } diff --git a/src/P2.cpp b/src/P2.cpp index 9497fabe..118e4a02 100644 --- a/src/P2.cpp +++ b/src/P2.cpp @@ -107,7 +107,7 @@ T P2_OpenMP(T x, // \sum_{i=a+1}^{b} -(i - 1) T sum = (a - 2) * (a + 1) / 2 - (b - 2) * (b + 1) / 2; - static_assert(port::is_signed::value, "T must be signed integer type"); + static_assert(pstd::is_signed::value, "T must be signed integer type"); int64_t xy = (int64_t)(x / max(y, 1)); LoadBalancerP2 loadBalancer(x, xy, threads, is_print); diff --git a/src/PhiTiny.cpp b/src/PhiTiny.cpp index 2a87b9ee..87195851 100644 --- a/src/PhiTiny.cpp +++ b/src/PhiTiny.cpp @@ -68,7 +68,7 @@ PhiTiny::PhiTiny() for (uint64_t x = 1; x < pp; x++) { uint64_t phi_xa = phi(x, a - 1) - phi(x / primes[a], a - 1); - ASSERT(phi_xa <= port::numeric_limits::max()); + ASSERT(phi_xa <= pstd::numeric_limits::max()); phi_[a][x] = (uint8_t) phi_xa; } } diff --git a/src/RiemannR.cpp b/src/RiemannR.cpp index cc63301f..251b9369 100644 --- a/src/RiemannR.cpp +++ b/src/RiemannR.cpp @@ -46,7 +46,7 @@ namespace { const primecount::Array zeta = { -0.500000000000000000000000000000000000000L, - port::numeric_limits::infinity(), + pstd::numeric_limits::infinity(), 1.644934066848226436472415166646025189219L, 1.202056903159594285399738161511449990765L, 1.082323233711138191516003696541167902775L, @@ -214,7 +214,7 @@ T RiemannR(T x) if (x < T(1e-5)) return 0; - T epsilon = port::numeric_limits::epsilon(); + T epsilon = pstd::numeric_limits::epsilon(); T sum = 1; T term = 1; T logx = std::log(x); @@ -254,7 +254,7 @@ T RiemannR_inverse(T x) return 0; T t = initialNthPrimeApprox(x); - T old_term = port::numeric_limits::infinity(); + T old_term = pstd::numeric_limits::infinity(); // The condition i < ITERS is required in case the computation // does not converge. This happened on Linux i386 where @@ -524,8 +524,8 @@ T RiemannR_inverse_overflow_check(T x) FLOAT res = RiemannR_inverse((FLOAT) x); // Prevent integer overflow - if (res > (FLOAT) port::numeric_limits::max()) - return port::numeric_limits::max(); + if (res > (FLOAT) pstd::numeric_limits::max()) + return pstd::numeric_limits::max(); else return (T) res; } diff --git a/src/S1.cpp b/src/S1.cpp index 6938c274..67f7555b 100644 --- a/src/S1.cpp +++ b/src/S1.cpp @@ -134,7 +134,7 @@ int128_t S1(int128_t x, int128_t s1; // uses less memory - if (y <= port::numeric_limits::max()) + if (y <= pstd::numeric_limits::max()) s1 = S1_OpenMP(x, (uint32_t) y, c, threads); else s1 = S1_OpenMP(x, y, c, threads); diff --git a/src/Sieve.cpp b/src/Sieve.cpp index 640e41fe..ce3705d5 100644 --- a/src/Sieve.cpp +++ b/src/Sieve.cpp @@ -325,7 +325,7 @@ void Sieve::allocate_counter(uint64_t low) // only counts the number of unsieved elements (1 bits) in // an interval of size: sieve_limit^(1/4) * sqrt(240). // Hence the max(counter value) = 2^18. - ASSERT(bytes * 8 <= port::numeric_limits::max()); + ASSERT(bytes * 8 <= pstd::numeric_limits::max()); uint64_t counter_size = ceil_div(sieve_.size(), bytes); counter_.counter.resize(counter_size); counter_.dist = bytes * 30; diff --git a/src/api.cpp b/src/api.cpp index 9e13abea..7644707a 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -127,7 +127,7 @@ int128_t pi(int128_t x, int threads) return 0; // Use 64-bit if possible - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return pi((int64_t) x, threads); else return pi_gourdon_128(x, threads); @@ -141,7 +141,7 @@ int128_t pi_deleglise_rivat(int128_t x, int threads) return 0; // Use 64-bit if possible - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return pi_deleglise_rivat_64((int64_t) x, threads); else return pi_deleglise_rivat_128(x, threads); @@ -155,7 +155,7 @@ int128_t pi_gourdon(int128_t x, int threads) return 0; // Use 64-bit if possible - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return pi_gourdon_64((int64_t) x, threads); else return pi_gourdon_128(x, threads); @@ -191,7 +191,7 @@ maxint_t get_max_x(double alpha_y) return (int128_t) max_x; #else unused_param(alpha_y); - return port::numeric_limits::max(); + return pstd::numeric_limits::max(); #endif } diff --git a/src/app/CmdOptions.hpp b/src/app/CmdOptions.hpp index b30d3ff5..3d928a22 100644 --- a/src/app/CmdOptions.hpp +++ b/src/app/CmdOptions.hpp @@ -81,7 +81,7 @@ struct Option T to() const { try { - if (port::is_floating_point::value) + if (pstd::is_floating_point::value) return (T) std::stod(val); else return (T) to_maxint(val); diff --git a/src/app/main.cpp b/src/app/main.cpp index 1817daef..faca6f83 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -43,7 +43,7 @@ namespace primecount { int64_t to_int64(maxint_t x) { - if (x > port::numeric_limits::max()) + if (x > pstd::numeric_limits::max()) throw primecount_error("x must be < 2^63"); return (int64_t) x; } @@ -81,7 +81,7 @@ maxint_t AC(maxint_t x, int threads) if (is_print()) set_print_variables(true); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return AC((int64_t) x, y, z, k, threads); else return AC(x, y, z, k, threads); @@ -111,7 +111,7 @@ maxint_t B(maxint_t x, int threads) if (is_print()) set_print_variables(true); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return B((int64_t) x, y, threads); else return B(x, y, threads); @@ -150,7 +150,7 @@ maxint_t D(maxint_t x, int threads) if (is_print()) set_print_variables(true); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return D((int64_t) x, y, z, k, (int64_t) Li(x), threads); else return D(x, y, z, k, Li(x), threads); @@ -189,7 +189,7 @@ maxint_t Phi0(maxint_t x, int threads) if (is_print()) set_print_variables(true); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return Phi0((int64_t) x, y, z, k, threads); else return Phi0(x, y, z, k, threads); @@ -219,7 +219,7 @@ maxint_t Sigma(maxint_t x, int threads) if (is_print()) set_print_variables(true); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return Sigma((int64_t) x, y, threads); else return Sigma(x, y, threads); @@ -242,7 +242,7 @@ maxint_t P2(maxint_t x, int threads) int64_t y = (int64_t) (iroot<3>(x) * alpha); int64_t a = pi_noprint(y, threads); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return P2((int64_t) x, y, a, threads); else return P2(x, y, a, threads); @@ -265,7 +265,7 @@ maxint_t S1(maxint_t x, int threads) int64_t y = (int64_t) (iroot<3>(x) * alpha); int64_t c = PhiTiny::get_c(y); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return S1((int64_t) x, y, c, threads); else return S1(x, y, c, threads); @@ -289,7 +289,7 @@ maxint_t S2_trivial(maxint_t x, int threads) int64_t z = (int64_t) (x / y); int64_t c = PhiTiny::get_c(y); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return S2_trivial((int64_t) x, y, z, c, threads); else return S2_trivial(x, y, z, c, threads); @@ -313,7 +313,7 @@ maxint_t S2_easy(maxint_t x, int threads) int64_t z = (int64_t) (x / y); int64_t c = PhiTiny::get_c(y); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return S2_easy((int64_t) x, y, z, c, threads); else return S2_easy(x, y, z, c, threads); @@ -337,7 +337,7 @@ maxint_t S2_hard(maxint_t x, int threads) int64_t z = (int64_t) (x / y); int64_t c = PhiTiny::get_c(y); - if (x <= port::numeric_limits::max()) + if (x <= pstd::numeric_limits::max()) return S2_hard((int64_t) x, y, z, c, (int64_t) Li(x), threads); else return S2_hard(x, y, z, c, Li(x), threads); diff --git a/src/deleglise-rivat/S2_easy.cpp b/src/deleglise-rivat/S2_easy.cpp index 8dfb0e86..cf5ddf39 100644 --- a/src/deleglise-rivat/S2_easy.cpp +++ b/src/deleglise-rivat/S2_easy.cpp @@ -166,7 +166,7 @@ int128_t S2_easy(int128_t x, int128_t sum; // uses less memory - if (y <= port::numeric_limits::max()) + if (y <= pstd::numeric_limits::max()) { auto primes = generate_primes(y); sum = S2_easy_OpenMP((uint128_t) x, y, z, c, primes, threads, is_print); diff --git a/src/deleglise-rivat/S2_easy_libdivide.cpp b/src/deleglise-rivat/S2_easy_libdivide.cpp index cdfb0fae..4d074665 100644 --- a/src/deleglise-rivat/S2_easy_libdivide.cpp +++ b/src/deleglise-rivat/S2_easy_libdivide.cpp @@ -185,7 +185,7 @@ T S2_easy_OpenMP(T x, int64_t prime = primes[b]; T xp = x / prime; - if (xp <= port::numeric_limits::max()) + if (xp <= pstd::numeric_limits::max()) sum += S2_easy_64(xp, y, z, b, prime, lprimes, pi); else sum += S2_easy_128(xp, y, z, b, prime, primes, pi); @@ -250,7 +250,7 @@ int128_t S2_easy(int128_t x, int128_t sum; // uses less memory - if (y <= port::numeric_limits::max()) + if (y <= pstd::numeric_limits::max()) { auto primes = generate_primes(y); sum = S2_easy_OpenMP((uint128_t) x, y, z, c, primes, threads, is_print); diff --git a/src/deleglise-rivat/S2_hard.cpp b/src/deleglise-rivat/S2_hard.cpp index fd8d9d57..9740768b 100644 --- a/src/deleglise-rivat/S2_hard.cpp +++ b/src/deleglise-rivat/S2_hard.cpp @@ -216,7 +216,7 @@ T S2_hard_OpenMP(T x, { // Unsigned integer division is usually slightly // faster than signed integer division - using UT = typename port::make_unsigned::type; + using UT = typename pstd::make_unsigned::type; thread.start_time(); UT sum = S2_hard_thread((UT) x, y, z, c, primes, pi, factor, thread); diff --git a/src/generate.cpp b/src/generate.cpp index eb9f3c41..a829d2c1 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -101,7 +101,7 @@ Vector generate_lpf(int64_t max) // Deleglise-Rivat prime counting algorithms. And // lfp(1) = +Infinity allows to simplify that algorithm. if (lpf.size() > 1) - lpf[1] = port::numeric_limits::max(); + lpf[1] = pstd::numeric_limits::max(); for (int64_t i = 2; i <= sqrt; i++) if (lpf[i] == 1) diff --git a/src/gourdon/AC.cpp b/src/gourdon/AC.cpp index 4db67511..ef8432c0 100644 --- a/src/gourdon/AC.cpp +++ b/src/gourdon/AC.cpp @@ -382,7 +382,7 @@ int128_t AC(int128_t x, int128_t sum; // uses less memory - if (max_prime <= port::numeric_limits::max()) + if (max_prime <= pstd::numeric_limits::max()) { auto primes = generate_primes(max_prime); sum = AC_OpenMP((uint128_t) x, y, z, k, x_star, max_a_prime, primes, threads, is_print); diff --git a/src/gourdon/AC_libdivide.cpp b/src/gourdon/AC_libdivide.cpp index 2d7ce13e..257d04a8 100644 --- a/src/gourdon/AC_libdivide.cpp +++ b/src/gourdon/AC_libdivide.cpp @@ -428,7 +428,7 @@ T AC_OpenMP(T x, int64_t prime = primes[b]; T xp = x / prime; - if (xp <= port::numeric_limits::max()) + if (xp <= pstd::numeric_limits::max()) sum += C2_64(xlow, xhigh, (uint64_t) xp, y, b, prime, lprimes, pi, segmentedPi); else sum += C2_128(xlow, xhigh, xp, y, b, primes, pi, segmentedPi); @@ -440,7 +440,7 @@ T AC_OpenMP(T x, int64_t prime = primes[b]; T xp = x / prime; - if (xp <= port::numeric_limits::max()) + if (xp <= pstd::numeric_limits::max()) sum += A_64(xlow, xhigh, (uint64_t) xp, y, prime, lprimes, pi, segmentedPi); else sum += A_128(xlow, xhigh, xp, y, prime, primes, pi, segmentedPi); @@ -513,7 +513,7 @@ int128_t AC(int128_t x, int128_t sum; // uses less memory - if (max_prime <= port::numeric_limits::max()) + if (max_prime <= pstd::numeric_limits::max()) { auto primes = generate_primes(max_prime); sum = AC_OpenMP((uint128_t) x, y, z, k, x_star, max_a_prime, primes, threads, is_print); diff --git a/src/gourdon/D.cpp b/src/gourdon/D.cpp index 1099269f..bb6052e6 100644 --- a/src/gourdon/D.cpp +++ b/src/gourdon/D.cpp @@ -210,7 +210,7 @@ T D_OpenMP(T x, { // Unsigned integer division is usually slightly // faster than signed integer division - using UT = typename port::make_unsigned::type; + using UT = typename pstd::make_unsigned::type; thread.start_time(); UT sum = D_thread((UT) x, x_star, xz, y, z, k, primes, pi, factor, thread); diff --git a/src/gourdon/Phi0.cpp b/src/gourdon/Phi0.cpp index 191192ed..bb9be694 100644 --- a/src/gourdon/Phi0.cpp +++ b/src/gourdon/Phi0.cpp @@ -143,7 +143,7 @@ int128_t Phi0(int128_t x, int128_t phi0; // uses less memory - if (y <= port::numeric_limits::max()) + if (y <= pstd::numeric_limits::max()) phi0 = Phi0_OpenMP(x, (uint32_t) y, z, k, threads); else phi0 = Phi0_OpenMP(x, y, z, k, threads); diff --git a/src/util.cpp b/src/util.cpp index c652baa1..68267d80 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -113,7 +113,7 @@ maxint_t to_maxint(const std::string& expr) if (pos != std::string::npos) { std::string n = expr.substr(pos); - maxint_t limit = port::numeric_limits::max(); + maxint_t limit = pstd::numeric_limits::max(); std::string max_n = to_string(limit); if (n.size() > max_n.size() || diff --git a/test/Li.cpp b/test/Li.cpp index 28691edd..1c8748c7 100644 --- a/test/Li.cpp +++ b/test/Li.cpp @@ -249,9 +249,9 @@ int main() } { - int64_t x = port::numeric_limits::max() / 10; + int64_t x = pstd::numeric_limits::max() / 10; int64_t res = Li_inverse(x); - if (res != port::numeric_limits::max()) + if (res != pstd::numeric_limits::max()) { std::cout << "Li_inverse(" << x << ") != INT64_MAX, failed to prevent integer overflow!" << std::endl; std::exit(1); @@ -260,9 +260,9 @@ int main() #if defined(HAVE_INT128_T) { - int128_t x = port::numeric_limits::max() / 10; + int128_t x = pstd::numeric_limits::max() / 10; int128_t res = Li_inverse(x); - if (res != port::numeric_limits::max()) + if (res != pstd::numeric_limits::max()) { std::cout << "Li_inverse(" << x << ") != INT128_MAX, failed to prevent integer overflow!" << std::endl; std::exit(1); diff --git a/test/Riemann_R.cpp b/test/Riemann_R.cpp index 21087319..c761856d 100644 --- a/test/Riemann_R.cpp +++ b/test/Riemann_R.cpp @@ -252,9 +252,9 @@ int main() } { - int64_t x = port::numeric_limits::max() / 10; + int64_t x = pstd::numeric_limits::max() / 10; int64_t res = RiemannR_inverse(x); - if (res != port::numeric_limits::max()) + if (res != pstd::numeric_limits::max()) { std::cout << "RiemannR_inverse(" << x << ") != INT64_MAX, failed to prevent integer overflow!" << std::endl; std::exit(1); @@ -263,9 +263,9 @@ int main() #if defined(HAVE_INT128_T) { - int128_t x = port::numeric_limits::max() / 10; + int128_t x = pstd::numeric_limits::max() / 10; int128_t res = RiemannR_inverse(x); - if (res != port::numeric_limits::max()) + if (res != pstd::numeric_limits::max()) { std::cout << "RiemannR_inverse(" << x << ") != INT128_MAX, failed to prevent integer overflow!" << std::endl; std::exit(1); diff --git a/test/fast_div.cpp b/test/fast_div.cpp index 556455d6..356a22ef 100644 --- a/test/fast_div.cpp +++ b/test/fast_div.cpp @@ -30,8 +30,8 @@ int main() std::random_device rd; std::mt19937 gen(rd()); - std::uniform_int_distribution dist_i32(1, port::numeric_limits::max()); - std::uniform_int_distribution dist_u64(0, port::numeric_limits::max()); + std::uniform_int_distribution dist_i32(1, pstd::numeric_limits::max()); + std::uniform_int_distribution dist_u64(0, pstd::numeric_limits::max()); // Test unsigned/signed for (int i = 0; i < 10000; i++) diff --git a/test/gourdon/FactorTableD.cpp b/test/gourdon/FactorTableD.cpp index 4f5bf4dc..3202b3d9 100644 --- a/test/gourdon/FactorTableD.cpp +++ b/test/gourdon/FactorTableD.cpp @@ -47,7 +47,7 @@ int main() auto mu = generate_moebius(z); FactorTableD factorTable(y, z, threads); - int64_t uint16_max = port::numeric_limits::max(); + int64_t uint16_max = pstd::numeric_limits::max(); int64_t limit = factorTable.first_coprime(); std::vector small_primes = { 2, 3, 5, 7, 11, 13, 17, 19 }; diff --git a/test/int128.cpp b/test/int128.cpp index 4fa956aa..5ce2e66e 100644 --- a/test/int128.cpp +++ b/test/int128.cpp @@ -35,25 +35,25 @@ int main() { #if defined(HAVE_INT128_T) - static_assert(port::numeric_limits::max() == ~((uint128_t) 0), - "port::numeric_limits::max() is broken"); + static_assert(pstd::numeric_limits::max() == ~((uint128_t) 0), + "pstd::numeric_limits::max() is broken"); - static_assert(port::is_integral::value, + static_assert(pstd::is_integral::value, "is_integral != true"); - static_assert(port::is_integral::value, + static_assert(pstd::is_integral::value, "is_integral != true"); - static_assert(port::is_signed::value, + static_assert(pstd::is_signed::value, "is_signed != true"); - static_assert(!port::is_signed::value, + static_assert(!pstd::is_signed::value, "is_signed != false"); - static_assert(!port::is_unsigned::value, + static_assert(!pstd::is_unsigned::value, "is_unsigned != false"); - static_assert(port::is_unsigned::value, + static_assert(pstd::is_unsigned::value, "is_unsigned != true"); { @@ -65,21 +65,21 @@ int main() { std::ostringstream s; - s << port::numeric_limits::min() + 1; + s << pstd::numeric_limits::min() + 1; std::cout << "-2^127+1 = " << s.str(); check(s.str() == "-170141183460469231731687303715884105727"); } { std::ostringstream s; - s << port::numeric_limits::max(); + s << pstd::numeric_limits::max(); std::cout << "2^127-1 = " << s.str(); check(s.str() == "170141183460469231731687303715884105727"); } { std::ostringstream s; - s << port::numeric_limits::max(); + s << pstd::numeric_limits::max(); std::cout << "2^128-1 = " << s.str(); check(s.str() == "340282366920938463463374607431768211455"); } diff --git a/test/isqrt.cpp b/test/isqrt.cpp index ee5ba2be..57279ec2 100644 --- a/test/isqrt.cpp +++ b/test/isqrt.cpp @@ -63,42 +63,42 @@ int main() std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 1000000000); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 11); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 15); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 181); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 255); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 46340); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 65535); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 3037000499ll); - n = port::numeric_limits::max(); + n = pstd::numeric_limits::max(); res1 = isqrt(n); std::cout << "isqrt(" << n << ") = " << res1; check(res1 == 4294967295ull); diff --git a/test/isqrt_constexpr.cpp b/test/isqrt_constexpr.cpp index 037ca7ab..c8d30f94 100644 --- a/test/isqrt_constexpr.cpp +++ b/test/isqrt_constexpr.cpp @@ -103,19 +103,19 @@ int main() static_assert(ct_sqrt(9223372037000250000ull) == 3037000500ull, "ct_sqrt(3037000500^2) failed!"); static_assert(ct_sqrt(9223372037000250001ull) == 3037000500ull, "ct_sqrt(3037000500^2+1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 11, "ct_sqrt(2^7-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 15, "ct_sqrt(2^8-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 181, "ct_sqrt(2^15-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 255, "ct_sqrt(2^16-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 46340, "ct_sqrt(2^31-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 65535, "ct_sqrt(2^32-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 3037000499ll, "ct_sqrt(2^63-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 4294967295ull, "ct_sqrt(2^64-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 11, "ct_sqrt(2^7-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 15, "ct_sqrt(2^8-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 181, "ct_sqrt(2^15-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 255, "ct_sqrt(2^16-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 46340, "ct_sqrt(2^31-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 65535, "ct_sqrt(2^32-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 3037000499ll, "ct_sqrt(2^63-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 4294967295ull, "ct_sqrt(2^64-1) failed!"); #if defined(HAVE_INT128_T) - static_assert(ct_sqrt(port::numeric_limits::max()) == 13043817825332782212ull, "ct_sqrt(2^127-1) failed!"); - static_assert(ct_sqrt(port::numeric_limits::max()) == 18446744073709551615ull, "ct_sqrt(2^128-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 13043817825332782212ull, "ct_sqrt(2^127-1) failed!"); + static_assert(ct_sqrt(pstd::numeric_limits::max()) == 18446744073709551615ull, "ct_sqrt(2^128-1) failed!"); // here std::sqrt((double) 443075998594972078030832658571409090) is 1 too small static_assert(ct_sqrt((((int128_t) 24019198012642651) << 64) | 15864680554123835074ull) == 665639541039271553ll, "ct_sqrt(443075998594972078030832658571409090) failed!"); diff --git a/test/lmo/FactorTable.cpp b/test/lmo/FactorTable.cpp index aaa8f02f..3ad76eff 100644 --- a/test/lmo/FactorTable.cpp +++ b/test/lmo/FactorTable.cpp @@ -44,7 +44,7 @@ int main() auto mu = generate_moebius(max); FactorTable factorTable(max, threads); - int64_t uint16_max = port::numeric_limits::max(); + int64_t uint16_max = pstd::numeric_limits::max(); int64_t limit = factorTable.first_coprime(); std::vector small_primes = { 2, 3, 5, 7, 11, 13, 17, 19 };