mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Joined: Mar 2007
Posts: 60
S
Babel fish
Offline
Babel fish
S
Joined: Mar 2007
Posts: 60
odd, if $calc(1 / banana) returns 0 then shouldnt $calc(1 +d 3) return 0.

Unless because the d is in the same parameter as the addition sign. This might cause everything after the first parameter to become invalid, returning only the first parameter, 1.


"In order to succeed, your desire for success should be greater than your fear of failure."
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
looks like there's a lot more happening here than it seems:

$calc(1 -+-- 2) -> 3
$calc(1 -+- 2) -> -1
$calc(1 -/- 2) -> 1
$calc(1 -/-- 2) -> 0
$calc(1 ++--++-- 2) -> 3
$calc(1 +++--++-- 2) -> -1
$calc(1 ++--++--/ 2) -> 0

some weird results shocked would be less confusing if every invalid operator was treated as such, and caused itself and the rest of the expression to be ignored


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Weird results indeed. I'm not sure if this is part of what you were pointing out, but plus and minus signs should be chainable. However mIRC is still getting the wrong values for some of the calculations you gave. ie.

Code:
$calc(1 -+-- 2) 	->  3 (should be -1)
$calc(1 -+- 2) 		-> -1 (should be 3)
$calc(1 -/- 2) 		->  1 (should be an error)
$calc(1 -/-- 2)		->  0 (should be an error)
$calc(1 ++--++-- 2)	->  3 (correct)
$calc(1 +++--++-- 2)	-> -1 (should be 3)
$calc(1 ++--++--/ 2)	->  0 (should be an error)


mIRC appears to incorrectly treat the additional plus signs with the same behaviour as if they were minuses, whereas they should all be discarded from the calculation.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Actually, looking at some of those numbers logically, they seem correct.

Assuming that + and - = cancel, and - and - = +
It also seems that mIRC takes the last extra minus sign and assumes it is the +- indicator on the last number (2 in this case).

$calc(1 -+-- 2) -> $calc(1 - -2) -> 3
$calc(1 -+- 2) -> $calc(1 - 2) -> -1

$calc(1 ++--++-- 2) -> $calc(1 + -2) -> -1 (wrong)
$calc(1 +++--++-- 2) -> $calc(1 ++ -2) -> $calc(1 + -2) -> -1

(It is hard to know the order of operations that mIRC uses with the extra + and -.

-genius_at_work

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A plus and a minus don't cancel each other out though. Once a minus is introduced all of the plus signs can be ignored (ie. $calc(2 - 3) could also be expressed as $calc(2 + -3) or any number of pluses without changing the result)

$calc(1 +++--++-- 2) is equivalent to $calc(1 ---- 2) which might be easier to think of as this: $calc(1 - (-(-(-2)))). Another way to think about it is that two minuses equal a plus, so $calc(1 ---- 2) is the same as $calc(1 ++ 2), or more simply: $calc(1 + 2).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Regardless of whether it is mathematically correct or not, the answers mostly follow a logical pattern (as I described above). That fact could help determine why $calc is returning the values that it returns. I don't know if Khaled simply passes $1 from $calc to the programming language's calculation function, or if he parses it first.

In any case, it is just an observation.

-genius_at_work

Joined: Mar 2007
Posts: 60
S
Babel fish
Offline
Babel fish
S
Joined: Mar 2007
Posts: 60
$1- not $1 :P

And you are right. The way $calc is used might be through the language's calculations therefore there is very little he can do without parsing it first. And then there is parsing it, and just the way he parses it is a little bit dodgy.


"In order to succeed, your desire for success should be greater than your fear of failure."
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
There's no equivalent to $calc() in C++. It's being parsed either by Khaled's own code or via a third-party library. Most likely Khaled's own since there's nothing listed in the "Acknowledgements" section in the help file.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Okay so i'm thinking...

$calc(2 - 3) = $calc(+2-+3) = -1
$calc(2 + -3) = $calc(+2+-3) = $calc(+2-+3) = -1
$calc(1 +++--++-- 2) = $calc(+1+++--++--+2) = $calc(+1++-+-+-+2) = $calc(+1+-2) = $calc(+1-+2) = -1
$calc(1 ---- 2) = $calc(+1----+2) = $calc(+1+-+-+-+-+2) = $calc(+1+2) = 3

I think I arrived at this by placing a + to the left of every character that isn't +. But my brain is scrabled. I can't make sense of anything now. I do know that this was really a waist of time. mIRC has a ton of inconsitanies that wreck havoc when you start doing some complicated stuff. I mean just look at /set and /var...

/var <var> = 1 + 2 ; <var> = 3
/set <var> = 1 + 2 ; <var> = = 1 + 2

And they both call the /set alias too! WTF!?! (I'm starting another thread about this)


Beware of MeStinkBAD! He knows more than he actually does!
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Actually, it is just $1 (in mIRC terms). $calc is an identifier, therefore $1 $2 etc are populated by the comma-delimited arguments within the () of $calc().

Example:

alias idtest { echo -a 1: $1 | echo -a 2: $2 }

//noop $idtest(1 + 2)


$calc only supports one argument (the equation). If you add a comma (to populate $2 $3 etc) you will get an invalid format error.

-genius_at_work

Page 2 of 2 1 2

Link Copied to Clipboard