lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> There IS a solution available that isn't confused by your first two
> examples, but it's not particularly elegant: when a unary minus
> expression is parsed, and the operand is a constant, the parser folds
> them together in the syntax tree instead of emitting an actual
> negation operation. (Your last example isn't just "arguably" the
> explicit negation, the use of parentheses makes it DEFINITELY an
> explicit negation because the parentheses mean you're demanding that
> the expression inside is computed BEFORE you apply the unary minus.)

Java singles out this particular case :-)

    It is a compile-time error if a decimal literal of type int is
    larger than 2147483648 (2^31), or if the decimal literal 2147483648
    appears anywhere other than as the operand of the unary minus
    operator (§15.15.4).
    [...]
    It is a compile-time error if a decimal literal of type long is
    larger than 9223372036854775808L (2^63), or if the decimal literal
    9223372036854775808L appears anywhere other than as the operand of
    the unary minus operator (§15.15.4).

    https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.1

-- Roberto