Post Reply 
Unary minus precedence preference
07-24-2014, 01:57 AM
Post: #21
RE: Unary minus precedence preference
(07-23-2014 10:10 PM)htom trites Wrote:  This really comes down to precedence and associations. Part of the reason that 0-2^2 "feels like" -4 is that our minds bind the - as a subtraction (which it is, it's not unary!)

The conflict is that unary - , to be truly unary, has to bind as or higher than parentheses; -2^2 has to become (-2)^2.

So there is no unary -, it's just a writing convention of deleting the 0.

Regarding the existence or not of the unary minus operator, I think in computing the unary minus is very real. I don't know if it meets your standards to be "truly unary" but it is real enough for all HP calculators to have a key dedicated to the unary minus (NEG, +/-, CHS), and a separate one for the binary minus.
And more so thinking in RPN, where there's no ambiguity, no operator precedence, and not even algebraic expressions. Yet the unary minus exists by itself.
I could also point out that in two's complement, the unary minus is not defined as (0-x), but it's defined as (~x)+1, where ~ is an operator that toggles all bits (XOR 0xFFFFFFF...). Granted, with the properly defined subtraction in the same domain, 0-x should give the same result as -x, but the definition of the unary minus exists by itself and is independent from the binary minus. And in hardware where you have only adders, it's common to define the binary minus in terms of the unary minus:
a-b = a+(-b) = a+(~b)+1
So in that case, the unary minus exists, but the binary minus doesn't!
And I guess you could generalize that and say that the subtraction doesn't exist, it's actually the addition of a negative number.
It's all a matter of perspective.

Claudio
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Unary minus precedence preference - Claudio L. - 07-24-2014 01:57 AM



User(s) browsing this thread: 1 Guest(s)