[Python-Dev] Floor division
Anders J. Munch
ajm at flonidan.dk
Tue Jan 23 10:19:25 CET 2007
Tim Peters wrote:
> Do note that this discussion is only about Python 3. Under the view
> that it was a (minor, but real) design error to /try/ extending
> Python's integer mod definition to floats, if __mod__, and __divmod__
> and __floordiv__ go away for binary floats in P3K they should
> certainly go away for decimal floats in P3K too.
What design error? float.__mod__ works perfectly.
>>> -1 % 50
49
>>> -1.0 % 50.0
49.0
>>>
It's only Decimal.__mod__ that's inconsistent. float.__mod__ has the
usual floating-point inaccuracies, but then with float that goes with
the territory.
I've had occasion to use it, and it was a pleasant surprise that it
"just worked", so I didn't have to go to the math module and ponder
over the difference between modulo or remainder. float modulo is
useful, consistent and intuitive; -1 on removing that.
- Anders
More information about the Python-Dev
mailing list