Document: WG14 N1738

## Background on -yx and -y/v

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.

1. exponents and roots
2. multiplication and division
3. addition and subtraction

There exist differing conventions concerning the unary operator "-" (usually read "minus"). In written or printed mathematics, the expression -32 is interpreted to mean -(32) = -9, but in some applications, -32 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:

1. Factorial.
2. Exponentiation.
3. Multiplication.
4. Division.
5. Addition.

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

PEMDAS:

1. Parentheses
2. Exponents
3. Mutiplication and Division
4. Addition and Subtraction

BODMAS:

1. Brackets
2. Orders
3. Division and Mutiplication
4. 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.