#112796  27/02/05 10:08 PM
Re: $calc(2^2) == INCORRECT

Hoopy frood
Registered: 02/11/03
Posts: 2327

Yeah, I cheated in C++ because pow() doesn't accept negative numbers :tongue:
_________________________
New username: hixxy

Top




#112797  28/02/05 10:04 AM
Re: $calc(2^2) == INCORRECT

Fjord artisan
Registered: 30/12/02
Posts: 208

I've given this a lot of thought, and I came up with what I hope is an informed opinion. The question here is this: in the equation 2^2, is the  associated with just the 2 that it is next to, or is it associated with the entire 2^2? That is, would 2^2 be (2)^2, or (2^2). The answer, according to the correct order of operations, is (2^2), or 4. However, in: var %negativetwo = 2 echo a $calc(%negativetwo ^2) the  is clearly and unambiguously associated with the 2 only, and so the echo should give 4. Now it comes down to whether or not mIRC's parser will allow $calc to know that the 2 in there came from a variable, and treat it as such (perhaps by, at least internally, enclosing it in parenthesis/brackets.) Here is the part of the show where I list pros and cons for "fixing" this: Pros: a) It would be technically correct (the only pro I can think of) Cons: a) It will likely break at least some scripts out there. b) fixing it must not come at the expense of breaking legitimate code, such as the example with %variables. I don't have an intimate knowlege of mIRC's script parser, so I don't know how easy that would be, or even if it could be done without extensive modification. In conclusion, if I were to be the one to make this decision, I would decide based upon how much work would have to be put into it. I see little sense in working long hours to fix something that nobody noticed until shortly before the product's 10th anniversary (happy bday, mIRC!!) if someone else is going to complain that now their script doesn't work. Fortunately, the burden isn't on me, but it is Khaled that must choose. In other news, I hear that Microsoft Excel agrees with mirc that 2^2 = 4.
Edited by Hrung (28/02/05 10:08 AM)

Top




#112798  28/02/05 08:14 PM
Re: $calc(2^2) == INCORRECT

Ameglian cow
Registered: 22/02/03
Posts: 32

Just to add to the discussion:
C#:
System.Diagnostics.Debug.WriteLine(2^2);
4
Java:
System.out.println(2^2);
4
VB .NET:
Debug.WriteLine(2 ^ 2)
4
PHP (5.0.3):
echo 2^2;
4
Excel indeed returns "4" when 2^2 is entered as a function.

Top




#112799  01/03/05 04:30 AM
Re: $calc(2^2) == INCORRECT

Fjord artisan
Registered: 26/03/04
Posts: 540

To add a bit more, my fiance is a college student going to be a teacher where her focus/specialty is math so I went and asked her since this is all fresh in her mind. She looked in her fancy teacher books and it is postive 4 just mine and her 2 cents Edit: (2)^2 is how it is supposed to look when you go to eval it
Edited by Armada (01/03/05 04:32 AM)

Top




#112800  01/03/05 11:54 PM
Re: $calc(2^2) == INCORRECT

