| 04-28-2006, 12:41 AM | #1 |
I'm wondering, since Pow(25, 2) is actually 25*25, why is Pow needed? Why do people use it? Why not just multiply the value by itself? Hell, why does vexorian use it on his caster system? As stated on wc3jass, it just takes longer to execute than the normal calculation. (I hope i got the right assumption on what Pow does..) |
| 04-28-2006, 12:57 AM | #2 |
Cos you can go Pow (25, 6) and thats alot easier than (25 x 25 x 25 x 25 x 25 x25) ? |
| 04-28-2006, 01:05 AM | #3 |
That appears to be the only reason. It's probably more efficient to use Pow for powers that aren't positive or negative integers. |
| 04-28-2006, 01:12 AM | #4 |
Blizzard randomly picked and choosed at math functions in the C standard library that they thought people might need. Indeed, Pow turns out to be not so useful, and often counterproductive for inexperienced programmers. BBDino's example can be done in 3 multiplications, which is still probably faster than pow. If you're working with integers, then it should definitely be done with multiplications or you'll be entering rounding hell, as 25^6 has enough digits to be skeptical of the last place. |
| 04-28-2006, 01:13 AM | #5 | |
Quote:
Nah, it's because of variable names. Example: JASS:
local real x = 25.00
local real pow = x*x
is better than: JASS:
local real x = 25.00
local real pow = Pow(x,2)
BUT: JASS:
local real AntiDisEstablishmentArianism = 25.00
local real pow = AntiDisEstablishmentArianism*AntiDisEstablishmentArianism
is not as easy as: JASS:
local real AntiDisEstablishmentArianism = 25.00
local real pow = Pow(AntiDisEstablishmentArianism,2)
Especially if you have to square a couple of vars in one statement. |
| 04-28-2006, 02:18 AM | #6 |
If you must, I bet you that: JASS:function SquareReal takes real x returns real return x*x endfunction |
| 04-28-2006, 03:44 AM | #7 |
no, it isn't. x*x is faster than Pow(x,2) But Pow((something),2) is faster if you would need to do a whole assignation. And much faster if it is a function call. JASS will never beat native C++ functions as bad as the C++ functions could be. |
| 04-28-2006, 05:17 AM | #8 |
ZZZZ ok benchmarking. +-1s x = r*r 7s x = r, y = x*x 9s //Assignment square-like you'd do for computing distances x = r*r*r*r 10s x = r*r, y = x*x 11s x = Pow(r,2.) 13s //Pow x = r*r,y=x*x*x 15s x = SquareReal(r) 18s //A squaring function r a literal real Assignment squaring is faster than pow while a square function is slower. I'm sure we can all agree the difference is inconsequential. my final words on this topic are to never use Pow for integer work or for evaluating polynomials |
| 04-28-2006, 05:23 AM | #9 |
what about integration? |
| 04-28-2006, 05:42 AM | #10 |
I fail to see the relevance or what your question is, but if you need to integrate a differential equation try this: http://www.wc3jass.com/viewtopic.php?t=2586 |
| 04-28-2006, 06:37 AM | #11 |
Pow can be used to create geometric series, A*B^(C - 1). |
| 04-28-2006, 07:45 AM | #12 |
Thanks for the answers. |
| 04-28-2006, 12:26 PM | #13 | |
Quote:
http://www.wc3jass.com/viewtopic.php?t=2430 now I remember, what was way slower was to use a function for the Pow |
| 04-29-2006, 12:22 PM | #14 |
If you only want to calculate X^2, using X*X will be more easier and faster. But when you want to calculate things like X^1.7 | X^1000 | X^variable, it will be much much more easier and convenient to use Pow.^_^ |
| 04-29-2006, 12:29 PM | #15 |
What about say Cos or Sin? Are the polinomic equivalents faster or? |
