[Bf-python] Vector Comparison Issue
Jonathan Merritt
j.merritt at pgrad.unimelb.edu.au
Tue Sep 20 16:11:40 CEST 2005
Campbell Barton wrote:
> from Blender import Mathutils
> f = 22.0 / 7.0
> vec = Mathutils.Vector(f,0,0)
> print vec.x == f
> ...False
I suppose it's an example of the general rule: "Never do floating point
equality comparisons!"
The general way around this is to check equality up to a reasonable
limit: epsilon. When epsilon is a small number greater than zero:
equal = ((vec.x + epsilon) >= f) and ((vec.x - epsilon) <= f)
Why do you want to check for floating-point equality to begin with
though? Can't you establish "logical equality", between objects or maps
of objects, rather than "numerical equality"?
Jonathan Merritt.
More information about the Bf-python
mailing list