c++ to c# prob....
Hi,
I have this in c++:
float len = float(sqrt(x*y));
if(len)
{
...
}
how can do this if statement in c#?
Thanks
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.
ex.
#define THRESHOLD 0.00001
float var = (float) (sqrt(x));
if(var < THRESHOLD){
//blah blah blah
}
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement