Unary minus precedence preference

07242014, 01:57 AM
Post: #21




RE: Unary minus precedence preference
(07232014 10:10 PM)htom trites Wrote: This really comes down to precedence and associations. Part of the reason that 02^2 "feels like" 4 is that our minds bind the  as a subtraction (which it is, it's not unary!) 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 (0x), 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, 0x 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: ab = 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 

« Next Oldest  Next Newest »

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