我有计算 pi 的方法。我只是想知道是否可以使用 C#5 的 async/await 功能来加快速度?
public decimal CalculatePi(int measure)
{
var target = measure;
decimal current = 3;
var incrementing = false;
var inner = (decimal)1.0;
while (current < target)
{
if (!incrementing)
{
inner = inner - (1/current);
current += 2;
incrementing = true;
}
if (incrementing)
{
inner = inner + (1/current);
current += 2;
incrementing = false;
}
}
return 4*inner;
}