Archived

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

c++ to c# prob....

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

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