• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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: 209
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