mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
isodd :: iseven #192939 13/01/08 04:18 AM
Joined: Aug 2007
Posts: 333
foshizzle Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Aug 2007
Posts: 333
these are 2 simple little things that i think would be handy to have... idk how easy it is to implement it but i want it...

in if then else statements i want :
ifodd: if X is an odd number
ifeven: if X is an even number


This is not the signature you are looking for
Re: isodd :: iseven [Re: foshizzle] #192940 13/01/08 04:49 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You can already use the "is multiple of" operator (//) directly in a condition, or you can use the modulus operator (%) from inside $calc().

eg.
Code:
if (2 // X) {
  ; X is even
}

or
Code:
if ($calc(X % 2)) {
  ; X is odd
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: isodd :: iseven [Re: foshizzle] #192948 13/01/08 10:31 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Yet another way:
Code:
if (X & 1) {
  ; X is odd
}
& is the bitwise AND operator (not to be confused with &&)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: isodd :: iseven [Re: foshizzle] #192958 13/01/08 01:50 PM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
and another possible way:

Code:
if ($calc(X % 2) == 0) {
  ; is even
}


If it ain't broken, don't fix it!
Re: isodd :: iseven [Re: Doqnach] #192971 13/01/08 05:18 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
And another:

Code:
if ($right(X,1) isin 13579) {
  ; X is odd.
}

Re: isodd :: iseven [Re: hixxy] #192972 13/01/08 05:49 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
and another:
Code:
if ($and(X,1)) {
  ; X is odd.
}


$maybe
Re: isodd :: iseven [Re: Mpdreamz] #192975 13/01/08 06:12 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
oh oh oh!
Code:
if ($calc(X / 2) == $int($calc(X / 2))) {
  ; X is even
}


or

Code:
if (. isin $calc(X / 2)) {
  ; X is odd
}



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: isodd :: iseven [Re: foshizzle] #192981 13/01/08 07:10 PM
Joined: Jun 2003
Posts: 5,024
M
Mentality Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Jun 2003
Posts: 5,024
I apologise for them.


Mentality/Chris
Re: isodd :: iseven [Re: Mentality] #192988 13/01/08 09:07 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Lol. So many ways, yet I think it would be helpful to have isodd or iseven built in anyhow. Usually, if something can be easily scripted, I wouldn't support adding it into mIRC itself. But checking for odd and/or even numbers shouldn't require knowing how to do the methods shown. Those are easy for someone who knows how, but those methods aren't obvious to new scripters, nor are they shown at all in the help file. Obviously, people can ask and be shown the way and maybe rememeber it for later. Still, having isodd/iseven makes sense to me.


Invision Support
#Invision on irc.irchighway.net
Re: isodd :: iseven [Re: Riamus2] #193004 14/01/08 12:11 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
I think having even more trivial /if conditions is superfluous.

As has been illustrated already in this thread, there are plenty of ways to do this already.

Re: isodd :: iseven [Re: Riamus2] #193006 14/01/08 12:16 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
The point is that it's not "scripted". the original suggestion, the "is multiple of" (//) operator was implemented in to test iseven/isodd, and its as basic as it gets.

You can blame qwerty for everyone else posting their zany methods. I'm with Bekar, though, and believe there's no reason to add in an operator that's purpose is already superceded by another more general operator.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: isodd :: iseven [Re: argv0] #193012 14/01/08 01:17 AM
Joined: Aug 2007
Posts: 333
foshizzle Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Aug 2007
Posts: 333
well thx for the suggestions/examples i guess


This is not the signature you are looking for
Re: isodd :: iseven [Re: foshizzle] #193075 14/01/08 08:48 PM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
I would vote on which 1 is faster.

I generally think using a custom identifier is slower.

Suppose I made a custom identifier $calculate() based exactly on $calc().

If I used something like.

alias calculate { return $calc($1-) }

I guess the question is is making a non-custom identifier any negligibly faster than using a custom identifier.

For the $iseven or $isodd case, probably not.

And since there's so many ways to check for $iseven or $isodd, I would say a default identifier would have to be slower than using a simple custom identifier (especially if Khaled combined all the above examples in his C++ source for such an identifier).

So probably meaningless.

-Neal.

Re: isodd :: iseven [Re: LostShadow] #193082 14/01/08 09:22 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
A built in method (it's not an identifier, btw) would be faster than any custom identifier. Obviously, the difference in speed would be negligible, but it would definitely not be slower. The main benefit is that it's an obvious way of obtaining whether or not something is even or odd.

Yes, the most common (I think) method right now is to use % to see... basically checking if the number can be evenly divided by 2. That's pretty easy to do and anyone with either a math background or who has scripted enough to know about it can do it. I still say having "isodd" or "iseven" would be good. Apparently, I'm outvoted on this, but it's up to Khaled in the end, so I'll still stand in favor of it and let him decide.

And, for those stating that it can be done using other methods that are easy, so shouldn't be added... why then do we bother having isop, etc?

Code:
if ($nick isop $chan) {}
if ($nick($chan,$nick,o)) {}


That's four characters difference and results would do the same thing. Obviously, isop is better, but the point is that there is an alternate method that doesn't even increase the amount of script by very much. With the iseven/isodd check, the difference in script size is a lot more. So considering adding it would make finding odd/even more intuitive and shouldn't be difficult to add, I don't think the reasoning that it's possible in other ways is really that valid. Again, that's just my opinion and I seem to be in the minority. smile


Invision Support
#Invision on irc.irchighway.net
Re: isodd :: iseven [Re: Riamus2] #193083 14/01/08 09:29 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
$nick() was added after isop, so it's not really an appropriate comparison.

As for size:
Code:
if (X & 1) ...
if (X isodd) ...


So it's actually longer than the most efficient and one of the most intuitive ways of doing the check. Not that it really matters, but just figured I'd point it out since you mentioned code length.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: isodd :: iseven [Re: Riamus2] #193085 14/01/08 09:32 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
There is no custom identifier involved in the //, \\ or & operators, so none of that is relevant.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: isodd :: iseven [Re: starbucks_mafia] #193088 14/01/08 10:00 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Before/after.... If $nick was first, would it be bad to add isop? Of course not, so the point still stands.

Ok, ignore the length. I wasn't really trying to compare length by saying smaller is better. I was just pointing out differences in size in case someone did bring it up... basically saying that the isop example is close and we still have it.

And, I was obviously mistaken in the size of the examples... I was going by memory (stupid idea for me) and because they were shown as 3 lines because of the brackets and what you want done if $true, I "remembered" it being larger than it was. I should have looked before talking about the length. Again, though... the length was just to curb any talk about length. I should have just left that out, I suppose. shocked

I still disagree about your examle being one of the "most intuitive" methods. I mean, from a person with little math background and little scripting/programming background, why in the world would they think that & (1 not 2) would give them whether or not something is even/odd? If it's intuitive, it would be obvious without having to figure it out or have it pointed out. & or % isn't intuitive at all without those backgrounds. "isodd" or "iseven" would be intuitive for just about anyone. I mean, you could walk up to a kid who knows evens and odds and ask, "If 10 iseven say Yes". The child would understand. That's intuitive. On the other hand, if you ask most people, "If 10 MOD 2 say Yes", they'd look at you like you had two heads.

So, ignore what I metioned of length and just take in the rest.


Invision Support
#Invision on irc.irchighway.net
Re: isodd :: iseven [Re: argv0] #193089 14/01/08 10:02 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
I was responding to LostShadow's comments about custom identifiers, where he said they'd be faster than a built in method. And, for anyone who wanted to, they could make a custom $isodd/$iseven identifier using a method of obtaining that. The point I was making is that a built in method would not be slower than the custom identifier method. LostShadows said it would be. It really had nothing to do with whether or not to add it. Just correcting what he said.

In any case, as I said, I know I'm in the minority for thinking adding it would be good. I understand that and accept it. Just pointing out my thoughts on it.


Invision Support
#Invision on irc.irchighway.net
Re: isodd :: iseven [Re: Riamus2] #193093 14/01/08 10:20 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
You have a valid point for wanting the shortcut but not for needing it (I know you dont need it BTW). What I'm trying to say is shortcuts however handy they may sound at first it also promotes bad thinking. If you cant figure a way to check if a number is odd or even, even the most crappy if (. isin $1) method, then isodd/iseven wont help them any further because after that they'll be stuck on the next "mystery". Most of the current shortcuts actually shortcut something used on a regular basis that would feel repetitive having to repeat all the time. if (N & 1) or if (2 \\ N) is hardly repetitive.


$maybe
Re: isodd :: iseven [Re: Mpdreamz] #193096 14/01/08 11:06 PM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
I do agree that custom identifiers are slower, hence my alias calculate { example for $calculate() being a clone of $calc().

But, if we combine these sources for the built-in identifier, $isodd().

Code:
alias isodd {
if ($calc(X % 2)) {
  ; X is odd
}
if (X & 1) {
  ; X is odd
}
if ($right(X,1) isin 13579) {
  ; X is odd.
}
if ($and(X,1)) {
  ; X is odd.
}
if (. isin $calc(X / 2)) {
  ; X is odd
}
}


Then, I would have to say, the built-in identifier is slower.

The problem is I pasted the above in mIRC scripting, when in fact, Khaled codes identifiers in C++ or something.

Therefore, if you used only 1 of the above code, for your custom--identifier, then it would be faster.

But before that, it just simply depends on the code source. It's possible that a build-in identifier could be so complex (from checking all the possibilities) that simply using a custom identifier is faster.

And I guess a built-in $isodd identifier, would not be as combined. You could code a non-built $isodd extremely complex, whereas a very simple custom-identifier could be faster. But of course, none of us could know that unless we see Khaled's built source.

Page 1 of 2 1 2