[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python comparing float



Ricardo Franco wrote:
    That's why when you are comparing floating point numbers, you always
    have to check if they are within some small error value from each
    other. How large that value is depends on your particular use case.

It's even better if you can avoid comparing floats for
equality at all. You can do that in this case by using an
integer loop counter and computing the float value from it:

>>> for i in xrange(11):
...    rate = 1.0 + i * 0.1
...    print rate
...
1.0
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0

--
Greg