467,908 Members | 1,845 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,908 developers. It's quick & easy.

Re: [Python-Dev] Why don't range and xrange threat floats as floats?

2008/11/5 L V <so******@yahoo.com>:
Why don't range and xrange threat floats as floats?
Is there any good reason range and xrange don't threat floats as floats but
as integers?
When I enter float arguments in a range, the floats are treated as integers.
(+ some warning)

This is how I think it should work:
>>>>range(0, 1, 0.1)
[0.0, 0.10000000000000001, 0.20000000000000001, 0.29999999999999999,
0.40000000000000002, 0.5, 0.59999999999999998, 0.69999999999999996,
0.80000000000000004, 0.90000000000000002]

I got these results by:
>>>>[x/10. for x in xrange(10)]

I'm not looking for alternatives, just for the reason that it works this
way.
Hi,

I don't think the Python developers list is th best list to post this
kind of question.

What version of Python did you use for this test?

Matthieu
--
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
Nov 5 '08 #1
  • viewed: 1240
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Berthold Hoellmann | last post: by
2 posts views Thread by Olaf Meyer | last post: by
reply views Thread by python-help-bounces | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
1 post views Thread by Jerald | last post: by
3 posts views Thread by Saravanan | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.