Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Operator precedence for: 1/-2/3

  1. Feb 9, 2012 #1
    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?
     
  2. jcsd
  3. Feb 9, 2012 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    That sounds backwards to me.
     
  4. Feb 9, 2012 #3

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    If "division is performed before unary minus", what does 1/-2 mean?
     
  5. Feb 9, 2012 #4
    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.

    The ordering of the symbols fundamentally disallows the / to be performed first here.
     
    Last edited: Feb 9, 2012
  6. Feb 9, 2012 #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).
     
  7. Feb 10, 2012 #6

    Mark44

    Staff: Mentor

    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.
     
  8. Feb 10, 2012 #7

    jedishrfu

    Staff: Mentor

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Operator precedence for: 1/-2/3
  1. 1/3 = 0.333 (Replies: 94)

  2. 1 + 1 = 3 (Replies: 28)

  3. 1 Divided by 3 (Replies: 60)

Loading...