On Fri, Sep 18, 2015 at 10:04 AM, David L Carlson <dcarl...@tamu.edu> wrote:
> Unfortunately the order of operations is not universal in computing. The > real question is whether a program performs the way it is documented. Excel > documents that unary operations take precedence over exponentiation and > that within groups, the order is left to right. LibreOffice Calc behaves as > Excel, but does not document the order of operations except to say */ > before +-, left to right. I couldn't find any statement about the order of > operations in the documentation for Gnumeric. > > R documents that unary operations come after exponentiation and, within > exponentiation, the order is right to left. Fortran puts unary operations > with addition and subtraction after exponentiation with exponentiation > right to left. C does not have an exponentiation operator, but unary > operations come before multiplication and division. > > When in doubt, use parentheses to make sure you get what you want. > > Very true. I do that if there is almost any chance that I, or another, might not actually know which is first. I especially adopted this when I learned a language called APL. It has _no_ precedence of operations. And it does them from right to left. E.g. A=B*C+D is interpreted as A=B*(C+D). I did programming in it for a couple of months. Then went back to normal programming. Wrote completely _wrong_ code. When I asked a friend why the calculation didn't get the "right" answer (2*4+3 == 14 was example I gave), he looked at me like I was insane <grin/>. -- Schrodinger's backup: The condition of any backup is unknown until a restore is attempted. Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be. He's about as useful as a wax frying pan. 10 to the 12th power microphones = 1 Megaphone Maranatha! <>< John McKown [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.