HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

This Doesn't Make Sense

03-22-2010, 07:13 PM#1
TheKid
This makes absolutely no sense:

Collapse JASS:
scope test initializer init
    public function init takes nothing returns nothing
        local real r = 1. //- .05 + .05
        
        if (r == 1.) then
            call BJDebugMsg("r==1.")
        else
            call BJDebugMsg("r!=1.")
        endif
        if (r != 1.) then
            call BJDebugMsg("r!=1.")
        else
            call BJDebugMsg("r==1.")
        endif
    endfunction
endscope

As it is, it will display "==1" twice in-game. If you remove the comment, it displays both "==1" and "!=1". How on earth can it satisfy both conditions.

This is so lame, it even screws up the R2I function which makes R2I(1.+.05-.05) not equal to 1. Instead it returns 0.
03-22-2010, 07:24 PM#2
Ammorth
It has something to do with == and != are compared differently.

I believe == uses an epsilon approach where as != uses a bit comparison approach. Aka, == allows for slight changes and still return true while != requires pretty much the exact same number.

http://www.cygnus-software.com/paper...ringfloats.htm
03-22-2010, 07:32 PM#3
TheKid
Good to know.

Quote:
Originally Posted by Wc3campaigns.net
You must spread some Reputation around before giving it to Ammorth again.

: (