bool cmpf(float A, float B, float epsilon = 0.005f)
{
return (fabs(A - B) < epsilon);
}
In this instance, why is it 0.005f? I understand the concept of epsilon as it essentially just scales a number between one and another so that the result can be more accurate.
However, why 0.005f? I think it's more of Maths question but I suppose it's something that should be known.
I do not understand how you mean to scale a number between one and another. What I do remember is that "machine epsilon" is the one of the smallest real values that a computer can represent.
When we want to compare 2 elements, we check if their difference is zero. With floats this can become cumbersome; as we may have calculations that; due to algorithmic differences output a different float. Algebraically; they should output the exact same number. This is when epsilon comes in and allows a certain deviation between the two which will still result in equality according to cmpf.