-
For floats you can reliably compare less than and greater than. Do not compare them for equality. But you should be able to test when the sign changes using these with no problem.
Perhaps I don't understand the problem.
Code:
bool SignChanged(float fPrevValue,float fCurValue)
{
if ((fPrevValue<0.0f && fCurValue>0.0f) ||
(fPrevValue>0.0f && fCurValue<0.0f) )
{
return true;
} else return false;
}
This won't test for equality but if the result is right at 0.0f it will return false. It will only return true if the sign has changed. Note that due to the way that floats are represented in memory there will be some slight imprecision in this method.
-
Hi, Thanks for all of the replies. I have figured out a solution based upon the first reply to this thread. I have 2 seperate nested loops. I think that all of you know more about coding than I ever will so I won;t embarass myself with it, but here is the basic math I implemented. One loop is for when M>0 the other M<0. I therefore know if I am looking for a change from positive to negative or vice versa. When Y becomes greater than or less than 0 I stop the loop, round the number, and output. It isn't even a little elegant, but hey, chrome doesn't get you home.