My compiler, XCode, gave me the message "Floating point exception," after going through the my code below, then ended the program abruptly.
It goes through other ones that use + instead of - fine, and also runs the one where both +'s and -'s are reversed.
Here is the relevant code (this is the only part that differs from the working code, and is thus the erroneous part)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
if ((double ((newx-oldx)/(newy-oldy)))==-1 && (newx-oldx)>0)
direction=2;
if (direction == 2)
{
for (int t = 0; t<newx-oldx; t++)
{
if(!(!(FindColor(oldx+t, oldy-t)==' ')))
{
test=true;
break;
}
if (test)
break;
}
if (test)
break;
if (!(FindColor(newx, newy)==CharTurn(WTurn)))
ValidMove=true;
}
|
This is as compared to the below, which definitely works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
if ((double((newx-oldx)/(newy-oldy)))==1 && (newx-oldx)>0)
direction=1;
if (direction == 1)
{
for (int t = 0; t<newx-oldx; t++)
{
if(!(!(FindColor(oldx+t, oldy+t)==' ')))
{
test=true;
break;
}
if (test)
break;
}
if (test)
break;
if (!(FindColor(newx, newy)==CharTurn(Wturn)))
ValidMove=true;
}
|
the slope I used was definitely -1 for
double ((newx-oldx)/(newy-oldy)))==-1
so I don't see what the problem is, unless double is unsigned for some reason.
Sorry if my question is unclear, because I am not including all of the code.
Really, my question was just what "Floating point exception" means, and if any of my code would lead to that error.
Thanks.