숫자 프로토콜

int PyNumber_Check(PyObject *o)
Part of the Stable ABI.

객체 o가 숫자 프로토콜을 제공하면 1을 반환하고, 그렇지 않으면 거짓을 반환합니다. 이 함수는 항상 성공합니다.

버전 3.8에서 변경: o가 인덱스 정수면 1을 반환합니다.

PyObject *PyNumber_Add(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2를 더한 결과나, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 + o2와 동등합니다.

PyObject *PyNumber_Subtract(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1에서 o2를 뺀 결과나, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 - o2와 동등합니다.

PyObject *PyNumber_Multiply(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2를 곱한 결과나, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 * o2와 동등합니다.

PyObject *PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI since version 3.7.

o1o2를 행렬 곱셈한 결과나, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 @ o2와 동등합니다.

버전 3.5에 추가.

PyObject *PyNumber_FloorDivide(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

Return the floor of o1 divided by o2, or NULL on failure. This is the equivalent of the Python expression o1 // o2.

PyObject *PyNumber_TrueDivide(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

Return a reasonable approximation for the mathematical value of o1 divided by o2, or NULL on failure. The return value is “approximate” because binary floating point numbers are approximate; it is not possible to represent all real numbers in base two. This function can return a floating point value when passed two integers. This is the equivalent of the Python expression o1 / o2.

PyObject *PyNumber_Remainder(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2로 나눈 나머지나, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 % o2와 동등합니다.

PyObject *PyNumber_Divmod(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

내장 함수 divmod()를 참조하십시오. 실패하면 NULL을 반환합니다. 이것은 파이썬 표현식 divmod(o1, o2)와 동등합니다.

PyObject *PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3)
Return value: New reference. Part of the Stable ABI.

내장 함수 pow()를 참조하십시오. 실패하면 NULL을 반환합니다. 이것은 파이썬 표현식 pow(o1, o2, o3)와 동등합니다, 여기서 o3는 선택적입니다. o3를 무시하려면, 그 자리에 Py_None을 전달하십시오 (o3NULL을 전달하면 잘못된 메모리 액세스가 발생합니다).

PyObject *PyNumber_Negative(PyObject *o)
Return value: New reference. Part of the Stable ABI.

성공 시 o의 음의 값(negation)을, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 -o와 동등합니다.

PyObject *PyNumber_Positive(PyObject *o)
Return value: New reference. Part of the Stable ABI.

성공 시 o를, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 +o와 동등합니다.

PyObject *PyNumber_Absolute(PyObject *o)
Return value: New reference. Part of the Stable ABI.

o의 절댓값이나, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 abs(o)와 동등합니다.

PyObject *PyNumber_Invert(PyObject *o)
Return value: New reference. Part of the Stable ABI.

성공 시 o의 비트 반전(bitwise negation)을, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 ~o와 동등합니다.

PyObject *PyNumber_Lshift(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2만큼 왼쪽으로 시프트 한 결과를, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 << o2와 동등합니다.

PyObject *PyNumber_Rshift(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2만큼 오른쪽으로 시프트 한 결과를, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 >> o2와 동등합니다.

PyObject *PyNumber_And(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2의 “비트별 논리곱(bitwise and)”을, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 & o2와 동등합니다.

PyObject *PyNumber_Xor(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2의 “비트별 배타적 논리합(bitwise exclusive or)”을, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 ^ o2와 동등합니다.

PyObject *PyNumber_Or(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2의 “비트별 논리합(bitwise or)”을, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 o1 | o2와 동등합니다.

PyObject *PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2를 더한 결과나, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 += o2와 동등합니다.

PyObject *PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1에서 o2를 뺀 결과나, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 -= o2와 동등합니다.

PyObject *PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2를 곱한 결과나, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 *= o2와 동등합니다.

PyObject *PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI since version 3.7.

o1o2를 행렬 곱셈한 결과나, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 @= o2와 동등합니다.

버전 3.5에 추가.

PyObject *PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2로 나눈 수학적 플로어(floor)나, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 //= o2와 동등합니다.

PyObject *PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

Return a reasonable approximation for the mathematical value of o1 divided by o2, or NULL on failure. The return value is “approximate” because binary floating point numbers are approximate; it is not possible to represent all real numbers in base two. This function can return a floating point value when passed two integers. The operation is done in-place when o1 supports it. This is the equivalent of the Python statement o1 /= o2.

PyObject *PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

o1o2로 나눈 나머지나, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 %= o2와 동등합니다.

PyObject *PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3)
Return value: New reference. Part of the Stable ABI.

내장 함수 pow()를 참조하십시오. 실패하면 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 o3가 Py_None일 때 파이썬 문장 o1 **= o2와, 그렇지 않으면 pow(o1, o2, o3)의 제자리 변형과 동등합니다. o3를 무시하려면, 그 자리에 Py_None을 전달하십시오 (o3NULL을 전달하면 잘못된 메모리 액세스가 발생합니다).

PyObject *PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2만큼 왼쪽으로 시프트 한 결과를, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 <<= o2와 동등합니다.

PyObject *PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2만큼 오른쪽으로 시프트 한 결과를, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 >>= o2와 동등합니다.

PyObject *PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2의 “비트별 논리곱(bitwise and)”을, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 &= o2와 동등합니다.

PyObject *PyNumber_InPlaceXor(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2의 “비트별 배타적 논리합(bitwise exclusive or)”을, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 ^= o2와 동등합니다.

PyObject *PyNumber_InPlaceOr(PyObject *o1, PyObject *o2)
Return value: New reference. Part of the Stable ABI.

성공 시 o1o2의 “비트별 논리합(bitwise or)”을, 실패 시 NULL을 반환합니다. 이 연산은 o1이 지원하면 제자리에서(in-place) 수행됩니다. 이것은 파이썬 문장 o1 |= o2와 동등합니다.

PyObject *PyNumber_Long(PyObject *o)
Return value: New reference. Part of the Stable ABI.

성공 시 정수 객체로 변환된 o를, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 int(o)와 동등합니다.

PyObject *PyNumber_Float(PyObject *o)
Return value: New reference. Part of the Stable ABI.

성공 시 float 객체로 변환된 o를, 실패 시 NULL을 반환합니다. 이것은 파이썬 표현식 float(o)와 동등합니다.

PyObject *PyNumber_Index(PyObject *o)
Return value: New reference. Part of the Stable ABI.

성공 시 파이썬 int로 변환된 o를, 실패 시 NULL을 반환합니다. 실패 시 TypeError 예외가 발생합니다.

버전 3.10에서 변경: The result always has exact type int. Previously, the result could have been an instance of a subclass of int.

PyObject *PyNumber_ToBase(PyObject *n, int base)
Return value: New reference. Part of the Stable ABI.

정수 n을 진수 base를 사용해서 변환한 문자열을 반환합니다. base 인자는 2, 8, 10 또는 16중 하나여야 합니다. 진수 2, 8 또는 16의 경우, 반환된 문자열은 '0b', '0o' 또는 '0x'의 진수 표시자가 각각 앞에 붙습니다. n이 파이썬 int가 아니면, 먼저 PyNumber_Index()로 변환됩니다.

Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc)
Part of the Stable ABI.

Returns o converted to a Py_ssize_t value if o can be interpreted as an integer. If the call fails, an exception is raised and -1 is returned.

If o can be converted to a Python int but the attempt to convert to a Py_ssize_t value would raise an OverflowError, then the exc argument is the type of exception that will be raised (usually IndexError or OverflowError). If exc is NULL, then the exception is cleared and the value is clipped to PY_SSIZE_T_MIN for a negative integer or PY_SSIZE_T_MAX for a positive integer.

int PyIndex_Check(PyObject *o)
Part of the Stable ABI since version 3.8.

Returns 1 if o is an index integer (has the nb_index slot of the tp_as_number structure filled in), and 0 otherwise. This function always succeeds.