Discussion Accuracy of GetUnitFacing(unit u)

SineCosine

I'm still looking for my Tangent
Well, a user by the name of AccName was having problems with GetUnitFacing.
His problem?
JASS:
if GetUnitFacing(u) == 270.00 and GetUnitFacing(u) != 270.00 then
    //Stuff
endif


At a glance, you should be able to conclude that the following is impossible.
How can something be and not be at the same time?

So, I set out to see if it was a bug or if it was an inaccuracy.
At first, it seemed like a bug.

After all..
I used this:
JASS:
library BlizzardHasPotentialBugs initializer Blizzard_Init
    globals
        boolean Set270 = false
    endglobals

    private function Test_Bug takes nothing returns nothing
        local unit u = gg_unit_Hpal_0000
        local real f
        
        if Set270 == true then
            call SetUnitFacingTimed(u, 270.00, 0)
        endif
        
        set f = GetUnitFacing(u)
        
        if (f == 270.00) and (f < 270.00) then
            if f <= 270.00 then
                call BJDebugMsg("Unit's facing is either smaller than or equal to 270.00")
            endif
            if f >= 270.00 then
                call BJDebugMsg("Unit's facing is either larger than or equal to 270.00")
            endif
            if f == 270.00 then
                call BJDebugMsg("Unit's facing is equal to 270.00")
            endif
            if f != 270.00 then
                call BJDebugMsg("Unit's facing not equal to 270.00")
            endif
            if f < 270.00 then
                call BJDebugMsg("Unit's facing is smaller than 270.00")
            endif
            if f > 270.00 then
                call BJDebugMsg("Unit's facing is larger than 270.00")
            endif
            call BJDebugMsg(R2S(GetUnitFacing(u)))
        else
            call BJDebugMsg("I ain't bugged!")
            call BJDebugMsg(R2S(GetUnitFacing(u)))
        endif
        
        set u = null
    endfunction

    private function Stuff takes nothing returns boolean
        if GetSpellAbilityId() == 'A000' then
            if Set270 == true then
                set Set270 = false
            else
                set Set270 = true
            endif
        endif
        
        return false
    endfunction
    
    private function Blizzard_Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 1.00, true)
        call TriggerAddAction(t, function Test_Bug)
        
        set t = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        call TriggerAddCondition(t, Condition(function Stuff))
    endfunction
endlibrary


And it showed me:
Unit's facing is either smaller than or equal to 270.00
Unit's facing is equal to 270.00
Unit's facing not equal to 270.00
Unit's facing is smaller than 270.00
270.00
That's queer?
IT'S A BUG!

Nay, I say.
The answer is, === and !== should be used.
But Blizzard doesn't have those as valid comparisons..
Do they?

So..
Just how many zeroes should we put to avoid this weird bug?
I tried it and..
The answer is: Many.

32 zeroes, to be exact.
0.0000000000000000000000

So..
What's your take on this? o.0

On a side note..
Why would someone wanna' know if something is and isn't at the same time?
 

Bribe

vJass errors are legion
Some responses that return real values have miniscule differences sometimes. GetSpellTargetX/Y return slightly different values for the same spell, and GetUnitFacing is not a good check for the angle between the caster and the spell target because sometimes the caster is able to get off the effect before completing the full turn towards the target.
 

SineCosine

I'm still looking for my Tangent
Yea, I know about the GetSpellTargetX/Y part, it pissed me off to no end at one point in time xD

The guy wasn't looking for the angle between the caster and target, I think.
He just wanted to know why this would give him a message when it isn't supposed to:
JASS:
if GetUnitFacing(u) == 270.00 and GetUnitFacing(u) != 270.00 then
    call BJDebugMsg("SHIT! I BUGGED! Oh noes!")
endif


[EDIT]
My solution is to add 32 decimal places for every value he wants to check this way..
But that would be tedious for a GUI user..
Would it not? o.0

And, would it even work?
As in, is it the solution to the problem? xD

[EDIT=2]
Holy Shi--
I tried to make a function that would make everything accurate up till 32 decimal places (In case it were ever needed..)
But something bugged ._.

Does it have something to do with the fact that binary is in base 2?
JASS:
call BJDebugMsg(R2S(270.00 * 1.00000000000000000000000000000000) + " Weird, huh?")
call BJDebugMsg(R2S(110.00 * 1.00000000000000000000000000000000) + " Weird, huh?")
call BJDebugMsg(R2S(220.00 * 1.00000000000000000000000000000000) + " Weird, huh?")


Results are..
540.000 Weird, huh?
220.000 Weird, huh?
440.000 Weird, huh?
 

uberfoop

~=Admiral Stukov=~
Yes, reals in Warcraft 3 fail miserably quite frequently when you use any sort of equality comparison on them. You will notice, however, that the >= and the < did NOT conflict. wc3 reals ARE good enough for that to work.

That's hardly the worst thing about wc3's floating point real system though. The worst is that arithmatic operations frequently store end results which are just wrong. If you have some repeating function on a timer which counts with a real in incriments of .1 from 0 to 10, you will be VERY lucky if the r==10 when you want to cut your looping works (as opposed to an r>9.91 and r<=10.09 check or something, which generally would work).


Anyway, welcome to the world of wc3 mathematics.
 

SineCosine

