Jump to content
  • Advertisement
Sign in to follow this  
renegade weapon

[SDL] Floating Point Exception

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have narrowed the cause of this error down to the following code.
int FindPointOfImpact ()
{
  int slope;
  slope = (ball.y - yimpact) / (ball.x - ximpact);
  return -(ball.y -slope*(ball.x)-bound) / (slope*ball.x);
}  
I'm pretty sure the math is correct... but everytime the function is called, the program crashes.

Share this post


Link to post
Share on other sites
Advertisement
Make sure that you are never dividing by zero. Use some error checking (a handle of if-statements) or exception handling.

Share this post


Link to post
Share on other sites
Yeah, check you are not dividing by zero. Also remember you want to return an int:

int FindPointOfImpact ()

{

float slope;

slope = (ball.y - yimpact) / (ball.x - ximpact);

return (int)(-(ball.y -slope*(ball.x)-bound) / (slope*ball.x));

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!