![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 68
Rep Power: 3
![]() |
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! |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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.
|
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Not sure of this, but I don't think the step can be between -1 and 1. You can, of course, roll your own.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0
![]() |
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): pass takes 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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why there is no ftoa? | InfoGeek | C | 6 | May 3rd, 2006 7:45 AM |
| how to print floating point numbers | eax | Assembly | 5 | Apr 17th, 2006 7:10 PM |
| 3d Graphics. | Sane | Other Scripting Languages | 54 | Apr 7th, 2006 9:38 PM |
| OverflowError: range() result has too many items | coldDeath | Python | 2 | Sep 3rd, 2005 1:18 PM |
| various questions on class Point methods | nocturna_gr | Java | 1 | May 7th, 2005 12:45 PM |