in reply to Operator Precedence (unary negation and exponentiation)

Fortran *duck* does the same ...

-- Hofmator

  • Comment on Re: Operator Precedence (unary nagation and exponentiation)

Replies are listed 'Best First'.
Re: Re: Operator Precedence (unary negation and exponentiation)
by Elliott (Pilgrim) on Jan 14, 2003 at 12:55 UTC
    Hmmm... well if it goes back to Fortran, then it's nearly as old as I am! I wonder if some compiler writer, tripping on 60s chemicals, got it wrong and his mistake has been passed from generation to generation or if, in fact, there is some very good reason for this order.

    Anyone got any thoughts on why it might be better in some context to evaluate exponentiation before unary negation? Or (less likely but possible) does anyone know the actual history?

      Because unary negation is actually a multiplication? And that everyone agrees that 4 * 3 ** 2 equals 36, and not 144? Of course, that's just guessing. Note that
      echo '-2^2' | bc
      gives you 4, and not -4.

      Abigail