Skip to content

Commit

Permalink
Improve accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 17, 2024
1 parent 1cbd7c6 commit 9e140d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/LogarithmicIntegral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ namespace primecount {
int64_t Li(int64_t x)
{
#if defined(HAVE_FLOAT128)
if (x > 1e10 && std::log2(x) >= std::numeric_limits<long double>::digits)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
return (int64_t) ::Li((__float128) x);
#endif
return (int64_t) ::Li((long double) x);
Expand Down Expand Up @@ -263,7 +264,8 @@ int64_t Li_inverse(int64_t x)
int128_t Li(int128_t x)
{
#if defined(HAVE_FLOAT128)
if (x > 1e10 && std::log2(x) >= std::numeric_limits<long double>::digits)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
return (int128_t) ::Li((__float128) x);
#endif
return (int128_t) ::Li((long double) x);
Expand Down
6 changes: 4 additions & 2 deletions src/RiemannR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ namespace primecount {
int64_t RiemannR(int64_t x)
{
#if defined(HAVE_FLOAT128)
if (x > 1e10 && std::log2(x) >= std::numeric_limits<long double>::digits)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
return (int64_t) ::RiemannR((__float128) x);
#endif
return (int64_t) ::RiemannR((long double) x);
Expand Down Expand Up @@ -587,7 +588,8 @@ int64_t RiemannR_inverse(int64_t x)
int128_t RiemannR(int128_t x)
{
#if defined(HAVE_FLOAT128)
if (x > 1e10 && std::log2(x) >= std::numeric_limits<long double>::digits)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
return (int128_t) ::RiemannR((__float128) x);
#endif
return (int128_t) ::RiemannR((long double) x);
Expand Down

0 comments on commit 9e140d3

Please sign in to comment.