Long Integer Objects

PyLongObject

此子类型的 PyObject represents a Python long integer object.

PyTypeObject PyLong_Type

此实例的 PyTypeObject represents the Python long integer type. This is the same object as long and types.LongType .

int PyLong_Check ( PyObject  *p )

返回 True 若其自变量是 PyLongObject 或子类型的 PyLongObject .

2.2 版改变: Allowed subtypes to be accepted.

int PyLong_CheckExact ( PyObject  *p )

返回 True 若其自变量是 PyLongObject ,但不是子类型的 PyLongObject .

2.2 版新增。

PyObject * PyLong_FromLong ( long  v )
返回值:新引用。

返回新的 PyLongObject 对象从 v ,或 NULL 当故障时。

PyObject * PyLong_FromUnsignedLong ( unsigned long  v )
返回值:新引用。

返回新的 PyLongObject 对象从 C unsigned long ,或 NULL 当故障时。

PyObject * PyLong_FromSsize_t ( Py_ssize_t  v )
返回值:新引用。

返回新的 PyLongObject 对象从 C Py_ssize_t ,或 NULL 当故障时。

2.6 版新增。

PyObject * PyLong_FromSize_t ( size_t  v )
返回值:新引用。

返回新的 PyLongObject 对象从 C size_t ,或 NULL 当故障时。

2.6 版新增。

PyObject * PyLong_FromLongLong ( PY_LONG_LONG  v )
返回值:新引用。

返回新的 PyLongObject 对象从 C long long ,或 NULL 当故障时。

PyObject * PyLong_FromUnsignedLongLong ( unsigned PY_LONG_LONG  v )
返回值:新引用。

返回新的 PyLongObject 对象从 C unsigned long long ,或 NULL 当故障时。

PyObject * PyLong_FromDouble ( double  v )
返回值:新引用。

返回新的 PyLongObject 对象从整数部分的 v ,或 NULL 当故障时。

PyObject * PyLong_FromString ( char  *str , char  **pend , int  base )
返回值:新引用。

返回新的 PyLongObject 基于字符串值 str , which is interpreted according to the radix in base 。若 pend 为非 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 based 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 不是 0 , it must be between 2 and 36 , inclusive. Leading spaces are ignored. If there are no digits, ValueError 会被引发。

PyObject * PyLong_FromUnicode ( Py_UNICODE  *u , Py_ssize_t  length , int  base )
返回值:新引用。

Convert a sequence of Unicode digits to a Python long integer value. The first parameter, u , points to the first character of the Unicode string, length gives the number of characters, and base is the radix for the conversion. The radix must be in the range [2, 36]; if it is out of range, ValueError 会被引发。

New in version 1.6.

Changed in version 2.5: This function used an int for length . This might require changes in your code for properly supporting 64-bit systems.

PyObject * PyLong_FromVoidPtr ( void  *p )
返回值:新引用。

Create a Python integer or long integer from the pointer p . The pointer value can be retrieved from the resulting value using PyLong_AsVoidPtr() .

1.5.2 版新增。

Changed in version 2.5: If the integer is larger than LONG_MAX, a positive long integer is returned.

long PyLong_AsLong ( PyObject  *pylong )

返回 C long representation of the contents of pylong 。若 pylong 大于 LONG_MAX OverflowError is raised and -1 将被返回。

long PyLong_AsLongAndOverflow ( PyObject  *pylong , int  *overflow )

返回 C long representation of the contents of pylong 。若 pylong 大于 LONG_MAX 或小于 LONG_MIN , set *overflow to 1 or -1 , respectively, and return -1 ; otherwise, set *overflow to 0 . If any other exception occurs (for example a TypeError or MemoryError), then -1 will be returned and *overflow 将是 0 .

2.7 版新增。

PY_LONG_LONG PyLong_AsLongLongAndOverflow ( PyObject  *pylong , int  *overflow )

返回 C long long representation of the contents of pylong 。若 pylong 大于 PY_LLONG_MAX 或小于 PY_LLONG_MIN , set *overflow to 1 or -1 , respectively, and return -1 ; otherwise, set *overflow to 0 . If any other exception occurs (for example a TypeError or MemoryError), then -1 will be returned and *overflow 将是 0 .

2.7 版新增。

Py_ssize_t PyLong_AsSsize_t ( PyObject  *pylong )

返回 C Py_ssize_t representation of the contents of pylong 。若 pylong 大于 PY_SSIZE_T_MAX OverflowError is raised and -1 将被返回。

2.6 版新增。

unsigned long PyLong_AsUnsignedLong ( PyObject  *pylong )

返回 C unsigned long representation of the contents of pylong 。若 pylong 大于 ULONG_MAX OverflowError 被引发。

PY_LONG_LONG PyLong_AsLongLong ( PyObject  *pylong )

返回 C long long from a Python long integer. If pylong cannot be represented as a long long OverflowError is raised and -1 被返回。

2.2 版新增。

unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong ( PyObject  *pylong )

返回 C unsigned long long from a Python long integer. If pylong cannot be represented as an unsigned long long OverflowError is raised and (unsigned long long)-1 被返回。

2.2 版新增。

2.7 版改变: A negative pylong 现在引发 OverflowError , not TypeError .

unsigned long PyLong_AsUnsignedLongMask ( PyObject  *io )

返回 C unsigned long from a Python long integer, without checking for overflow.

2.3 版新增。

unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask ( PyObject  *io )

返回 C unsigned long long from a Python long integer, without checking for overflow.

2.3 版新增。

double PyLong_AsDouble ( PyObject  *pylong )

返回 C double representation of the contents of pylong 。若 pylong cannot be approximately represented as a double OverflowError exception is raised and -1.0 将被返回。

void* PyLong_AsVoidPtr ( PyObject  *pylong )

Convert a Python integer or long integer pylong 到 C void 指针。若 pylong 无法转换, OverflowError will be raised. This is only assured to produce a usable void pointer for values created with PyLong_FromVoidPtr() .

1.5.2 版新增。

Changed in version 2.5: For values outside 0..LONG_MAX, both signed and unsigned integers are accepted.

上一话题

布尔对象

下一话题

浮点对象

本页