Babel fish
Registered: 11/07/03
Posts: 77
Loc: Alabama (yes we have computers...

i have a ti89 calculate and if you do 2^2 it will say 4 so it always takes it as (2)^2 so it sees the negative as out in front, same happens on 83's HOWEVER as always if you put it as (2)^2 it will be 4 As far as i know that is how it should behave w/o () around the 2 or the 2 being like var %two = 2 i would say that it should auto see 2 as (2) thats what the ti's do at least 2>a a^2 = 4 My 2 cents as well.
_________________________
hmmm signed by me

Top




#112801  07/03/05 08:46 PM
Re: $calc(2^2) == INCORRECT

Babel fish
Registered: 10/12/02
Posts: 86
Loc: California, USA

No matter how you look at it, there's going to be HUGE opinion regarding this. You're always taught that multiplication supercedes addition/subtraction. But, in this case, it looks as though you have a problem. The order of operations states that it's left to right unless a supercede interrupts the process, thus eliminating rules until the operation takes place, putting order back to left to right. In this case, we have 2^2, but with it as is, and everyone not wanting to interpret it in any fancy order: (2)^2, (0  2)^2, 0  2 ^ 2, or whatever else you can think of, it's simply a matter of everyone's opinion, including mine. If you were to ask me, I would have to explain as follows:
2^2  A number that is already labeled negative must stay there, because if we go on to changing things the way we want (0  2), in my opinion, we screw up the whole mathematical system. The equations must be interpretted as they are written. So, in this case, have negative 2 squared 2 times, 2^2. So, following the order of operations' alloted cases where multiplication supercedes any other form of calculation, you must identify that this equation is multiplying a negative number twice, which allows you to end up with a positive. I'm stating this as OPINION because that's what it is. I could be wrong, or I could be right, it's all opinion. You can't say, well this is (2)^2, because that is NOT how this operation is written. If there is a rule that will allow you to write just that, then I think that is the missing link that we are searching for. If you slice it, you see (2)^2, (2)^2. Either way, your negative attachment is superceding the multiplication because it is a multiplication in itself. You are negotiating the point of whether the number is positive or negative, which is noted as an operation of importance to that of multiplication/division, so this MUST be concluded before any multiplication is done. Why? Order of operations tells us that it is to be performed left to right, unless an operation of higher law/imporance is apparent before that calculation can take place, in which case those operations are performed beforehand, left to right of course. Once those operations have been done, you can continue with normal left>right operation. In this case, however, we have 2 cases where left>right has the same rule of operation as each other.
Anyhow, I'm open to other suggestions that heed incorrect on this. Sorry for the long post ;)
_________________________
Zmodem

Top




#112802  07/03/05 10:22 PM
Re: $calc(2^2) == INCORRECT

Hoopy frood
Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK

Do you even understand what you wrote there?
The case of whether it should be 4 or 4 is solely down to whether you take the minus symbol to be the unary negative operator or a component of the number 2. Seeing that plain string in any programming language or on paper I would take the answer to be 4, and if it were down to that then I'd say anyone disagreeing with it is wrong outright. The only place where it's not so clear is the fact that mIRC has no numeric type and so, as several people have pointed out, a variable with the value 2 put into $calc() will behave functionally equivalent as the plain string whereas it would in 99% of cases be meant as a representation of a negative number.
I think mIRC's $calc() should be a little more advanced in it's parsing and treat input from variables as if surrounded by parentheses. Scripters who wanted to override this behaviour could always use evaluation brackets.
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top




#112803  08/03/05 08:11 AM
Re: $calc(2^2) == INCORRECT

Babel fish
Registered: 10/12/02
Posts: 86
Loc: California, USA

Agreed completely, as for understanding, of course I do. The only problem here seems to be that I couldn't stop typing, for whatever reason. Go figure...
_________________________
Zmodem

Top




#112804  08/03/05 02:42 PM
Re: $calc(2^2) == INCORRECT

Ameglian cow
Registered: 18/12/02
Posts: 39
Loc: Sweden

You my friend are so encouraging:) Mentioning Haskell and Prolog in the same thread, kudos!=)

Top




#112805  11/03/05 10:38 PM
Re: $calc(2^2) == INCORRECT

Vogon poet
Registered: 03/02/05
Posts: 194
Loc: Georgia, USA

I am confused, considering I AM in grade school :tongue:, however, i'll still throw in my own two cents: 2^2 = (2)(2) When multiplying two numbers with the same sign, the product will be positive. So, (2)(2) = 4. For all I know, i'm completely wrong. :tongue:
_________________________
"God sometimes puts us in the dark for us to see the light"

Top




#112806  11/03/05 11:51 PM
Re: $calc(2^2) == INCORRECT

Pikka bird
Registered: 04/11/04
Posts: 16

I am confused, considering I AM in grade school :tongue:, however, i'll still throw in my own two cents: 2^2 = (2)(2) When multiplying two numbers with the same sign, the product will be positive. So, (2)(2) = 4. For all I know, i'm completely wrong. :tongue: it was said before: (2)^2 = (2)*(2)= 4 but 2^2 = 1*(2^2) = 1*4 = 4 how simple

Top




#112807  12/03/05 11:00 PM
Re: $calc(2^2) == INCORRECT

Fjord artisan
Registered: 09/12/02
Posts: 266
Loc: Australia

My LG mobile phone says 2^2 is 4. Life's Good with LG.
_________________________
You won't like it when I get angry.

Top




#112808  13/03/05 01:09 AM
Re: $calc(2^2) == INCORRECT

Planetary brain
Registered: 26/09/03
Posts: 4230

OK OK OK I HAVE HAD ENOUGH
I have checked and the official answer is 2^2 is exactly 0 (+/4)

Top




#112809  16/05/05 11:28 AM
Re: $calc(2^2) == INCORRECT

Hoopy frood
Registered: 18/02/03
Posts: 2594

HAHAHA. I love that answer Dave. Glad I revisited this thread. It seems this equation is really a loaded gun in academia, bringing about a fervent debate in any field of science. You'll get completely different answers from a math professor than you would a physics or computer science professor. Put them in the same room and watch them go. It's hours of fun! The key to remember is that physics and computer science professors haven't touched algebra since they were 13, and probably don't remember this rule anyway. While they may be correct in how their mind wraps around the mathimatical problem, they are incorrect in how the written expression is officially translated from ink into problem. Unlike the English language which relies heavily on context, mathimatical syntax has to be black and white, even if it means creating obscure rules that make 2^2 = 4.
_________________________
Well. At least I won lunch. Good philosophy, see good in bad, I like!

