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

Mark Dickinson report at bugs.python.org
Tue May 25 14:56:02 CEST 2010

New submission from Mark Dickinson <dickinsm at 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 needed for implementing multiplication and division of timedeltas by a float:  see issue 1289118  .

This patch exposes the operation to Python C code as _PyLong_Divmod_Near, and refactors long_round to use this operation.

assignee: mark.dickinson
files: div_nearest.patch
keywords: patch
messages: 106431
nosy: mark.dickinson
priority: normal
severity: normal
status: open
title: Expose round-to-nearest division algorithm in Objects/longobject.c
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file17459/div_nearest.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list