Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jan 8, 2024
1 parent cf0cf46 commit e9995b7
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/nthPrimeApprox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,17 @@ namespace primesieve {

uint64_t Li(uint64_t x)
{
auto res = ::Li((long double) x);

// Prevent 64-bit integer overflow
if (res > (long double) std::numeric_limits<uint64_t>::max())
return std::numeric_limits<uint64_t>::max();

return (uint64_t) res;
return (uint64_t) ::Li((long double) x);
}

uint64_t Li_inverse(uint64_t x)
uint64_t Ri(uint64_t x)
{
auto res = ::Li_inverse((long double) x);

// Prevent 64-bit integer overflow
if (res > (long double) std::numeric_limits<uint64_t>::max())
return std::numeric_limits<uint64_t>::max();

return (uint64_t) res;
return (uint64_t) ::Ri((long double) x);
}

uint64_t Ri(uint64_t x)
uint64_t Li_inverse(uint64_t x)
{
auto res = ::Ri((long double) x);
auto res = ::Li_inverse((long double) x);

// Prevent 64-bit integer overflow
if (res > (long double) std::numeric_limits<uint64_t>::max())
Expand Down

0 comments on commit e9995b7

Please sign in to comment.