#499 Cannot execute for loop with ridiculously large numbers

closed-fixed
nobody
None
5
2012-12-04
2012-12-02
copaceticman
No

I can execute this block of code in IDL, but not in GDL:

for i=0,600851475143/2 do begin
print,i
if i ge 100 then break
endfor
end
---------------------------------------------------------
I have been going through the interpreter files and cannot find a statement that says "if 'for loop end' is greater than x do not execute"

So I decided to make an official bug report about this, since I cannot seem to fix it myself. Of course I barely know where to start looking.

Discussion

  • Marc Schellens
    Marc Schellens
    2012-12-03

    This is because IDL since version 8.0 promotes the loop start variable type automatically to LONG or LONG64 if the end value is to large. Before 8.0 this was not done: The loop end variable is converted to the type of the loop start variable. As here the end value is to large to be hold in an INT the conversion (from the LONG64 constant to INT) leads to a negative INT, and hence the loop isn't executed. GDL release 0.9.2 behaves like IDL 7. The CVS version already behaves like IDL 8.0.
    So either use the CVS version, or use LONG64 for the start value:
    for i=0LL, ...
    (I noticed that GDL still has a problem with the BREAK, that's why I do not close this report now)

     
  • copaceticman
    copaceticman
    2012-12-03

    Oh, that would explain that. I didn't know IDL did that. Thanks. Feel free to delete this post as you please.

     
  • Marc Schellens
    Marc Schellens
    2012-12-04

    • status: open --> closed-fixed