Salinan VS2013 Ultimate saya mengkompilasi kode ini selama 60+ detik:
class Program
{
static void Main(string[] args)
{
double dichotomy = Dichotomy(
d =>
{
try
{
int size = (int) d;
byte[] b = new byte[size];
return -b.Length;
}
catch (Exception)
{
return 0;
}
},
0,
int.MaxValue,
1);
Console.WriteLine(dichotomy);
Console.ReadKey();
}
private static double Dichotomy(
Func<double, double> func,
double a,
double b,
double epsilon)
{
double delta = epsilon / 10;
while (b - a >= epsilon)
{
double middle = (a + b) / 2;
double lambda = middle - delta, mu = middle + delta;
if (func(lambda) < func(mu))
b = mu;
else
a = lambda;
}
return (a + b) / 2;
}
}
Tetapi jika saya mengganti double
dengan int
, itu segera dikompilasi. Bagaimana bisa dijelaskan ...?