Message305844
On the main proposal: rounding an integer division to the nearest integer does seem to be a somewhat common need, and one that's not entirely trivial to code up and get right first time. (Unlike floor or ceiling of a quotient, which can be simply spelled as `n // d` or `-(-n // d)` respectively.) As Serhiy points out, it already turns up in multiple guises in the C source. The questions for me would be:
1. Is it actually a common enough need that we should add it?
2. If answer to (1) is yes, where should we add it? A method on the `int` type is one possible option, beyond the ones already mentioned.
3. There are actually three related operations here: (a) round a quotient to the nearest integer; (b) get the remainder of that rounding (the integer version of math.remainder), and (c) both (a) and (b) together. Which of those three should be implemented? (i.e., do we want the round-to-nearest analogs of div, mod, divmod, all three, or some nontrivial subset)? |
|
Date |
User |
Action |
Args |
2017-11-08 14:04:26 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, facundobatista, belopolsky, stutzbach, skrah, serhiy.storchaka, wolma |
2017-11-08 14:04:26 | mark.dickinson | set | messageid: <1510149866.71.0.213398074469.issue31978@psf.upfronthosting.co.za> |
2017-11-08 14:04:26 | mark.dickinson | link | issue31978 messages |
2017-11-08 14:04:26 | mark.dickinson | create | |
|