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

Re: [pygame] Python comparing float



Alternatively, in the numpy module (part of the Scientific Tools for PythonÂhttp://www.scipy.org/Â) there is the linspace function, which you could use like this
for x in numpy.linspace(0,2,21):
  print(x)

Russell

On 23 August 2012 14:34, Ricardo Franco <ricardo.krieg@xxxxxxxxx> wrote:
Well, this is a good idea, I go do this way. tks


2012/8/22 Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx>
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



--
Ricardo Franco AndradeÂÂÂÂÂÂÂÂÂÂÂÂ @ricardokrieg

( Game | Desktop | Web ) Developer

email: ricardo.krieg@xxxxxxxxx
contact:Â+55 (86) 9958 9725