Operator precedence for: 1/-2/3

  • Thread starter Twinbee
  • Start date
  • Tags
    Operator
In summary, there is a debate over the correct answer for the expression 1/-2/3, with answer A (-0.1666666667) being claimed as correct by programming languages and calculators, while answer B (-1.5) seems to follow operator precedence more accurately. The issue lies in the order of operations, with some arguing that division should be performed before unary minus, while others argue that the ordering of symbols disallows it. The convention in math is to use parentheses to clarify the order of operations, but in programming languages, there is a specific set of rules to follow. Ultimately, it comes down to personal preference and the specific language being used.
  • #1
Twinbee
117
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
  • #2
Twinbee said:
division is performed before the unary minus.
That sounds backwards to me.
 
  • #3
If "division is performed before unary minus", what does 1/-2 mean?
 
  • #4
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:
  • #5
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).
 
  • #6
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.
 

FAQ: Operator precedence for: 1/-2/3

1. What is operator precedence?

Operator precedence is the set of rules that determines the order in which the operations in an expression are evaluated. It is important to understand operator precedence in order to correctly interpret and evaluate mathematical expressions.

2. How is operator precedence determined?

The operator precedence is determined by the specific programming language or mathematical notation being used. In most cases, operators are evaluated from left to right, with some exceptions for certain operators like exponentiation and logical operators.

3. What is the operator precedence for 1/-2/3?

The operator precedence for 1/-2/3 is division, followed by division, and then multiplication. This means that the expression will be evaluated as (1/-2)/3, resulting in a value of -0.16667.

4. Can operator precedence be changed?

In most cases, the operator precedence cannot be changed, as it is determined by the programming language or mathematical notation. However, parentheses can be used to change the order of operations and override the default operator precedence.

5. Why is understanding operator precedence important?

Understanding operator precedence is important because it affects the outcome of mathematical expressions. Evaluating expressions incorrectly due to a lack of understanding of operator precedence can lead to errors in calculations and incorrect results.

Back
Top