[Patches] fix overflow bug in ldexp(x, exp)

Guido van Rossum guido@python.org
Tue, 09 May 2000 06:24:03 -0400


> Note another current revoltingism:
> 
> >>> range(1., 8., 3.5)
> [1, 4, 7]
> >>>
> 
> OK by me if all such crap "gets broke".

Ditto here.  But it's hard to fix.  This was the consequence of a
patch by Don Beaudry (remember Don?) with a good purpose: if an
extension type supports "int-ness", e.g. by defining a tp_int function
in its type object or (for a class instance) by having an __int__
method, it is acceptable for integral formats (e.g. i) in
PyArg_Parse*().  Unfortunately, floats also have int-ness, in order to
support the int() built-in function.

I'm not sure how to fix this, but I believe that the best fix might be
to define separate APIs an object can expose for int-ness and for
roundable-or-truncatable-to-int-ness.  Seems a Py3k issue though.

BTW, this also suggests that Trent's recent patches to string methods
are slightly backward incompatible, since they specifically check for
int-or-long-ness.  However, since these arguments are *documented* as
behaving just like slice indices, and slice indices do the same thing,
I think it's best to leave it like this.  If we find a lot of user
complaints of needlessly broken code, we can back out of this one...

--Guido van Rossum (home page: http://www.python.org/~guido/)