I'm still looking for my Tangent
Wow ._.
But what about the 32 decimal places fixing it? XD

Is that correct?
Or am I sadly mistaken, too =/

I tried the test again with this:
JASS:
    private function FixReal takes real r returns real
        return (r * 1.00000000000000000000000000000000) / 2.00000000000000000000000000000000
    endfunction


And I compared GetUnitFacing(u) with FixReal(270.00)
The unit's facing never got to == 270 and != 270 at the same time ever again =)
 

Bribe

vJass errors are legion
This is why I have R2I conversions in my Time Travel system instead of using reals the whole time.
 

SineCosine

I'm still looking for my Tangent
That would simplify things a hell lot ._.
Oh, well.

I'll try to forget this ever happened xD
 

Troll-Brain

You can change this now in User CP.
== rounds about 3 numbers or so under the digit (like R2S i think), while >= , <= don't, or at least with more numbers under the digit.
I haven't tested the other operators, but maybe it's the same shit.
Easy to test, hf.
 

Bribe

vJass errors are legion
Please also keep in mind that, in terms of both reals and integers, you must be absolutely positive that that value will not increase/decrease unexpectedly and overshoot the "==" margin.
 

SanKakU

Member
Yes, reals in Warcraft 3 fail miserably quite frequently when you use any sort of equality comparison on them. You will notice, however, that the >= and the < did NOT conflict. wc3 reals ARE good enough for that to work.

That's hardly the worst thing about wc3's floating point real system though. The worst is that arithmatic operations frequently store end results which are just wrong. If you have some repeating function on a timer which counts with a real in incriments of .1 from 0 to 10, you will be VERY lucky if the r==10 when you want to cut your looping works (as opposed to an r>9.91 and r<=10.09 check or something, which generally would work).


Anyway, welcome to the world of wc3 mathematics.
would this be because warcraft 3 often uses random values? like rolling dice for damage for units, unlike in starcraft.
 

uberfoop

~=Admiral Stukov=~
would this be because warcraft 3 often uses random values? like rolling dice for damage for units, unlike in starcraft.
Not at all. If that were the case, it would only screw up on use of random values and not when, say, incrimenting along in small steps from one value to another.

I figure it's just a really bad case of floating point operation precision fail.

Here's a basic example. When watching the numbers go by, note the jumps being small power-of-two-esque numbers:
JASS:

scope MathFail initializer Init

globals
    real r = 0.00
endglobals

private function Repeater takes nothing returns nothing
    set r = r + .1
    call BJDebugMsg(R2SW(r,30,10))
endfunction

private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(),.5,true,function Repeater)
endfunction

endscope
 

SineCosine

I'm still looking for my Tangent
I know that nobody would do this..
Except for a few..

But it does pose a potential problem. (Whatever that problem may be =x)
Well, lesson learned, I guess.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    Is that going to be a full game now tom?
  • The Helper The Helper:
    what is this Ghan? https://enterprise.ghannet.com/ you are totally holding out on us my friend
  • Ghan Ghan:
    Not mine, I just ran the server. They let the domain expire but it was a cool project so I kept it alive there.
  • Ghan Ghan:
    Used to be enterpriserpg.com I think.
  • The Helper The Helper:
    If you go to the world editor tutorials site and click the starcraft link it takes you there :)
  • Ghan Ghan:
    lol
  • Ghan Ghan:
    I forgot about that alias name. (The full URL still went to the correct site.) That should be fixed.
  • Ghan Ghan:
    Silkroad Forums site really needs help.
  • Ghan Ghan:
    Its software has been out of support since 2017.
  • Ghan Ghan:
    The woes of using custom styles....
  • The Helper The Helper:
    does anyone still use silk road forums?
  • Ghan Ghan:
    It's about as active as here I'd say. Not much going on.
  • Wizard Wizard:
    I think it doesn't help that the silk road game isn't as popular any more I think. The only MMO I play these days is FFXIV like most other people I know.
  • The Helper The Helper:
    I checked a status page for players and it says the game has 500 daily players.
  • The Helper The Helper:
    I cannot believe that site is still going I wonder if Ryoko is involved with it at all would love to talk to him again and see what he is up to
  • The Helper The Helper:
    my oldest daughter failed her driving test today for her license she is 22 and yes I have been driving her everywhere her whole life
  • The Helper The Helper:
    Now they are blaming me on Facebook for her failure LOL I am accepting it because it is my failure I am her driving teacher even though she had certified driving instruction from the best place in town I for some reason cannot teach her how to drive this is frustrating
  • jonas jonas:
    I didn't get my license until I was 25
    +1
  • The Helper The Helper:
    Back in the old days when I was getting a license people were getting them at 16 yrs old and many were getting hardships so they could get them earlier. Almost nobody did not drive when they were able. Nowadays though....
  • Ghan Ghan:
    Why drive when there's Uber Eats?
    +2
  • The Helper The Helper:
    I hope Varine is OK have not heard from him in a while.
    +1
  • Ghan Ghan:
    Diablo 2 Resurrected launching in 9 days.
  • The Helper The Helper:
    Just got a new to me computer hope it will run it
  • jonas jonas:
    I would buy if it had better modding support than D2, like a small lua script engine or much less hardcoded stuff

    Members online

    Affiliates

    Hive Workshop NUON Dome
    Top