[SciPy-Dev] tricky unary versus binary minus

Robert Kern robert.kern at gmail.com
Sat Feb 18 00:03:38 EST 2017


On Fri, Feb 17, 2017 at 9:00 PM, <josef.pktd at gmail.com> wrote:
>
> just an observation
>
> >>> bwi
> 25
> >>> - bwi // 2    # not what I wanted
> -13
> >>> 0 - bwi // 2
> -12
> >>> - (bwi // 2)
> -12
>
> different rules from float division
>
> >>> 0 - bwi / 2
> -12.5
> >>> - bwi / 2
> -12.5
>
> bug in my code

The rules (of operator precedence) are the same in both cases; unary
negation binds tighter than either division, which in turn binds tighter
than binary subtraction. It's just that in the latter case, both orders of
operations just happen to give the same result for these values.

--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20170217/4b1340c5/attachment.html>


More information about the SciPy-Dev mailing list