[issue8817] Expose round-to-nearest division algorithm in Objects/longobject.c

2010-05-26 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Ah, good point. I knew there was a reason I didn't like Py_XDECREF. I'll fix this and then apply this patch tonight. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8817

[issue8817] Expose round-to-nearest division algorithm in Objects/longobject.c

2010-05-26 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Committed (with the DECREF(one) fix) in r81541. -- components: +Interpreter Core resolution: - accepted stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org

[issue8817] Expose round-to-nearest division algorithm in Objects/longobject.c

2010-05-25 Thread Mark Dickinson
New submission from Mark Dickinson dicki...@gmail.com: The implementation of 'round' for Python integers uses a round-to-nearest form of divmod: a, b - q, r, where q is the nearest integer to a / b and r = a - b*q. This form of divmod would be useful elsewhere. In particular, it's currently

[issue8817] Expose round-to-nearest division algorithm in Objects/longobject.c

2010-05-25 Thread Alexander Belopolsky
Alexander Belopolsky belopol...@users.sourceforge.net added the comment: Just a few nitpicks on the patch (in increasing pickiness): 1. Any reason to prefer PyTuple_SetItem to PyTuple_SET_ITEM at the end of _PyLong_Divmod_Near? You are filling a brand new tuple, so PyTuple_SET_ITEM seems to

[issue8817] Expose round-to-nearest division algorithm in Objects/longobject.c

2010-05-25 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Thanks for reviewing! Updated patch, that addresses points 1-3. For 4, there's no need for the old code, since self - divmod_near(self, 10**-n)[1] is enough. And I didn't like the old algorithm anyway; the new one is more

[issue8817] Expose round-to-nearest division algorithm in Objects/longobject.c

2010-05-25 Thread Alexander Belopolsky
Alexander Belopolsky belopol...@users.sourceforge.net added the comment: Looking at Py_DECREF(one); result = PyTuple_New(2); if (result == NULL) goto error; .. error: Py_XDECREF(one); If PyTuple_New fails, wouldn't it result in one being DECREF's twice? --