Unary minus precedence preference
|
07-23-2014, 04:16 AM
Post: #12
|
|||
|
|||
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)? In the context of a compiler, it needs to be dependent on the standard of the language in question. Dig far enough into any language standard and you should find (1) precedence rules for the exponentiation and unary minus operators, and (2) a precise definition of what is meant by the unary minus. The C standard sidesteps this issue in part by not providing a built-in exponentiation operator. It has this to say about the unary minus: "The result of the unary - operator is the negative of its (promoted) operand." This may leave some room for interpretation and implementation of "negative," but this is generally well-defined in the context of established binary integer representations and floating-point standards. So, again, it essentially comes down to a convention. And any language that does not specify a clear-cut convention for operations like -2^2 is certainly asking for trouble! John |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)