EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2015
02:23 PM
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:
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.
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.
2 REPLIES 2

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2015
02:28 AM
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?
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2015
12:51 PM
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.
+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.