Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 8th, 2007, 9:33 PM   #1
kurt
Programmer
 
Join Date: Oct 2005
Posts: 68
Rep Power: 3 kurt is on a distinguished road
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!
kurt is offline   Reply With Quote
Old Apr 8th, 2007, 9:57 PM   #2
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 310
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
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.
andro is offline   Reply With Quote
Old Apr 8th, 2007, 9:58 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Apr 9th, 2007, 2:27 AM   #4
ptmcg
Newbie
 
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0 ptmcg is on a distinguished road
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
ptmcg is offline   Reply With Quote
Old Apr 10th, 2007, 4:13 PM   #5
ptmcg
Newbie
 
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0 ptmcg is on a distinguished road
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
ptmcg is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC