D
D
Dmitry Korolev2018-09-08 16:20:05
Unity
Dmitry Korolev, 2018-09-08 16:20:05

How does Unity compare two floats for inequality?

I compare heights from two vectors3 for the fact of inequality. what will happen to the comparison if one of the heights loses accuracy?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey V, 2018-09-08
@dthpth

instead of comparing the height values, compare the modulus of their difference with the error of interest, for example:
если модуль(a - b) < 0.0005 -> a равно b

D
Daniil Basmanov, 2018-09-09
@BasmanovDaniil

Vectors are usually subtracted from each other and the sqrMagnitude of the resulting vector is compared with the epsilon, also sometimes magnitude is taken , which is more expensive in calculations, but sometimes gives more accurate results.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question