|
|
|
|
|
by pasta
3371 days ago
|
|
Comparing for equality is not tricky because it works: 3.1415927410125732421875 equals 3.1415927410125732421875 The problem is that programmers expect the float to be a decimal (smaller than the float) or integer. For example if you want to calculate that two vectors are parallel then comparing for lesser or greater won't give you the expected result if you need them to be zero in difference. You might think that the vectors (0, 10) and (10, 10) are parallel but using !(x > 0 || x < 0) won't help you. You still end up using a threshold of the smallest float, something like (abs(x - 0) < 0.0000000000000000000001) |
|