Forum
v1.8.9 : IF / ULONG > ULONG() array comparison bug - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: v1.8.9 : IF / ULONG > ULONG() array comparison bug (/showthread.php?tid=870)



v1.8.9 : IF / ULONG > ULONG() array comparison bug - JMcGibbitts - 02-05-2019

Hello Boriel, my first post here, so I'm sorry it's to report a bug.

I found a problem when comparing a ULONG variable with any entry in an array of ULONGs.
Saving the array entry to a temporary ULONG variable to compare with is a workaround.

The problem seems to happen with v1.87, so is perhaps an older bug.

A working code comparison sample is pasted below.
The code purpose is to find where to insert a page number in an array of page numbers, where the pages are stored in correct sequence but are not simply incrementing numbers.
Switch between SUBs v1() / v2() to compare the output.

Thanks

Code:
' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Declarations
DIM ulStoryPage, ulTemp AS ulong  
DIM ulLongStory (5) AS ulong   => { 900000, 700000, 500000, 300000, 100000, 0 }
DIM uiCounter, uiPosition, uiYPos AS ubyte
' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Inits.
LET uiCounter = 5 : LET uiPosition = 5 : LET uiYPos = 10
LET ulStoryPage = 500001
' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Cosmetics
BORDER 0
INK 1
PAPER 0
BRIGHT 1
CLS
PRINT AT 0,0; "Story Page = "; ulStoryPage
' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Toggle this between v1() and V2() to compare.
v1()   ' v1() fails the comparison against the array.
'v2()   ' v2() uses a temp variable to store / compare array value.

DO
LOOP

' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB v1()    ' Find the page position in the story - V1...  This fails the comparison, so the page is never inserted.
    DO
        LET uiCounter = uiCounter - 1
        IF ulStoryPage > ulLongStory(uiCounter)     '  Trying to compare the ULONG against the ULONG in the array.
            LET uiPosition = uiCounter
            PRINT AT uiYPos,0; INK 4; "Slot=";uiCounter; " Page="; ulLongStory(uiCounter); " insert @"; uiPosition
        ELSE
            PRINT AT uiYPos,0; INK 2; "Slot=";uiCounter; " Page="; ulLongStory(uiCounter)
        ENDIF
        LET uiYPos = uiYPos + 1
    LOOP UNTIL uiCounter = 0
END SUB


' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB v2()    ' Find the page position in the story V2...  Assigns the array value to a temp value to compare.  (This works)
    DO
        LET uiCounter = uiCounter - 1
        LET ulTemp = ulLongStory(uiCounter)         '     Using a temporary ULONG to compare with instead of the array.
        IF ulStoryPage > ulTemp
            LET uiPosition = uiCounter
            PRINT AT uiYPos,0; INK 4; "Slot=";uiCounter; " Page="; ulLongStory(uiCounter); " insert @"; uiPosition
        ELSE
            PRINT AT uiYPos,0; INK 2; "Slot=";uiCounter; " Page="; ulLongStory(uiCounter)
        ENDIF
        LET uiYPos = uiYPos + 1
    LOOP UNTIL uiCounter = 0
END SUB



Re: v1.8.9 : IF / ULONG > ULONG() array comparison bug - boriel - 02-09-2019

This bug was fixed in version 1.8.8

Please download 1.8.9 and try. I've checked and your program run ok Smile


Re: v1.8.9 : IF / ULONG > ULONG() array comparison bug - JMcGibbitts - 02-09-2019

I have just used my local v1.8.9 zip to update the directory again, checked I copied everything across. It runs just fine. I apologize, as it seems for some stupid reason I must not have properly updated my install even since v1.8.7. :oops:


Re: v1.8.9 : IF / ULONG > ULONG() array comparison bug - boriel - 02-10-2019

No worries! Indeed compiling programs is the best way to find new bugs. :wink:
For the 1.9.x (currently I'm a bit busy) a lot of testing will be needed since it changes a lot in the optimizer.