For comparing floats they recommend using Mathf.Approximately
At the same time, they don't use it, for example, for comparing types such as vectors.
From Vector3.cs:
public bool Equals(Vector3 other)
{
return x == other.x && y == other.y && z == other.z;
}
If I understand it correctly it wouldn't cause any problem when using ==
operator to compare floats that are formed the same way (or copied from the same source). For example:
float x = 10f / 10f;
float a = x; // or `a = 10f / 10f`;
float b = x;
bool equal = (a == b); // always `true`
but it can cause a problem if floats are formed differently even if their results are supposed to be the same. For example:
float a = 10f / 10f;
float b = 11f - 10f;
bool equal = (a == b); // result is unpredictable
Is my understanding correct?