I've got a problem with this piece of iterating code:
/* Iterate to apparent position */
while (a1 != aT) {
/* <-- assume a1 == aT here after the 3rd iteration */
a1 = aT;
/* Recalculate position */
Venus_C(JDE - aT);
/* Calculate */
ep = sqrt(pow(Venus_x(), 2) + pow(Venus_y(), 2)
+ pow(Venus_z(), 2));
aT = 0.0057755183 * ep;
}
It's part of an astronomical library which is used in two of my projects. Assume on line 3 that after the 3rd iteration, the two variables, a1 and aT, both of which are type double, are identical. The only problem is...the loop never exits. I even tried putting a printf in there to show that the two variables are the same and yet, it still continues with the loop.
I had no idea how GDB works but when I had it on, I can say that it was of no help at all. Please do not ask why...it just did not help. I decided to use Visual C++'s debugger. That would've helped...except I found out that when I compiled with VC++, it worked as expected. I tried using Cygwin and, remarkably, that also worked. So with that, I pinpointed the problem down to MinGW. Since Cygwin was GCC 4.3.2 rather than 4.4.0, I assumed that GCC 4.4.0 was the culprit. No such luck. Even after downgrading down as far as GCC 3.3.3, I had the exact same problem...the loop just doesn't want to exit.
I would use Cygwin except I can't because one of my 2 projects is not free software (though the other is) along with the fact that I've had NOTHING but trouble when I try to use it with anything else.
Also, it's not just any while loop that fails. ONLY that one fails actually. The following worked perfectly as expected:
double a = 0, b = 20;
while (a != b) {
a+=0.01;
}
Using Code::Blocks IDE 8.02 on Windows XP SP3 with MinGW 5.1.6 and GCC 4.4.0.