Matthieu Brucher wrote:
It works this way because you can't be sure that you won't get an extra
increment. When you repeatedly add fractions together, the desired final
result might be just less or just more than the actual integral value.
If it's just less you will get an extra increment. It just doesn't work.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
2008/11/5 L V <somelauw@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:
>[0.0, 0.1000000000000 0001, 0.2000000000000 0001, 0.2999999999999 9999,
>0.400000000000 00002, 0.5, 0.5999999999999 9998, 0.6999999999999 9996,
>0.800000000000 00004, 0.9000000000000 0002]
>>
>I got these results by:
>I'm not looking for alternatives, just for the reason that it works this
>way.
>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.400000000000 00002, 0.5, 0.5999999999999 9998, 0.6999999999999 9996,
>0.800000000000 00004, 0.9000000000000 0002]
>>
>I got these results by:
>>>>[x/10. for x in xrange(10)]
>way.
increment. When you repeatedly add fractions together, the desired final
result might be just less or just more than the actual integral value.
If it's just less you will get an extra increment. It just doesn't work.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/