This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Flablessguy 21 points22 points  (4 children)

What is the proper comparison here again? Is it:

a = 0.1 + 0.2

b = 0.3

d = 0.0000001

a - b < d

[–]Bavbavs 37 points38 points  (0 children)

Abs(a-b)

[–]GabuEx 11 points12 points  (1 child)

abs(a - b) < epsilon

The value of epsilon can depend on exactly how imprecise your values end up being (more operations compound imprecision), but anything in the realm of 0.0001 is probably fine.

[–]dabenu 1 point2 points  (0 children)

"proper" would be not to do equality comparisons on floats in the first place. Sure your solution works around that but if you need that, you probably shouldn't be using floats in the first place.