Skip to content

Commit

Permalink
Align C# "edigits" benchmark with other implementations (#459)
Browse files Browse the repository at this point in the history
Co-authored-by: hanabi1224 <[email protected]>
  • Loading branch information
xakep139 and hanabi1224 authored Jan 22, 2025
1 parent e048725 commit adae263
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bench/algorithm/edigits/1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

class DigitsOfE
{
private static readonly double LogOfTau = Math.Log(Math.Tau);
private static readonly double LogOfTen = Math.Log(10);

public static void Main(string[] args)
{
int n;
Expand Down Expand Up @@ -45,7 +48,7 @@ public static void Main(string[] args)
{
if (b == a + 1)
{
return (new BigInteger(1), new BigInteger(b));
return (BigInteger.One, new BigInteger(b));
}
var mid = (a + b) / 2;
var (pLeft, qLeft) = SumTerms(a, mid);
Expand Down Expand Up @@ -79,12 +82,12 @@ static int BinarySearch(int n)

static bool TestK(int n, int k)
{
if (k < 0)
if (k <= 0)
{
return false;
}
var lnKFactorial = k * (Math.Log((double)k) - 1) + 0.5 * Math.Log(Math.PI * 2);
var log10KFactorial = lnKFactorial / Math.Log(10);
var lnKFactorial = k * (Math.Log((double)k) - 1) + 0.5 * LogOfTau;
var log10KFactorial = lnKFactorial / LogOfTen;
return log10KFactorial >= (double)(n + 50);
}
}

0 comments on commit adae263

Please sign in to comment.