Jump to content
  • Advertisement
Sign in to follow this  
WonderWorld

rearranging expression

This topic is 5199 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

Hi guys I have this expression dist3 = 1 - (aY - aST->tri2D[2].y) / (aST->tri2D[0].y - aST->tri2D[2].y); The problem with this expression is that it runs the risk of a division by 0. Can someone help me to rearrange it to remove the division? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
dist3 = aST->tri2D[0].y - aST->tri2D[2].y;
dist3 = (dist3 != 0) ? (1 - (aY - aST->tri2D[2].y) / dist3) : DIV_BY_ZERO_VALUE;


Share this post


Link to post
Share on other sites
As Atm97fin implied in a rather concise way, you must manually check to make sure the denominator is not zero. More often than not, division by zero means that the problem can't be solved with the information given. This also means that rearranging the equation will not help. You'll still need to check for a zero denominator and handle that as a special case.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!