Skip navigation

In creating a Vector or Matrix4x4 class, it is tempting to think its a good idea to overload the == operator __not__ with an element by element comparison for exact equality (as it __should__ be!) but instead to equate it to some version of a .Near() method (where we check that each element is within some EPSILON of the corresponding element in the other matrix)

It turns out this is __not__ a very good idea for the following reason

Say you want to make a std::map<Matrix> for some reason. Now finding is based on operator== and operator<.

So you have a huge problem if you overloaded operator== to mean “approximately equal”!

More expensive key lookup, (lots of fabs()), and worse, more collisions where you may not want them!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: