**Document:** WG14 N1738

**Submitter:** Fred J. Tydeman (USA)

**Submission Date:** 2013-08-20

**Subject:**Background on -yx and -y/v

In the many math books I have read over the years, I have never seen anything about operator precedence. So, when converting from the math -yv to C, it could be one of:

- (-y)*v
- -(y*v)
- (-1)*(y*v)
- ((-1)*y)*v
- 0-(y*v)

What does -x mean? The two obvious choices are:

- 0-x
- (-1)*x

However, -1 depends upon the meaning of -x (so is recursive loop).

I did a web search for "order of operations math" and got many hits.

http://en.wikipedia.org/wiki/Order_of_operations has:

- exponents and roots
- multiplication and division
- addition and subtraction

There exist differing conventions concerning the unary
operator "-" (usually read "minus"). In written or printed
mathematics, the expression -3^{2} is interpreted to mean -(3^{2})
= -9, but in some applications, -3^{2} is interpreted to mean
(-3)^{2} = 9.

Similarly, there can be ambiguity in the use of the slash ('/') symbol in expressions such as 1/2x. It can mean (1/2)x or 1/(2x).

The above wikipedia URL has a reference to http://planetmath.org/orderofoperations which has a different order of operations:

- Factorial.
- Exponentiation.
- Multiplication.
- Division.
- Addition.

Another web hit is: http://www.purplemath.com/modules/orderops.htm has:

PEMDAS:

- Parentheses
- Exponents
- Mutiplication and Division
- Addition and Subtraction

BODMAS:

- Brackets
- Orders
- Division and Mutiplication
- Addition and Subtraction

But, in the fine print, that site adds: Multiplication by juxtaposition is stronger than normal multiplication. So, 1/2x is done as 1/(2x), while 1/2*x is done as (1/2)*x.

Notice: In all of those web sites, the order is missing: unary "-" ("negate").

My suggestion for the tables in G.5.1 is:

- -yv should be done as (-y)v
- -x/v shoule be done as (-x)/v

Reason:

Negate is not affected by rounding, but gives the correct sign of the final result. The product or division is then done, which is affected by rounding. If you do negate after rounding, you end up with the wrong result for asymmetric rounding.