Top




#112810  16/05/05 02:07 PM
Re: $calc(2^2) == INCORRECT

Planetary brain
Registered: 13/10/04
Posts: 8327
Loc: MA, USA

Really, it's just a matter of how a program looks at the expression. If you have a negative sign (not a minus sign), then it automatically treats it as (2). If you use a minus sign, then it treats it as 2. When you square it, you have (2^2) with a minus sign and (2)^2 for the negative sign. Both are correct like DaveC said. This is why you should use ()'s with anything ambiguous. For mIRC, use ()'s and it will work just fine.
_________________________
Invision Support #Invision on irc.irchighway.net

Top




#112811  17/05/05 01:55 AM
Re: $calc(2^2) == INCORRECT

Fjord artisan
Registered: 30/12/02
Posts: 208

Just nitpicking, but ()'s cannot remove ambiguity from such an equation, because there is no ambiguity to begin with. The order of operations clearly states how "2^2" (or any other equation for that matter) should be interpretted. Math is a form of logic, and logic can't say anything for certain if there is any ambiguity in one of the steps. ()'s are a part of the language of math and, properly used, can only change the meaning of the equation, not clarify it. "Properly used" here means not just thrown in for fun. In fact, extra ()'s can make an equation more difficult, or at least more time consuming, for a person to sort out. Simple example: (((1) + 1) + 1) = 1 + 1 + 1. None of the ()'s make any difference to the outcome, they just make it take slightly longer to read. Again, I'm only having fun splitting hairs here. My opinion on the problem itself was already summed up in an earlier post.
_________________________
If I knew now what I will know then... maybe things will have been different...

Top




#112812  17/05/05 02:56 AM
Re: $calc(2^2) == INCORRECT

Planetary brain
Registered: 13/10/04
Posts: 8327
Loc: MA, USA

Parentheses are used to change the order of operation. In this case, it is necessary to let the program know you want the order of operation to be different from that which it uses as a default. Yes, I know you already know that. I'm just clarifying as you seem to have done with previous statement. That is why I said that in cases where a mathematical operation is "ambiguous" (by this if you read the context, I'm talking about where order of operations is in question), it can and will prevent issues. It is true that you don't have to add them all over the place, but they are needed at certain times.
In this case, the "correct" order of operation without parentheses would be 2^2 * 1 = 4. A minus operation whether by negative sign or by an actual minus is done after powers. In fact, multiplication and division (both of which are done before any minus/negative operation) is done after exponents.
2*2^3 = 16 if you don't use parentheses
If you wanted 4^3, you have to use parentheses just has you would with 2^2 (aka 1*2^2).
_________________________
Invision Support #Invision on irc.irchighway.net

Top




#112813  17/05/05 06:31 PM
Re: $calc(2^2) == INCORRECT

Hoopy frood
Registered: 18/02/03
Posts: 2594

Dude, you guys still don't get it.
You are forbidden from adding paranthasis to the expression, because doing so would change the expression.
2^2 is perfectly valid and unambiguous on its own. Nothing else but 2^2 is the same written expression as 2^2. Modifying the expression changes the expression and invalidates your arguement, because you'd be talking about a whole new expression entirely.
Now presuming that modifying the expression with paranthesis is forbidden, and acknowledging that 2^2 is a valid expression in its own... Know that 2^2 is equal to 4 and nothing else.
No IFs, ANDs or BUTs. Final. It is mathmatical LAW.
_________________________
Well. At least I won lunch. Good philosophy, see good in bad, I like!

Top




#112814  17/05/05 07:09 PM
Re: $calc(2^2) == INCORRECT

Planetary brain
Registered: 13/10/04
Posts: 8327
Loc: MA, USA

Exactly. My comments regarding parentheses was to show what must be done to get 2^2 to be equal to +4. Like in my last post, exponents are done before multiplication/division/addition/subtraction if you have no parentheses to change the order of operation.
_________________________
Invision Support #Invision on irc.irchighway.net

Top




#112815  17/05/05 09:10 PM
Re: $calc(2^2) == INCORRECT

Hoopy frood
Registered: 12/04/03
Posts: 701
Loc: Leuven, Belgium

It's not a mathematics forum here, it's a mIRC scripting forum. This means that the parsing of an expression is done by mIRC and that parsing is unambiguous since it always returns 4 for 2^2.
(ps: oh no, not again)

Top





