Skip to content

Commit adae263

Browse files
xakep139hanabi1224
andauthored
Align C# "edigits" benchmark with other implementations (#459)
Co-authored-by: hanabi1224 <[email protected]>
1 parent e048725 commit adae263

File tree

1 file changed

+7
-4
lines changed
  • bench/algorithm/edigits

1 file changed

+7
-4
lines changed

bench/algorithm/edigits/1.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
class DigitsOfE
55
{
6+
private static readonly double LogOfTau = Math.Log(Math.Tau);
7+
private static readonly double LogOfTen = Math.Log(10);
8+
69
public static void Main(string[] args)
710
{
811
int n;
@@ -45,7 +48,7 @@ public static void Main(string[] args)
4548
{
4649
if (b == a + 1)
4750
{
48-
return (new BigInteger(1), new BigInteger(b));
51+
return (BigInteger.One, new BigInteger(b));
4952
}
5053
var mid = (a + b) / 2;
5154
var (pLeft, qLeft) = SumTerms(a, mid);
@@ -79,12 +82,12 @@ static int BinarySearch(int n)
7982

8083
static bool TestK(int n, int k)
8184
{
82-
if (k < 0)
85+
if (k <= 0)
8386
{
8487
return false;
8588
}
86-
var lnKFactorial = k * (Math.Log((double)k) - 1) + 0.5 * Math.Log(Math.PI * 2);
87-
var log10KFactorial = lnKFactorial / Math.Log(10);
89+
var lnKFactorial = k * (Math.Log((double)k) - 1) + 0.5 * LogOfTau;
90+
var log10KFactorial = lnKFactorial / LogOfTen;
8891
return log10KFactorial >= (double)(n + 50);
8992
}
9093
}

0 commit comments

Comments
 (0)