-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlowMath.cs
More file actions
20 lines (15 loc) · 730 Bytes
/
SlowMath.cs
File metadata and controls
20 lines (15 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System.Globalization;
using ExtendedNumerics;
namespace EasySourceGenerators.Examples;
public static class SlowMath
{
public static int CalculatePiDecimal(int decimalNumber)
{
if (decimalNumber < 0) throw new ArgumentOutOfRangeException(nameof(decimalNumber), "Decimal number must be non-negative.");
if (decimalNumber == 0) return 3;
BigDecimal pi = BigDecimal.ApproximatePi(decimalNumber + 1);
if(pi.DecimalPlaces < decimalNumber) throw new ArgumentException($"Failed to calculate pi to {decimalNumber} decimal places.");
string piString = pi.ToString(CultureInfo.InvariantCulture);
return int.Parse(piString.Substring(decimalNumber + 1, 1));
}
}