| 01-01-2007, 05:06 AM | #1 |
kay i need something like this JASS:function IsIntEven takes integer i returns boolean ... ... endfunction this function checks weather a integer is even or odd, e,g : JASS:IsIntEven(2) //returns true IsIntEven(19) // returns false IsIntEven(100) //returns true IsIntEven(7) // returns false +rep to first who solved the question ![]() |
| 01-01-2007, 05:30 AM | #2 |
A roundabout way, and it's sorta messy but here's the steps:
Example: 9/2 = 4.5 4.5 (real) —> 4 (integer) 4.5 =/= 4, so it's not even. 16/2 = 8 8 (real) = 8 (integer) 8 == 8, so it is even. However, I don't think that solves your problem, though; you need a boolean. |
| 01-01-2007, 05:38 AM | #3 |
lol atctually it does !! thanks !! JASS:function IsIntEven takes integer i returns boolean local integer n = 2*R2I(I2R(i)/2) if n==i then return true else return false endif endfunction +rep xD |
| 01-01-2007, 05:41 AM | #4 |
Use the Modulo bj function. JASS:function ModuloInteger takes integer dividend, integer divisor returns integer local integer modulus = dividend - (dividend / divisor) * divisor // If the dividend was negative, the above modulus calculation will // be negative, but within (-divisor..0). We can add (divisor) to // shift this result into the desired range of (0..divisor). if (modulus < 0) then set modulus = modulus + divisor endif return modulus endfunction It returns the "leftovers" if dividend is divided by divisor. So your divisor will be 2, your dividend will be i. If the leftover is = to 0, then it's even. Edit: Just saw your last post..that will work too ^^. |
| 01-01-2007, 06:00 AM | #5 |
Nice! I was helpful for once! Thanks for the +Rep man! |
| 01-01-2007, 08:52 AM | #6 |
JASS:function IsIntEven takes integer i returns boolean return i == (i/2)*2 endfunction |
| 01-01-2007, 09:10 AM | #7 | |
Quote:
|
| 01-01-2007, 10:43 AM | #8 |
no, your PC calculates part for part. The first part will round the devided int (if it was 1,2,3..), the second will multiply again, which means if the int was rounded, there will be mistake. So this is seriously correct and the bset solution at all. Give Captain Griffen +rep, his solution is faster than all the others. EDIT: Wrong name you should +rep |
| 01-06-2007, 08:52 AM | #9 |
Bert, not to rebuke myself but... how is my solution faster than Captain Griffen's? It seems that his requires only one division and 1 multiplication, while mine requires 1 division, 1 multiplication, an I2R() conversion, and an R2I() conversion. Also, seems rather hypocritical that you instructed others to rep me, but did not do so yourself... ![]() |
| 01-06-2007, 02:48 PM | #10 |
Sorry, .. I guess my eyes were shut, but I did not see the quote. :? |
| 01-06-2007, 08:41 PM | #11 |
I was gonna say... |
