comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: crazy loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: crazy loops [message #29359 is a reply to message #29354] Wed, 13 February 2002 05:35 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
M Carmen (mcgonzal@uv.es) writes:

> I have a question related with loops......can someone teel me why
>
> if i do a loop that goes to a maximum of 0.6:
> for r=0.0, 0.6, 0.1 do begin & print, r & endfor
>
> I get:
> 0.000000
> 0.100000
> [........]
> 0.500000
> 0.600000
>
> and if now i change the maximum value of the range to 0.7:
> for r=0.0, 0.7, 0.1 do begin & print, r & endfor
>
> I get:
> 0.000000
> 0.100000
> [........]
> 0.500000
> 0.600000
>
> EXACTLY THE SAME!!!

Well, the short answer is "Because of the way computers
represent floating point numbers." There have been numerous
posts on this topic in the past. You might try searching
the Google archives for "Set Precision", for example. The
bottom line, however, is that it is not a good idea to use
floating point values as counters, since you can't rely on
their exact value. This has nothing to do with IDL. It is
entirely related to how computers work.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: how to debug a IDL DLM routine
Next Topic: Radar dB values

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:43:25 PDT 2025

Total time taken to generate the page: 0.00420 seconds