![]() |
Floating point range
I search my book, searched Google and this forum, but still can't find a way to do this:
:
range(1,2, 10e-9)How can I create a range that increments in a value that is small? Thanks in advance! |
Pretty sure you need to implement your own frange() function. Be careful about the inaccuracies of floating point numbers especially on the order of magnitude you are suggesting.
|
Not sure of this, but I don't think the step can be between -1 and 1. You can, of course, roll your own.
|
Don't forget range() creates a list of all of the entries, so range(1,2,1e-9) would create a billion-entry list. If instead you are trying to iterate a billion times (and I hope you have some time on your hands!), you may be better off with "for i in xrange(0,1e9): f = float(i)/1e9" and then use f as your 0-to-1-by-billionths counter.
-- Paul |
Out of curiosity, I timed how long a do-nothing for loop takes to iterate 1e9 times. On my 2GHz CPU system, running Python 2.4.1:
:
for i in xrange(1e9): passtakes 127.5 seconds. So it is feasible to do something a billion times in Python, but I wouldn't put much processing in the body of that loop. -- Paul |
| All times are GMT -5. The time now is 2:20 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC