[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Operator precedence and unary minus
- From: dyngeccetor8 <dyngeccetor8@...>
- Date: Tue, 22 May 2018 01:57:06 +0300
On 05/21/2018 11:47 PM, Egor Skriptunoff wrote:
> The problem arises because in Lua negation operator is "not commutative"
> with modulo:
> (-a) % b ~= - (a%b)
> That's why in Lua we have an unpleasant surprise:
> - a%m - b%n ~= - b%n - a%m> It's looks very weird.
> That should be an equality as in all other programming languages.
Probably in that languages negation operator _is_ commutative:
-(a % b) == (-a) % b
Lua 5.3 has four unary operators: "#", "~", "-", "not".
Lowering priority of "-" looks inconsistent.
Lowering priority of all unary operators hurts more than cures.