mIRC Home    About    Download    Register    News    Help

Page 1 of 2 1 2 >
Topic Options
#192939 - 13/01/08 04:18 AM isodd :: iseven
foshizzle Offline
Fjord artisan

Registered: 20/08/07
Posts: 333
Loc: Silicon Valley
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

Top
#192940 - 13/01/08 04:49 AM Re: isodd :: iseven [Re: foshizzle]
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
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.

Top
#192948 - 13/01/08 10:31 AM Re: isodd :: iseven [Re: foshizzle]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
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

Top
#192958 - 13/01/08 01:50 PM Re: isodd :: iseven [Re: foshizzle]
Doqnach Offline
Hoopy frood

Registered: 18/01/03
Posts: 1063
and another possible way:

Code:
if ($calc(X % 2) == 0) {
  ; is even
}
_________________________
If it ain't broken, don't fix it!

Top
#192971 - 13/01/08 05:18 PM Re: isodd :: iseven [Re: Doqnach]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
And another:

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

Top
#192972 - 13/01/08 05:49 PM Re: isodd :: iseven [Re: hixxy]
Mpdreamz Offline
Hoopy frood

Registered: 27/04/04
Posts: 759
Loc: Arnhem, The Netherlands
and another:
Code:
if ($and(X,1)) {
  ; X is odd.
}
_________________________
$maybe

Top
#192975 - 13/01/08 06:12 PM Re: isodd :: iseven [Re: Mpdreamz]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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"

Top
#192981 - 13/01/08 07:10 PM Re: isodd :: iseven [Re: foshizzle]
Mentality Offline
Planetary brain

Registered: 01/06/03
Posts: 5024
Loc: London, England
I apologise for them.
_________________________
Mentality/Chris

Top
#192988 - 13/01/08 09:07 PM Re: isodd :: iseven [Re: Mentality]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#193004 - 14/01/08 12:11 AM Re: isodd :: iseven [Re: Riamus2]
Bekar Offline
Fjord artisan

Registered: 11/12/02
Posts: 503
Loc: Melbourne, Australia
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.

Top
#193006 - 14/01/08 12:16 AM Re: isodd :: iseven [Re: Riamus2]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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"

Top
#193012 - 14/01/08 01:17 AM Re: isodd :: iseven [Re: argv0]
foshizzle Offline
Fjord artisan

Registered: 20/08/07
Posts: 333
Loc: Silicon Valley
well thx for the suggestions/examples i guess
_________________________
This is not the signature you are looking for

Top
#193075 - 14/01/08 08:48 PM Re: isodd :: iseven [Re: foshizzle]
LostShadow Offline
Fjord artisan

Registered: 12/01/04
Posts: 509
Loc: Chicago, Illinois, U.S.A.
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.

Top
#193082 - 14/01/08 09:22 PM Re: isodd :: iseven [Re: LostShadow]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#193083 - 14/01/08 09:29 PM Re: isodd :: iseven [Re: Riamus2]
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
$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.

Top
#193085 - 14/01/08 09:32 PM Re: isodd :: iseven [Re: Riamus2]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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"

Top
#193088 - 14/01/08 10:00 PM Re: isodd :: iseven [Re: starbucks_mafia]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#193089 - 14/01/08 10:02 PM Re: isodd :: iseven [Re: argv0]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#193093 - 14/01/08 10:20 PM Re: isodd :: iseven [Re: Riamus2]
Mpdreamz Offline
Hoopy frood

Registered: 27/04/04
Posts: 759
Loc: Arnhem, The Netherlands
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

Top
#193096 - 14/01/08 11:06 PM Re: isodd :: iseven [Re: Mpdreamz]
LostShadow Offline
Fjord artisan

Registered: 12/01/04
Posts: 509
Loc: Chicago, Illinois, U.S.A.
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.

Top
Page 1 of 2 1 2 >