# Tolerance

Hello everyone!

I have question about Equal Vector and Tolerance.
Tolerance - what is it? I know from UE tips what tolerance is “…a specified error…”, but what does it really mean? How can I calculate it by manual?
I don’t understand why I have different results (if I correct copy/paste log):

Equal vectors is True
X=0.000 Y=1.000 Z=0.000
X=0.293 Y=0.858 Z=0.421

Equal vectors is False
X=0.000 Y=1.000 Z=0.000
X=-0.411 Y=0.359 Z=0.838

Tolerance in both cases is 0.7.

I can not find info in manual? If you can find info, please send link me.

Hi, not sure how much you know about the floats so I’ll start from the basics.

Because of how float variables are stored in computer memory there is a really high chance that 2 float variables declared as 0.7 won’t actually be 0.7000(…) but for example 0.70001 and 0.6999, and that makes default comparison operator unreliable (to say the least). To make that bearable ;D people got an idea that they will check the range instead of 1 value comparison. For example if the variable is somewhere between 6.9f and 7.1f and you’re using 0.7f as base, that would make it a tolerance of 0.1

Having that in mind the vector is just a struct with 3 float so the same rules apply. Here is the code the vector’s Equals() method use:

``````FORCEINLINE bool TVector<T>::Equals(const TVector<T>& V, T Tolerance) const
{
return FMath::Abs(X-V.X) <= Tolerance && FMath::Abs(Y-V.Y) <= Tolerance && FMath::Abs(Z-V.Z) <= Tolerance;
}
``````

As you can see it takes absolute of the difference between the vector you’re calling method on and the checking(?) vector, then checks whether that value is <= your tolerance.

Oh and going back to your example, the one when the method returns false, the difference between Z values is higher than 0.7 that’s why this returns false.

Hope that helps you : )

EDIT: Updated my float explanation.

Hi again.

I know a little about floats.

Do I right understend?

Case True:
0.000-0.293<=0.7 && 1.000-0.858<=0.7 && 0.000-0.421<=0.7
-0.293<=0.7 (True) && 0.142<=0.7 (True) && -0.421<=0.7 (True) - Result - True

Case False:
0.000-(-0.411)<=0.7 && 1.000-0.359<=0.7 && 0.000-0.838<=0.7
0.411<=0.7 (True) && 0.641<=0.7 (True) && -0.838<=0.7 (True) - Result - True, UE Result - False

It seems I have done mistake. Where have I done it? This moment confuse me.

I forgot Abs().
Abs(-0.838) is 0.838. And it isn’t <= 0.7.

Thanks for explanation.

You’re welcome. Glad I was able to help : D