
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 Josef

On Fri, Feb 17, 2017 at 9:00 PM, <josef.pktd@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


On Sat, Feb 18, 2017 at 12:04 AM, Alan Isaac <alan.isaac@gmail.com> wrote:
http://python-history.blogspot.com/2010/08/why-pythons- integer-division-floors.html
I need floor division for the remaining computation, so that part I'm happy with.(Actually, when I start to use divmod I have only non-negative numbers)
bwi = 5 np.arange(-bwi // 2, bwi // 2 + 1) array([-3, -2, -1, 0, 1, 2]) np.arange(-(bwi // 2), bwi // 2 + 1) array([-2, -1, 0, 1, 2])
the bug hunting was: Why is the window asymmetric? What threw me off is the operator precedence, what Robert said about operator precedence is kind of obvious ex-post, but the case where it matters doesn't show up often enough to automatically think about it, and the familiar float analogy doesn't apply. e.g. I avoid remembering some rules by using explicit, defensive parenthesis
1.5**(-2)
it's commutative
--2 / -3 -0.6666666666666666 ---2 / 3 -0.6666666666666666 ---(2 / 3) -0.6666666666666666
Josef
fwiw, Alan _______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org https://mail.scipy.org/mailman/listinfo/scipy-dev
participants (3)
-
Alan Isaac
-
josef.pktd@gmail.com
-
Robert Kern