A better example to look at for vectors is the
// Returns true if the vectors are equal.
public static bool operator==(Vector3 lhs, Vector3 rhs)
// Returns false in the presence of NaN values.
float diff_x = lhs.x - rhs.x;
float diff_y = lhs.y - rhs.y;
float diff_z = lhs.z - rhs.z;
float sqrmag = diff_x * diff_x + diff_y * diff_y + diff_z * diff_z;
return sqrmag < kEpsilon * kEpsilon;
You can see that this applies an approximate-equality check, testing whether their difference has magnitude less than
kEpsilon, or a hundred thousandth of a unit.
This way users get extra tolerance for rounding automatically, even if they do the most careless thing. If the user wants exact equality only, they need to ask for it, by using
Vector3.Equals(). (This also ensures that if you use a vector as a key in a collection like a hash map/dictionary, you won't get spurious collisions from an overly-permissive comparison)
So the definition of
Equals this way isn't the devs saying that
Mathf.Approximately() is unnecessary. In fact it's just the opposite: they're saying that approximate equality checks or range checks should be your default, and you should reach for exact equality only when you're sure that's appropriate for your context, by typing extra to get
.Equals() instead of