I would suggest using NearlyEqual for float comparison:
It works fine to me. What is TotalVector?
!= 0 not working in this case?
code :
if (TotalVector.Y != 0)
{
UE_LOG(LogTemp, Warning, TEXT("TotalVector.Y = %f"), TotalVector.Y);
}
result :
anyone had the same experience?
yes, I tried FMath::IsNearlyEqual() and it’s working but I wanna know why != not working ?!
Because there are no absolute values for float; i.e. there’s no 2 but 1.9999999 or 2.0000001 or something like this. Your TotalVector is probably a very small value near zero (but not zero). That’s why we use NearlyEqual to compare float values. Also, look here. It describes the issue with floating values precision:
! operator nagetaes the any boolean value you can use it on variables and function returns so do !FMath::IsNearlyEqual(), or just simply do FMath::IsNearlyEqual() == false
thx for all replies. all help, the links is answer my question.
Thx Ali.