Post Reply 
Unary minus precedence preference
06-04-2024, 11:54 AM
Post: #41
RE: Unary minus precedence preference
(07-23-2014 03:14 AM)htom trites Wrote:  Do you take -2^2 to mean: (-2)^2, -(2^2), or 0-(2^2)?

I've always taught that unary minus is the last (and should be parsed as if it was that by a computer), even though it's usually written as the second.

(I admit I came to this conclusion writing a compiler that emitted code for both one's and two's complement ALUs.)

I don't see any practical difference between your second and third meanings, only a notational difference.

On HP Prime and TI nNspire II CAS (and many others, it would seem) the unary minus is assigned the same priority as addition and subtraction so the exponentiation is done first.

-2^2 is seen as
-(2^2)

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Unary minus precedence preference - toml_12953 - 06-04-2024 11:54 AM



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