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 b06bbaf commit 6c273d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/LogarithmicIntegral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int64_t Li(int64_t x)
{
#if defined(HAVE_FLOAT128)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 4)
return (int64_t) ::Li((__float128) x);
#endif
return (int64_t) ::Li((long double) x);
Expand All @@ -239,10 +239,10 @@ int64_t Li_inverse(int64_t x)
if (x > 1e10)
{
double logx = std::log(x);
double n = (double) x * logx * logx * logx;
double n = (double) x * logx * logx;
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;

if (std::log2(n) >= long_double_mantissa_bits)
if (std::log2(n) >= long_double_mantissa_bits - 4)
{
__float128 res = ::Li_inverse((__float128) x);
if (res > (__float128) std::numeric_limits<int64_t>::max())
Expand All @@ -266,7 +266,7 @@ int128_t Li(int128_t x)
{
#if defined(HAVE_FLOAT128)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 4)
return (int128_t) ::Li((__float128) x);
#endif
return (int128_t) ::Li((long double) x);
Expand All @@ -278,10 +278,10 @@ int128_t Li_inverse(int128_t x)
if (x > 1e10)
{
double logx = std::log(x);
double n = (double) x * logx * logx * logx;
double n = (double) x * logx * logx;
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;

if (std::log2(n) >= long_double_mantissa_bits)
if (std::log2(n) >= long_double_mantissa_bits - 4)
{
__float128 res = ::Li_inverse((__float128) x);
if (res > (__float128) std::numeric_limits<int128_t>::max())
Expand Down
12 changes: 6 additions & 6 deletions src/RiemannR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ int64_t RiemannR(int64_t x)
{
#if defined(HAVE_FLOAT128)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 4)
return (int64_t) ::RiemannR((__float128) x);
#endif
return (int64_t) ::RiemannR((long double) x);
Expand All @@ -563,10 +563,10 @@ int64_t RiemannR_inverse(int64_t x)
if (x > 1e10)
{
double logx = std::log(x);
double n = (double) x * logx * logx * logx;
double n = (double) x * logx * logx;
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;

if (std::log2(n) >= long_double_mantissa_bits)
if (std::log2(n) >= long_double_mantissa_bits - 4)
{
__float128 res = ::RiemannR_inverse((__float128) x);
if (res > (__float128) std::numeric_limits<int64_t>::max())
Expand All @@ -590,7 +590,7 @@ int128_t RiemannR(int128_t x)
{
#if defined(HAVE_FLOAT128)
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 3)
if (x > 1e10 && std::log2(x) >= long_double_mantissa_bits - 4)
return (int128_t) ::RiemannR((__float128) x);
#endif
return (int128_t) ::RiemannR((long double) x);
Expand All @@ -602,10 +602,10 @@ int128_t RiemannR_inverse(int128_t x)
if (x > 1e10)
{
double logx = std::log(x);
double n = (double) x * logx * logx * logx;
double n = (double) x * logx * logx;
double long_double_mantissa_bits = std::numeric_limits<long double>::digits;

if (std::log2(n) >= long_double_mantissa_bits)
if (std::log2(n) >= long_double_mantissa_bits - 4)
{
__float128 res = ::RiemannR_inverse((__float128) x);
if (res > (__float128) std::numeric_limits<int128_t>::max())
Expand Down

0 comments on commit 6c273d2

Please sign in to comment.