[Elliot Gorokhovsky <elliot.gorokhov...@gmail.com>] > I'm working on a special-case compare function for bounded integers for the > sort stuff. By looking at the implementation, I figured out that Py_SIZE of > a long is the sign times the number of digits (...right?). > ...
Please ignore the other reply you got - they clearly aren't familiar with the code. The details are explained in Include/longintrepr.h. In short, an integer _is_ based on PyVarObject. Py_SIZE is a macro that merely extracts (or allows to set) the ob_size member, the sign of the int is stored as the sign of ob_size (which is really an abuse of ob_size's intended meaning), and the number of "digits" is the absolute value of ob_size. And ob_size is 0 if and only if the int is 0. Note that the number of bits per digit varies across platforms. That too is all explained in longintrepr.h. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/