Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Roku Guru

Bug: for v=2^31-2 to 2^31-1 ==> infinite loop

Just discovered this when my attempt to enumerate all ints "hanged"*. Minimal example in the topic subject. In more detail:

BrightScript Debugger> a = 2^31 - 2: b = a + 1: ? a, b, type(a), type(b)
2147483646 2147483647 Integer Integer

BrightScript Debugger> for v = a to b: ? v: next
2147483646
2147483647
-2147483648
-2147483647
-2147483646
-2147483645
-2147483644
...

Can also be done step-dancing, e.g. "for v = 2^31 - 200 to 2^31 - 5 step 150" and i bet can be done backwards too (going under -2^31)

(*) back-of-the-envelope math told me full range should take ~5.5hrs but i was doing step 257 which should be done in under 2 mins.
0 Kudos
2 REPLIES 2
Komag
Roku Guru

Re: Bug: for v=2^31-2 to 2^31-1 ==> infinite loop

What the heck? :shock: :?: What's going on under the hood there?
0 Kudos
EnTerr
Roku Guru

Re: Bug: for v=2^31-2 to 2^31-1 ==> infinite loop

It went "to infinity and beyond". MAXINT is 0b 01111111 11111111 11111111 11111111 (2147483647, 2^31-1).
+1 to that gives 0b 10000000 00000000 00000000 00000000, better known as MININT (-2147483648 or -2^31).
And that's clearly smaller than the loop's upper limit, so now we are at "1 Infinite Loop"

It's a PITA boundary condition, that's what it is. Hmm, don't know if they can fix it without that costing in performance to all FOR loops.
0 Kudos