[Python-Dev] [Python-checkins] r64424 - in python/trunk:Include/object.h Lib/test/test_sys.py Misc/NEWSObjects/intobject.c Objects/longobject.c Objects/typeobject.cPython/bltinmodule.c

Nick Coghlan ncoghlan at gmail.com
Thu Jun 26 16:52:57 CEST 2008


Raymond Hettinger wrote:
> FYI, I had already updated the patch to incorporate your suggestion.
> It checks __index__ first and then __float__ if index doesn't exist.
> The result makes it work with Decimal inputs.

Only sort of - the domain of the output is then constrained by what the 
builtin float type can represent, which strikes me as fairly 
inappropriate for what should be a lossless display operation (both 
fractions.Fraction and decimal.Decimal can represent a lot of numbers 
that float can't deal with properly). To use the old faithful example of 
this, given:

 >>> float(Decimal("1.1"))
1.1000000000000001

what happens for bin(Decimal("1.1")) with the patch version that uses 
__float__?

As I've said elsewhere in this thread, I'm certainly not averse to the 
basic idea of letting bin/oct/hex handle rational numbers as well as 
integers, I just don't see it as something we have to have in the 
current release cycle, and nor do I see it really working properly 
without adding a __rational__ special method that returns a 
numerator/denominator 2-tuple (which would obviously require a PEP).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list