[issue5576] Don't use PyLong_SHIFT with _PyLong_AsScaledDouble()

Mark Dickinson report at bugs.python.org
Tue Dec 29 19:15:22 CET 2009

Mark Dickinson <dickinsm at gmail.com> added the comment:

> Long double (80 bits) exponent is in range [-16382; 16383] and so 
> fits in an int, unsigned int, size_t or Py_ssize_t.

Sure, but I don't think that's relevant to the point I was attempting to 
make:  PyLong_AsScaledDouble returns the number of bits in the given 
PyLong, and that number can be (theoretically) as large as 
PY_SSIZE_T_MAX * PyLong_SHIFT.  So Py_ssize_t is a better fit than int 
to hold this number:  otherwise you'll get unnecessary overflows on a 
64-bit system.

I'm working on refactoring PyLong_AsScaledDouble and PyLong_AsDouble to 
have them both use the same core code.  This would make 
PyLong_AsScaledDouble correctly rounded, and hence independent of the 
implementation of a PyLong (in particular, independent of the decision 
to use 15-bit or 30-bit digits for PyLongs: this decision really 
shouldn't affect the result of a log function or any other functions 
using _PyLong_AsScaledDouble).


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list