[issue5576] Don't use PyLong_SHIFT with _PyLong_AsScaledDouble()
STINNER Victor
report at bugs.python.org
Fri Mar 27 01:23:23 CET 2009
New submission from STINNER Victor <victor.stinner at haypocalc.com>:
_PyLong_AsScaledDouble() writes the exponent in a int which have to be
multiplied by PyLong_SHIFT to give the power of 2. I proposed to
multiply the exponent by PyLong_SHIFT in _PyLong_AsScaledDouble() to
directly get the power of 2. It avoids complex code to test integer
overflow in code using _PyLong_AsScaledDouble() (the test is only done
once, in _PyLong_AsScaledDouble).
I also propose to change exponent type from "int*" to "unsigned int*".
Previous maximum exponent was INT_MAX//PyLong_SHIFT (eg. 143165576 for
PyLong using base 2^15). The new maximum is now
UINT_MAX//PyLong_SHIFT, the double ;-)
And since issue #4258 is commited (Use 30-bit digits instead of 15-bit
digits for Python integers), PyLong_SHIFT value may be different
depending on the compiler option. Using my patch, the long implement
will be a little bit more hidden.
The function _PyLong_AsScaledDouble() should be private because the
name starts with "_". But I see it in Include/longobject.h. In Python,
it's used in longobject.c and mathmodule.c.
----------
components: Interpreter Core
files: pylong_asscaleddouble-2.patch
keywords: patch
messages: 84236
nosy: haypo
severity: normal
status: open
title: Don't use PyLong_SHIFT with _PyLong_AsScaledDouble()
versions: Python 2.7, Python 3.1
Added file: http://bugs.python.org/file13428/pylong_asscaleddouble-2.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5576>
_______________________________________
More information about the Python-bugs-list
mailing list