Diffrence between Rad2Deg() and bj_RADTODEG?

luorax

Invasion in Duskwood
Reaction score
67
I don't know what's the difference between them (I guess there isn't any) but it's definitely [ljass]bj_RADTODEG[/ljass]. It's a simple multiplication and global read, while the other native is a function call plus at least a multiplication. I've never seen anyone using [ljass]Rad2Deg[/ljass], if it was faster, those speedfreaks on THW would have used it already.
 

Tyrulan

Ultra Cool Member
Reaction score
37
[ljass]Rad2Deg()[/ljass] is a function, and requires a lookup (through pointers) and a call stack displacement.

[ljass]bj_RADTODEG[/ljass] is a constant variable. It is scoped such that access to it is much faster (and always will be) than calling a function.

The difference then becomes in how you use them. Some people don't mind the negligible speed difference and prefer the function conversion. Some people like seeing the math. Using [ljass]Rad2Deg()[/ljass] will also use [ljass]bj_RADTODEG[/ljass] to compute the returned value. What coders are really doing is skipping a step.

Thus [ljass]Rad2Deg(50)[/ljass] is actually calculating [ljass]50 * bj_RADTODEG[/ljass] ( [ljass]bj_RADTODEG[/ljass] has a value of [ljass]180 / bj_PI[/ljass]).

Hope this helps.

Cheers.
 

Bribe

vJass errors are legion
Reaction score
67
No one I have seen has done any tests to confirm that one produces different results from the other. It's there because Blizzard wanted it to be there. One less-evil but unecessary function is I2R, especially when the GUI adds it, since it's only useful for division and could be replaced with (i + 0.).
 

Tyrulan

Ultra Cool Member
Reaction score
37
One less-evil but unecessary function is I2R, especially when the GUI adds it, since it's only useful for division and could be replaced with (i + 0.).
Made even further useless by the editor's limited - but still apparent - implicit casting.
JASS:
local integer myInteger = 1
call DisplayTextToForce(GetPlayersAll(), R2S(I2R(myInteger)))
call DisplayTextToForce(GetPlayersAll(), R2S(myInteger + 0.))
call DisplayTextToForce(GetPlayersAll(), R2S(myInteger))

The last 2 of the 3 displays use implicit casting. All are syntactically correct and produce the same results.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
the way you are talking about this is like blizzard never makes useless functions, yet bjs still exist, the gui ifs add nots to every conditional statement, and plenty of gui functions cause crashes in the editor, blizzard are game-makers, not language designers or even game completors (every game they release is unfinished)

but yes, to answer the question, whenever you have an option between using a variable and simple math it will always be faster than any function call, even [ljass]DoNothing()[/ljass] :p
 

Tyrulan

Ultra Cool Member
Reaction score
37
Mhm, quite right. It's preference, since the speed difference is negligible.
 

DaFatalGigabyte

New Member
Reaction score
0
Thus [ljass]Rad2Deg(50)[/ljass] is actually calculating [ljass]50 * bj_RADTODEG[/ljass] ( [ljass]bj_RADTODEG[/ljass] has a value of [ljass]bj_PI / 180[/ljass]).
[ljass]bj_RADTODEG[/ljass] has a value of [ljass]180 / bj_PI[/ljass].
[ljass]bj_DEGTORAD[/ljass] has a value of [ljass]bj_PI / 180[/ljass].
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    nobody signs up or comments
  • The Helper The Helper:
    its crazy
  • The Helper The Helper:
    363 bots on the forum been like that for about a month this is the most bots we have ever consistently hosted
  • The Helper The Helper:
    and we are on cloud flare too right?
  • Stephen Stephen:
    Probably stupid AI garbage. It's harvesting our Nuon knowledge.
  • Stephen Stephen:
    The bots I mean.
  • The Helper The Helper:
    I suspect AI Bots as well
  • The Helper The Helper:
    Happy Saturday!!!
    +1
  • The Helper The Helper:
    I reorganized the forums somewhat but I doubt anyone would notice
  • The Helper The Helper:
    Happy Friday!
    +1
  • The Helper The Helper:
    Happy Saturday!
    +1
  • The Helper The Helper:
    The forum software says we have 554 members online now. We did not have that many unique visitors the whole day today. Too many bots and the disconnect between the forum counts and the stats.
  • Varine Varine:
    Currently it says 413 guests and 2 members
    +1
  • Varine Varine:
    Aww
  • The Helper The Helper:
    That is going to be mostly bots
  • The Helper The Helper:
    527 (members: 2, guests: 525)
  • The Helper The Helper:
    Happy Saturday!
    +1
  • V-SNES V-SNES:
    Happy Saturday!
    +1
  • The Helper The Helper:
    622 (members: 2, guests: 620)
  • The Helper The Helper:
    666 (members: 4, guests: 662) :)
    +1
  • Varine Varine:
    609 (members: 4, guests: 605)
  • The Helper The Helper:
    I was posting that last one because the 666 users online :)
    +1
  • The Helper The Helper:
    Happy Wednesday Night!
    +1
  • The Helper The Helper:
    Happy Thursday!
    +1
  • The Helper The Helper:
    Marathon watching The Expanse!

    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