mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
S
Spitfire3292
Spitfire3292
S
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.

#175227 19/04/07 10:43 AM
Joined: Feb 2006
Posts: 523
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 523
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,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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.

Joined: Oct 2005
Posts: 1,671
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,671
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,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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).

Joined: Oct 2005
Posts: 1,671
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,671
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

S
Spitfire3292
Spitfire3292
S
$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.

#175325 20/04/07 10:19 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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.

M
MeStinkBAD
MeStinkBAD
M
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)

#175377 21/04/07 06:22 PM
Joined: Oct 2005
Posts: 1,671
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,671
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