in reply to Re: Operator Precedence (unary nagation and exponentiation)
in thread Operator Precedence (unary negation and exponentiation)

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?

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

Replies are listed 'Best First'.
Re: Operator Precedence (unary negation and exponentiation)
by Abigail-II (Bishop) on Jan 14, 2003 at 13:19 UTC
    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