整數物件¶
All integers are implemented as "long" integer objects of arbitrary size.
On error, most PyLong_As* APIs return (return type)-1 which cannot be
distinguished from a number. Use PyErr_Occurred() to disambiguate.
-
type PyLongObject¶
- 為 受限 API 的一部分 (做為一個不透明結構 (opaque struct)).
This subtype of
PyObjectrepresents a Python integer object.
-
PyTypeObject PyLong_Type¶
- 為 穩定 ABI 的一部分.
This instance of
PyTypeObjectrepresents the Python integer type. This is the same object asintin the Python layer.
-
int PyLong_Check(PyObject *p)¶
Return true if its argument is a
PyLongObjector a subtype ofPyLongObject. This function always succeeds.
-
int PyLong_CheckExact(PyObject *p)¶
Return true if its argument is a
PyLongObject, but not a subtype ofPyLongObject. This function always succeeds.
-
PyObject *PyLong_FromLong(long v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from v, orNULLon failure.CPython 實作細節: CPython keeps an array of integer objects for all integers between
-5and256. When you create an int in that range you actually just get back a reference to the existing object.
-
PyObject *PyLong_FromUnsignedLong(unsigned long v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from a C unsigned long, orNULLon failure.
-
PyObject *PyLong_FromSsize_t(Py_ssize_t v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from a CPy_ssize_t, orNULLon failure.
-
PyObject *PyLong_FromSize_t(size_t v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from a Csize_t, orNULLon failure.
-
PyObject *PyLong_FromLongLong(long long v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from a C long long, orNULLon failure.
-
PyObject *PyLong_FromInt32(int32_t value)¶
-
PyObject *PyLong_FromInt64(int64_t value)¶
- 為 穩定 ABI 的一部分 自 3.14 版本開始.
Return a new
PyLongObjectobject from a signed C int32_t or int64_t, orNULLwith an exception set on failure.在 3.14 版被加入.
-
PyObject *PyLong_FromUnsignedLongLong(unsigned long long v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from a C unsigned long long, orNULLon failure.
-
PyObject *PyLong_FromUInt32(uint32_t value)¶
-
PyObject *PyLong_FromUInt64(uint64_t value)¶
- 為 穩定 ABI 的一部分 自 3.14 版本開始.
Return a new
PyLongObjectobject from an unsigned C uint32_t or uint64_t, orNULLwith an exception set on failure.在 3.14 版被加入.
-
PyObject *PyLong_FromDouble(double v)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectobject from the integer part of v, orNULLon failure.
-
PyObject *PyLong_FromString(const char *str, char **pend, int base)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Return a new
PyLongObjectbased on the string value in str, which is interpreted according to the radix in base, orNULLon failure. If pend is non-NULL, *pend will point to the end of str on success or to the first character that could not be processed on error. If base is0, str is interpreted using the Integer literals definition; in this case, leading zeros in a non-zero decimal number raises aValueError. If base is not0, it must be between2and36, inclusive. Leading and trailing whitespace and single underscores after a base specifier and between digits are ignored. If there are no digits or str is not NULL-terminated following the digits and trailing whitespace,ValueErrorwill be raised.也參考
PyLong_AsNativeBytes()andPyLong_FromNativeBytes()functions can be used to convert aPyLongObjectto/from an array of bytes in base256.
-
PyObject *PyLong_FromUnicodeObject(PyObject *u, int base)¶
- 回傳值:新的參照。
Convert a sequence of Unicode digits in the string u to a Python integer value.
在 3.3 版被加入.
-
PyObject *PyLong_FromVoidPtr(void *p)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分.
Create a Python integer from the pointer p. The pointer value can be retrieved from the resulting value using
PyLong_AsVoidPtr().
-
PyObject *PyLong_FromNativeBytes(const void *buffer, size_t n_bytes, int flags)¶
- 為 穩定 ABI 的一部分 自 3.14 版本開始.
Create a Python integer from the value contained in the first n_bytes of buffer, interpreted as a two's-complement signed number.
flags are as for
PyLong_AsNativeBytes(). Passing-1will select the native endian that CPython was compiled with and assume that the most-significant bit is a sign bit. PassingPy_ASNATIVEBYTES_UNSIGNED_BUFFERwill produce the same result as callingPyLong_FromUnsignedNativeBytes(). Other flags are ignored.在 3.13 版被加入.
- PyObject *PyLong_FromUnsignedNativeBytes(const void *buffer, size_t n_bytes, int