function IAbsBJ takes integer a returns integer
if (a >= 0) then
return a
else
return -a
endif
endfunction
JASS:function IAbsBJ takes integer a returns integer if (a >= 0) then return a else return -a endif endfunction
it does exactly what you want and it should be faster compared to stuff like SquareRoot or Pow even through it is BJ and Pow/SqRt are natives
if x < 0 then
set x = x * -1
endif
I dont know but isntx = -x
faster thenx = x * -1
?
I would not blindly say that. Unless you have done benchmarks it is quite possible that the power function would be faster than a custom 1 dimension abs function. Making a custom function call is considerably slow due to extensive name lookups and stack interaction while working out the power using floating points might be highly optimized in assembly.it does exactly what you want and it should be faster compared to stuff like SquareRoot or Pow even through it is BJ and Pow/SqRt are natives
public class Test {
public static void main(String[] args) {
double timer = System.nanoTime();
double a = 0;
for(int i = 0 ; i < 1000000 ; i+= 1){
a+= Math.pow(Math.random(), Math.random());
}
System.out.println(a);
System.out.println((System.nanoTime()-timer)/1000000000);
}
}
i did not know u could do x = -x but i would think it is if ur able to. i always did x = x * 1 never thought about trying x = -x. both r faster than the absolute value bj function tho
I would not blindly say that. Unless you have done benchmarks it is quite possible that the power function would be faster than a custom 1 dimension abs function. Making a custom function call is considerably slow due to extensive name lookups and stack interaction while working out the power using floating points might be highly optimized in assembly.
Infact you can compute powers so fast that doing over 1,000,000 double (twice the precision of floats or WC3 real) power calculations in JAVA using random double values (generated in the range of 0.0 and 1.0) and summing the results only takes 0.289519014 seconds. I will repeat again, that is a million double precision IEEE compliant power calculations in under 0.289519014 and it is not only doing those (computes random doubles as well as virtual machine maintenance).
I doubt you can run a million lines of JASS in a second.
Code:public class Test { public static void main(String[] args) { double timer = System.nanoTime(); double a = 0; for(int i = 0 ; i < 1000000 ; i+= 1){ a+= Math.pow(Math.random(), Math.random()); } System.out.println(a); System.out.println((System.nanoTime()-timer)/1000000000); } }
People to not spread lies such as the power of floating points being a costly computation. If the function is slower (which I doubt when compared to the abs function) then that is because of the JASS wrappers which drown out the actual computation of the power. Yes they are slow compared to basic integer operations (like all floating point operations) but they are still entire orders of magnitude faster than the JASS interpreter, so much so that you could ignore the computation entirly.what the hell do u want again?
if AND32(Item_Id, Player_Id) > 0 then
...
else
...
endif
0b10001100
& 0b00001000
= 0b00001000
local integer i = 8
loop
exitwhen i == 0 or ItemVar == 0
set i = i-1
if ItemVar <= PowersOf2[i] then
if GetTriggerPlayer() == PlayerVar[PowersOf2[i]] then
// Can be used
set i = 0
endif
set ItemVar = ItemVar - PowersOf2[i]
endif
endloop
u can do:
using http://www.hiveworkshop.com/forums/jass-resources-412/snippet-byte-222868/JASS:if AND32(Item_Id, Player_Id) > 0 then ... else ... endif
The idea is based on bitwise operations, lets assume Item_Id = 140 and Player_Id = 8, then you write down the binary representation and do the bitwise AND (&).:
140 = 0b10001100, 8 = 0b00001000
Code:0b10001100 & 0b00001000 = 0b00001000
This simply checks if the bit specified by the second argument is set in the first argument. Since the bitwise operator (&) is not available in Jass you have to use workarounds, like that AND32 Library. http://en.wikipedia.org/wiki/Bitwise_operation
So with that snippet you're talking about hmm.. Lemme check if I get it.
"AND32(140, 128)" would return 1
"AND32(120, 128)" would return 0
"AND32(5, 1)" would return 1
"AND32(5, 2)" would return 0
Right?
no, "AND32(5, 1)" and "AND32(140, 128)" will return something greater than 0, but not necessarily 1.