[Tutor] floating point rounding inconsistency

eryksun eryksun at gmail.com
Fri Sep 28 23:07:11 CEST 2012


On Fri, Sep 28, 2012 at 9:17 AM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> On 28/09/2012 13:37, Steven D'Aprano wrote:
>
>> Deprecating and dropping features causes pain to developers who are
>> already using them correctly. There is strong opposition on deprecating
>> round.
>
> And there is strong support for deprecating round.  Personally I'm staying
> out of the blood bath as I've never used it :)

That would be an odd back-step since Python 3 generalized the built-in:

    >>> class Test:
    ...     def __round__(self, ndigits=None):
    ...         return 1
    ...
    >>> round(Test())
    1

Also, float, Decimal, and Fraction in Python 3 return an int when the
ndigits argument is omitted. For example, float rounds using the math
lib's round function, then rounds that to even, and returns
PyLong_FromDouble. Is the discussion just about removing the ndigits
aspect but keeping the round-to-int aspect?


More information about the Tutor mailing list