Operator precedence for: 1/-2/3

  • Thread starter Thread starter Twinbee
  • Start date Start date
  • Tags Tags
    Operator
AI Thread Summary
The discussion centers on the expression 1/-2/3, presenting two potential results: A (-0.1666666667) and B (-1.5). Most programming languages and calculators support result A, while some argue that B aligns better with operator precedence, suggesting division occurs before applying the unary minus. The debate highlights that the order of operations can lead to confusion, particularly regarding how division and unary minus interact. The consensus leans towards using parentheses for clarity, as the lack of them can lead to misinterpretation of the intended calculation. Ultimately, the conversation underscores the importance of understanding operator precedence in mathematical expressions.
Twinbee
Messages
116
Reaction score
0
The sum below has two potential answers:

A: 1/-2/3 = -0.1666666667
B: 1/-2/3 = -1.5

Programming languages and most (but not all) calculators claim A is correct.

However, B seems to follow operator precedence more accurately as the division is performed before the unary minus. Using brackets:

1/(-(2/3))
...makes more sense than:
(1/-2)/3

Is there a more official stance on the issue?
 
Mathematics news on Phys.org
Twinbee said:
division is performed before the unary minus.
That sounds backwards to me.
 
If "division is performed before unary minus", what does 1/-2 mean?
 
That sounds backwards to me.
Okay, most people would agree that:

-3^2 = -9

So there the exponential operator has precedence over the unary minus. If ^ has precedence, it makes sense to reason that / and * should have precedence too.

If "division is performed before unary minus", what does 1/-2 mean?

The ordering of the symbols fundamentally disallows the / to be performed first here.
 
Last edited:
The order of the unitary minus has nothing to do with it. The unitary minus is equivalent to multiplying by -1. The question is which division is performed first and the convention is to use some D*** parentheses!
When there is no good reason to assume someone can figure out what you mean, don't assume someone can figure out what you mean, just say it. However, if you have a gun to you head and are asked which one is right, I'd say "A" since it reads left to right and there is no convention in math (maybe there is in compsci where the computer doesn't have an option to think about it).
 
Twinbee said:
Okay, most people would agree that:

-3^2 = -9

So there the exponential operator has precedence over the unary minus. If ^ has precedence, it makes sense to reason that / and * should have precedence too.
But the ^ operator is different from the arithmetic operators +, -, *, and /, and has higher precedence. For that reason, 3^2 + 2 is evaluated as 9 + 2 = 11, rather than 3^(2+2) = 81. Similarly 2 * 3^2 = 2 * 9 = 18, not 6^2 = 36.
 
Back
Top