(-) precedence
|
12-09-2022, 04:02 PM
Post: #24
|
|||
|
|||
RE: (-) precedence
(12-08-2022 09:21 PM)Thomas Okken Wrote: Unary minus should have the same precedence as binary minus, that's the way it works in standard mathematical notation. Another way of understanding it is that -x is shorthand for 0-x. This is how modern Fortran does it, but many others had unary +/- above * / mod. (-a)*b = -(a*b) (-a)/b = -(a/b) We don't notice any difference until we added MOD operator. For example, this is from HP Prime emulator: CAS> 2 * 3 MOD 4 → 2 CAS> 2 MOD 3 * 4 → 8 This showed MOD had same precedence as MUL. It just evaluate from left to right. CAS> - 10 MOD 7 → 4 CAS> 0 - 10 MOD 7 → -3 This showed UNARY MINUS had higher precedence than MOD, thus also MUL and DIV |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)