How can I speed-up this loop (in C)?
unsigned int x = 50000000;
double a= 0.9;
double b= -0.9;
for ( unsigned int i = 1; i <= x; i++)
{
a *= 0.9; //power
b -= a/i;
}
Execution time: 14.000 s
I don't know why, but when I add this 2 lines in code, execution time is only 1.000 s.
unsigned int x = 50000000;
double a= 0.9;
double b= -0.9;
for ( unsigned int i = 1; i <= x; i++)
{
a *= 0.9; //power
a += 10e250;
a -=10e250;
b -= a/i;
}
Thanks for any help