diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-01-31 15:52:05 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-01-31 15:52:05 (GMT) |
commit | 5b8132ffa34244cc24b603d8462e6e733e014e71 (patch) | |
tree | 9ed5a901229b5dfef77b2f88ddf961f57a211f1a /Include/longobject.h | |
parent | 89fc4f3e5623d24632b1daf503a2f32ac2bd0d66 (diff) | |
download | cpython-5b8132ffa34244cc24b603d8462e6e733e014e71.zip cpython-5b8132ffa34244cc24b603d8462e6e733e014e71.tar.gz cpython-5b8132ffa34244cc24b603d8462e6e733e014e71.tar.bz2 |
_PyLong_NumBits(): The definition of this was too specific to the quirky
needs of pickling longs. Backed off to a definition that's much easier
to understand. The pickler will have to work a little harder, but other
uses are more likely to be correct <0.5 wink>.
_PyLong_Sign(): New teensy function to characterize a long, as to <0, ==0,
or >0.
Diffstat (limited to 'Include/longobject.h')
-rw-r--r-- | Include/longobject.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Include/longobject.h b/Include/longobject.h index 3b808fb..1ac213c 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -44,11 +44,17 @@ PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int); PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, int, int); #endif -/* _PyLong_NumBits. Return the number of bits needed to represent a long - in contiguous 2's-complement form, including 1 for the sign bit. For - example, this returns 1 for 0, and 2 for 1 and -1. Note that the - ceiling of this divided by 8 is the number of bytes needed by - _PyLong_AsByteArray to store the long in 256's-complement form. +/* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0. + v must not be NULL, and must be a normalized long. + There are no error cases. +*/ +PyAPI_FUNC(int) _PyLong_Sign(PyObject *v); + + +PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v); +/* _PyLong_NumBits. Return the number of bits needed to represent the + absolute value of a long. For example, this returns 1 for 1 and -1, 2 + for 2 and -2, and 2 for 3 and -3. It returns 0 for 0. v must not be NULL, and must be a normalized long. (size_t)-1 is returned and OverflowError set if the true result doesn't fit in a size_t. |