|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
Joined: Nov 2003
Posts: 2,327 |
Yeah, I cheated in C++ because pow() doesn't accept negative numbers :tongue:
New username: hixxy
|
|
|
|
Joined: Dec 2002
Posts: 208
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
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 b-day, 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.
Last edited by Hrung; 28/02/05 10:08 AM.
|
|
|
|
Joined: Feb 2003
Posts: 32
Ameglian cow
|
Ameglian cow
Joined: Feb 2003
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.
|
|
|
|
Joined: Mar 2004
Posts: 540
Fjord artisan
|
Fjord artisan
Joined: Mar 2004
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
Last edited by Armada; 01/03/05 04:32 AM.
|
|
|
|
Joined: Jul 2003
Posts: 77
Babel fish
|
Babel fish
Joined: Jul 2003
Posts: 77 |
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
|
|
|
|
Joined: Dec 2002
Posts: 87
Babel fish
|
Babel fish
Joined: Dec 2002
Posts: 87 |
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
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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.
|
|
|
|
Joined: Dec 2002
Posts: 87
Babel fish
|
Babel fish
Joined: Dec 2002
Posts: 87 |
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
|
|
|
|
Joined: Dec 2002
Posts: 39
Ameglian cow
|
Ameglian cow
Joined: Dec 2002
Posts: 39 |
You my friend are so encouraging:-) Mentioning Haskell and Prolog in the same thread, kudos!=)
|
|
|
|
Joined: Feb 2005
Posts: 194
Vogon poet
|
Vogon poet
Joined: Feb 2005
Posts: 194 |
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"
|
|
|
|
Joined: Nov 2004
Posts: 16
Pikka bird
|
Pikka bird
Joined: Nov 2004
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
|
|
|
|
Joined: Dec 2002
Posts: 266
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 266 |
My LG mobile phone says -2^2 is 4. Life's Good with LG.
You won't like it when I get angry.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
OK OK OK I HAVE HAD ENOUGH
I have checked and the official answer is -2^2 is exactly 0 (+/-4)
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
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!
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
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
|
|
|
|
Joined: Dec 2002
Posts: 208
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 208 |
Just nit-picking, 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...
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
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
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
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 un-ambiguous 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!
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
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
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
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)
|
|
|
|
|