Re: Problem with exponentiation: -2**2 gives 4 instead of -4



On May 26, 5:11 am, Don Porter <dgpor...@xxxxxxxxxxx> wrote:
Kevin Kenny wrote:
It's not even an EIAS issue. If we were designing [expr]
from scratch or willing to accept the incompatibility,
it could simply not include a leading sign in *its* notion
of a numeric literal.  

That is the way the [expr] parser works.  All literal
"-" and "+" characters in the expression are operators.
None are treated as part of a literal number.

That is good to know, and it helps the analysis.

The EIAS explanation make it sound like Tcl is somehow unique among
programming languages, in that the developers got something wrong.
There has to be a defined order of precedence: how will a program
order instructions for execution? [expr] isn't unique, it is just a
special case with for semi-numeric calculations.

I don't really think it is valid to apply algebraic notation to
programming statements, but I am still struck that there is some
confusion about the difference between the negation operator (unary
minus) and the subtraction operator (binary minus). Even in algebra,
the two are kept separate.

For instance, in defining different types of number domains, you run
into stuff like this: if a > b, then a - b is non-negative. Note that
"a" and "b" is a notation which includes the sign. Both a and b could
be negative in the above condition. In Tcl, like many programming
languages, a and b could be substituted in many different ways.

In the example:

expr {0 - 3/4} => 0, 3/4 is a number (0), so it is equivalent to [expr
{0 - 0}]. If we take the first 0 to be a, then we could chose a number
b less than 0 and see what binary minus gets us:

expr {0 - -3/4} => 1, so the general rule of numbers holds here.

Otherwise, instead of complaining about the evils of unary minus, we
should complain about 3/4 == 0. Which is more or less "intuitive"
here?

Unary minus, is an operator which is applied first, when all these
unary operators are applied, then binary minus can be applied:

expr {1---2**2} => -3
expr {1-+-2**2} => -3
expr {1+-2**2} => 5
expr {1--2.0**-2.0} => .75 (1-1.0/-2**2)
.



Relevant Pages

  • Re: First use of Lisp at work!
    ... unary minus having lower precedence than ... I don't know who the various infix languages cope with it, ...
    (comp.lang.lisp)
  • Re: defining inverse number
    ... Binary minus is not fundamental ... because it can be represented via unary minus, which in turn is just a ... So subtraction is really adding the additive inverse. ...
    (sci.math)
  • Re: defining inverse number
    ... real and complex number algebra). ... Binary minus is not fundamental ... because it can be represented via unary minus, which in turn is just a ... From -a to a required the use of an additional operator, viz. ...
    (sci.math)
  • defining inverse number
    ... real and complex number algebra). ... Binary minus is not fundamental ... because it can be represented via unary minus, which in turn is just a ... via fundamental operators and constants? ...
    (sci.math)