Well, knowing my routines, -4^0.5 is evaluated as (-4)^0.5. So i do not know why it gives such a result...
Printable View
Well, knowing my routines, -4^0.5 is evaluated as (-4)^0.5. So i do not know why it gives such a result...
Whilist it is true that in most languages, unary minus has very high precedence, in most usual languages ^ does not mean power. However, in cases when it does mean power, it does usually have higher precedence. In addition, when power is implimented as another symbol (** in Pascal springs to mind) it is usually higher than unary subtract.
Therefore, I think most people would expect:
-4^0.5 to be -(4^0.5) = -2
Of course, you can do what you like and these rules are only for convenience, but I'd say how it works now is correct.
In c++, unary minus is evaluated before nearly every other operator, but it doesn't have a pow operator.
Excel apparently does the unary minus before powers.
Wikipedia claims that powers should be done first.
I've just tested MMF2 and it does do (-4) pow 2, so I don't know where the claim it did any different came from. The counter displays it as "-1." (numbers form), but the debugger shows the full -1.#IND.
EDIT: In fact even in the case of '0 - value("counter") pow 0.5' (MMF has no negate operator, have to put "0 - ") it does the subtract first, which probably IS wrong.No that's wrong, my counter had a value of -4. MMF handles it correctly
"Excel apparently does the unary minus before powers." -- Just tested and you are right. That is very very odd. Perhaps it is the best behavour for MMF then if Excel does it.
Still, I do think that evalaulating power is quite an established tradition. For instance, you would always write (-2)^2 instead of -2^2.
"In c++, unary minus is evaluated before nearly every other operator, but it doesn't have a pow operator." - Yeah it is true that it is very high on the precedence table.
and that's why I always use parentheses :)