Post Reply 
Unary minus precedence preference
07-23-2014, 12:08 PM (This post was last modified: 07-23-2014 01:40 PM by Wes Loewer.)
Post: #13
RE: Unary minus precedence preference
(07-21-2014 08:00 PM)Claudio L. Wrote:  While symbolic object support in newRPL is getting ready to be released in a new demo, I stumbled upon the unary minus precedence ambiguity:

Excel does: -2^2 = 4
while almost everybody else give -2^2= -4

I implemented it as -2^2=-4 for the time being (just to follow the herd), but are there any good reasons to choose one precedence or the other?

I'd say the best reason for choosing -4 is because that's the one that is correct. :-)

Every math textbook will indicate that -2^2 = -4. Yes, there are programmers that have chosen to make their product produce a result of 4, but the standard convention is -4.

I like this guy's slant on it:
http://lpsolit.wordpress.com/2011/05/17/...y-to-them/

Interesting that MS-Excel did not follow the then de-facto standard Lotus 1-2-3 in this. Lotus 1-2-3, along with Quattro-Pro, Lotus Improv, Apple-Works, and even MS-Works all used the standard behavior. I can't help but wonder if it was a programmer error that then had to be maintained for compatibility. Now that Excel is the de-facto standard, OpenOffice/LibreOffice, Google Docs, and others feel the pressure to follow suit.

(07-21-2014 08:00 PM)Claudio L. Wrote:  Are there any other ambiguities that I need to be aware of regarding other operators?
Well, there's always a^b^c. Some treat it as (a^b)^c (Casio & older TI calculators) while others use a^(b^c) (HP in Algebraic mode & newer TI calculators). This one doesn't have a standard mathematical equivalent since the ^ character is not used in math for exponentiation, but a^(b^c) more likely matches what the user intended since the rising superscript fonts are evaluated from the top down.

-wes

[minor correction: The site http://macnauchtan.com/pub/precedence.html indicated that MS-Works did not behave the same as Excel, but when I tried versions 2.0 (DOS) and 4.5a (Win95) I found that they did behave like Excel.]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Unary minus precedence preference - Wes Loewer - 07-23-2014 12:08 PM



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