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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top