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 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