[Python-Dev] Floats as indexes
Aahz
aahz@pythoncraft.com
Sun, 28 Jul 2002 23:17:24 -0400
On Sun, Jul 28, 2002, Guido van Rossum wrote:
>
> >>> "%d" % 3.14
> '3'
> >>> a = []
> >>> a.insert(0.9, 42)
> >>> a
> [42]
> >>>
>
> I find the second example more aggravating than the first. This
> touches upon a recent discussion, where one of the suggestions was
> to use __index__ rather than __int__ in this case. I think that's
> not the right solution; perhaps instead, floats and float-like types
> should support __truncate__ and __round__ to convert them to ints in
> certain ways. (Of course then we can argue about whether to round to
> even, and what to do if the float is so large that its smallest unit
> of precision is larger than one.)
Blech. I believe that floats and similar objects should never be
implicitly converted to indexes. There are too many ways for silent
errors to get propagated.
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
Project Vote Smart: http://www.vote-smart.org/