• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] How to do X to the 2nd Power?

Status
Not open for further replies.
We're talking processor speed. Pow (I think, someone correct me if I'm wrong) uses a conditional loop to multiply x, which means it has to evaluate <index> conditions, or more, making it much slower than straight multiplication. If processing speed doesn't matter to you, however, feel free to use Pow, but i personally think x*x looks more organised, however I can see why anything over a power of about 4 might tempt you to use the function.
 
Level 13
Joined
Jun 22, 2004
Messages
783
Correct, however when not used oftenly, don't be bothered to use the pow function inside the editor, it's nothing significant really + if you want to have x to the power of 50, you might get sore finger from clicking or typing once your done.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
We're talking processor speed. Pow (I think, someone correct me if I'm wrong) uses a conditional loop to multiply x, which means it has to evaluate <index> conditions, or more, making it much slower than straight multiplication. If processing speed doesn't matter to you, however, feel free to use Pow, but i personally think x*x looks more organised, however I can see why anything over a power of about 4 might tempt you to use the function.
No, it uses a power series. A for() in C may very well be (in fact, has incredibly good odds of being) faster than that many multiplications in Jass.
 
In the other thread you guys said, that even Sine and Cosine functions are nothing to worry about when processed quite often. Im confused.
As far as I know, computers approximate Sine and Cosine with a taylor series (correct me if im wrong). that takes alot more processing time then a simple potentialization (hope that word exists).
 
Level 9
Joined
Nov 28, 2008
Messages
704
@Poot

Why the hell would JASS multiplication be that slow?

JASS is interpreted into bytecode when the map loads. So like Python, Lua, and every other interpreted language, it's slow as molasses compared to something like C++.

It's still blazing fast though. It may be 5x slower, but 5 more nanoseconds isn't noticeable at all.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Hemlock said:
Correct, however when not used oftenly, don't be bothered to use the pow function inside the editor, it's nothing significant really + if you want to have x to the power of 50, you might get sore finger from clicking or typing once your done.

JASS:
set i = 0
loop
    exitwhen i == 50
    set x = x * x
    set i = i+1
endloop
 
Status
Not open for further replies.
Top