HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Real - Integer Return Bug Comparisons Bugged

05-14-2006, 05:39 AM#1
PipeDream
Found a little bug from Blizzard. I created a linked list system using a location as a pair. To type cast I return bugged to reals. I was using location == null to indicate the end of the line. Unfortunately this doesn't work, as the comparison will always return true. Fixing takes a tiny workaround: assign the integer version to a variable first and compare with zero. Here's some test code:
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function H2R takes handle h returns real
    return h
    return 0.
endfunction

function ItoB takes integer i returns boolean
    return i
    return false
endfunction

function BtoI takes boolean b returns integer
    return b
    return 0
endfunction

function MakePair_OO takes location oList1, location oList2 returns location
    return Location(H2R(oList1),H2R(oList2))
endfunction

function First_I takes location list returns integer
    return GetLocationX(list)
    return 0
endfunction

function ItoR takes integer i returns real
    return i
    return 0.
endfunction

function RtoI takes real r returns integer
    return r
    return 0
endfunction

function Bugged takes nothing returns nothing
    local location oLoc = Location(5.,23.)
    local location oPair = MakePair_OO(oLoc,null)
    call BJDebugMsg("Test1 Integer value: "+I2S(First_I(oPair)))
    call BJDebugMsg("Is equal to zero?")
    if(First_I(oPair) == 0) then
        call BJDebugMsg("Yes")
    else
        call BJDebugMsg("No")
    endif
endfunction

function NotBugged takes nothing returns nothing
    local integer x
    local location oLoc = Location(5.,23.)
    local location oPair = MakePair_OO(oLoc,null)
    call BJDebugMsg("Test2 Integer value: "+I2S(First_I(oPair)))
    call BJDebugMsg("Is equal to zero?")
    set x = First_I(oPair) //Work around.  assign to variable first.
    if(x == 0) then
        call BJDebugMsg("Yes")
    else
        call BJDebugMsg("No")
    endif
endfunction

function Test3 takes nothing returns nothing
    call BJDebugMsg("Test3 42 is "+I2S(RtoI(ItoR(42))))
    if(RtoI(ItoR(42)) == 0) then
        call BJDebugMsg("RtoI(ItoR(42)) == 0 is bugged and returns true")
    else
        call BJDebugMsg("RtoI(ItoR(42)) seems to be working")
    endif
endfunction

function Test4 takes nothing returns nothing
    if(BtoI(ItoB(42)) == 0) then
        call BJDebugMsg("BtoI(ItoB(42)) == 0 is bugged and returns true")
    else
        call BJDebugMsg("BtoI(ItoB(42)) seems to be working")
    endif
endfunction

function Test takes nothing returns nothing
    call Bugged()
    call NotBugged()
    call Test3()
    call Test4()
endfunction

Bizarre- I have no explanation for why this happens. It shouldn't really bite anyone ever unless they're doing something silly like I was trying- putting data into reals.
05-20-2006, 07:05 PM#2
weaaddar
Reals use float specification 32 0's isn't always zero. You can have a -0 and a positive 0 as well.
05-20-2006, 11:25 PM#3
PipeDream
Indeed, however I'm never touching zero in real format. BTW 32 0's is always +zero, the first bit is a sign bit which distinguishes.
05-23-2006, 04:17 AM#4
weaaddar
Sorry, haven't used floats in a while. Theres a reason we return bug to ints. Seriously, there the most stable. Code's can't have arrays (they might be able to now) strings have bizzare implications. Reals have this quirk, and bools well they might work but why...
05-23-2006, 07:29 PM#5
The)TideHunter(
H2I = Handle Raw Data Signature
H2R = I've never properly tested
H2S = Fatal error
06-18-2006, 04:06 PM#6
BertTheJasser
H2R is/was used by Vex's castersys (around 9.xx or 10.xx)
06-18-2006, 04:59 PM#7
Blade.dk
And there might be a reason if it doesn't use it anymore. H2S doesn't give a fatal error, that is not true. But if it returns null, and you use it with gamecache it will give you a fatal error.
06-18-2006, 06:42 PM#8
The)TideHunter(
The last time i tested, this function:

Collapse JASS:
function H2S takes handle H returns string
    return H
    return null
endfunction

Gave me a fatal error every time, i tried null and "", both fatal errors.
Unless you just do a simple work around like:

Collapse JASS:
function H2I takes handle H returns integer
    return H
    return 0
endfunction

function H2S takes handle H returns string
    return I2S(H2I(H))
    return null
endfunction
06-18-2006, 06:55 PM#9
Vexorian
I use integer 2 real conversions in the caster system. This seems to be a problem with real 2 handle conversions and then comparing to null
06-18-2006, 07:22 PM#10
Blade.dk
The)TideHunter( it doesn't crash everywhere, it does when used in situations where using ""/null normally would cause a crash IF the function returns null. All handles have a unique id, the same with strings. So it will return the string that has the same id as the handle, and in case there is no such string, it will return null - Which makes some things crash, not everything.
06-18-2006, 07:55 PM#11
BertTheJasser
Oh sorry, got mixed up.