7.2.2 Long Integer Objects

 

PyLongObject
This subtype of PyObject represents a Python long integer object.

PyTypeObject PyLong_Type
This instance of PyTypeObject represents the Python long integer type. This is the same object as types.LongType.  

int PyLong_Check(PyObject *p)
Returns true if its argument is a PyLongObject.

PyObject* PyLong_FromLong(long v)
Return value: New reference.
Returns a new PyLongObject object from v, or NULL on failure.

PyObject* PyLong_FromUnsignedLong(unsigned long v)
Return value: New reference.
Returns a new PyLongObject object from a C unsigned long, or NULL on failure.

PyObject* PyLong_FromDouble(double v)
Return value: New reference.
Returns a new PyLongObject object from the integer part of v, or NULL on failure.

long PyLong_AsLong(PyObject *pylong)
Returns a C long representation of the contents of pylong. If pylong is greater than LONG_MAX  an OverflowError is raised. 

unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
Returns a C unsigned long representation of the contents of pylong. If pylong is greater than ULONG_MAX  an OverflowError is raised. 

double PyLong_AsDouble(PyObject *pylong)
Returns a C double representation of the contents of pylong.

PyObject* PyLong_FromString(char *str, char **pend, int base)
Return value: New reference.
Return a new PyLongObject based on the string value in str, which is interpreted according to the radix in base. If pend is non-NULL, *pend will point to the first character in str which follows the representation of the number. If base is 0, the radix will be determined base on the leading characters of str: if str starts with '0x' or '0X', radix 16 will be used; if str starts with '0', radix 8 will be used; otherwise radix 10 will be used. If base is not 0, it must be between 2 and 36, inclusive. Leading spaces are ignored. If there are no digits, ValueError will be raised.

See About this document... for information on suggesting changes.