For integer n
, you can write n+1
and n-1
as -~n
and ~-n
, since
n+1
as-~n
n-1
as~-n
because the bit flip ~x
equals -1-x
. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.
Compare:
while n-1: #Same as while n!=1
while~-n:
(n+1)*2
-~n*2
c/(n-1)
c/~-n
or f(n)+1
or-~f(n)
(n-1)/10+(n-1)%10
~-n/10+~-n%10
The operators ~
and unary -
are higher precedence than *
, /
, %
, unlike binary +
.