Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

xyz

c++ to c# prob....

This topic is 5233 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, I have this in c++: float len = float(sqrt(x*y)); if(len) { ... } how can do this if statement in c#? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Having a float as your conditional for an if is not good design, since rounding errors can have even a supposedly 0 value equal to a very small number instead. You should use a threshold if you want to compare a float value to zero
ex.

#define THRESHOLD 0.00001
float var = (float) (sqrt(x));
if(var < THRESHOLD){
//blah blah blah
}

Share this post


Link to post
Share on other sites
No need to define a threshold since .Net already has one.

float len = (float)Math.Sqrt(x*y);
if ((len > - float.Epsilon)&&(len < float.Epsilon))
{
//...Equal to zero
}

[edited by - eagleone on March 18, 2004 2:47:45 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!