Possible Problem with Vector == overload

May 28, 2011 at 6:00 PM

Hi there,

I was working with vectors today and I had the vector(-40,0,0,1) and I wanted to see if it was equal to Vector.Zero.  To my suprise I found it was!  I'm not sure this is correct but before I changed any code I wanted to be sure.

Here is what I found in the vector == overload:

   public static bool operator ==(Vector v1, Vector v2)
   if (+(v1.X - v2.X) < float.Epsilon && +(v1.Y - v2.Y) < float.Epsilon && +(v1.Z - v2.Z) < float.Epsilon)
    return true;
   return false;

for this to work woudn't we need Math.Abs around each of the subtractions?

May 30, 2011 at 8:31 AM

This appears to me to be a bug - further, the writer appears to have the impression that C# has a feature which it does not in fact have.  There is no operator + meaning "mathematical absolute value of the righthand value."  To demonstrate, in a fresh project try this:

int i = +(-2);

Note that the value of 'i' will be -2.  Fortunately, I did a search for "operator +(" and nobody seems to be trying something fishy to implement such a non-intuitive bypass of the math absolute value with floats.