• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Integer/Real glitch #2?

Status
Not open for further replies.
Hello again. Gonna write a post about JASS bug again.
When I've analyzed SirNikolas's version of FICS, I've found a lulz. Here is the code:
JASS:
    function Trig_FICS_BinSearch takes integer id returns integer
        local integer first = 0
        local integer last = udg_FICS_Length
        local integer mid
        if id >= udg_FICS_Ids[0] and id <= udg_FICS_Ids[last - 1] then
            loop
                exitwhen first >= last
                set mid = (first + last) / 2
                if id <= udg_FICS_Ids[mid] then
                    set last = mid
                else
                    set first = mid + 1
                endif
            endloop
            if id == udg_FICS_Ids[last] then
                return udg_FICS_Num[last]
            endif
        endif
        return 0
    endfunction
I understand that this is a binary searching.
But can someone explain which sorcery made this line: set mid = (first + last) / 2 compile? o_O
It must give an error since the result of the division may be real and I see: local integer mid in the beginning! integer is not real. But / 2 is compiling!
I wonder, how... Bug or a feature?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
I don't think it rounds values, I think it truncates the fractional part.
JASS:
library IntegerTest initializer init
    
    function FUCKMEPLZ takes nothing returns nothing
        local integer a=R2I(1.2)
        local integer b=R2I(1.8)
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60.00," a holds value "+I2S(a))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60.00," b holds value "+I2S(b))
    endfunction
    
    function init takes nothing returns nothing
        call TimerStart(CreateTimer(),1.00,false,function FUCKMEPLZ)
    endfunction
endlibrary

attachment.php
 

Attachments

  • output.JPG
    output.JPG
    35.5 KB · Views: 217
Level 14
Joined
Jun 27, 2008
Messages
1,325
Dont you know the expression "Its not a bug, its a feature!".

Well, this is literally the case here... :D

And about rounding, its simply a "DIV" operation (some languages support that, including WurstScript). Its equal to performing a real division and cutting off the digits behind the decimal point.
 
Status
Not open for further replies.
Top