Discussion Accuracy of GetUnitFacing(unit u)

SineCosine

I'm still looking for my Tangent
Reaction score
77
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
Reaction score
67
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
Reaction score
77
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=~
Reaction score
177
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
Reaction score
77
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
Reaction score
67
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
Reaction score
77
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.
Reaction score
85
== 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
Reaction score
67
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
Reaction score
21
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=~
Reaction score
177
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
Reaction score
77
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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top