数値型プロトコル (number protocol)¶
-
int
PyNumber_Check(PyObject *o)¶ オブジェクト o が数値型プロトコルを提供している場合に
1を返し、そうでないときには偽を返します。この関数呼び出しは常に成功します。バージョン 3.8 で変更: o がインデックス整数だった場合、
1を返します。
-
PyObject*
PyNumber_Add(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 を加算した結果を返し、失敗すると
NULLを返します。Python の式o1 + o2と同じです。
-
PyObject*
PyNumber_Subtract(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 から o2 を減算した結果を返し、失敗すると
NULLを返します。Python の式o1 - o2と同じです。
-
PyObject*
PyNumber_Multiply(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 を乗算した結果を返し、失敗すると
NULLを返します。Python の式o1 * o2と同じです。
-
PyObject*
PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 を行列乗算した結果を返し、失敗すると
NULLを返します。 Python の式o1 @ o2と同じです。バージョン 3.5 で追加.
-
PyObject*
PyNumber_FloorDivide(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
Return the floor of o1 divided by o2, or
NULLon failure. This is the equivalent of the Python expressiono1 // o2.
-
PyObject*
PyNumber_TrueDivide(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
Return a reasonable approximation for the mathematical value of o1 divided by o2, or
NULLon 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 expressiono1 / o2.
-
PyObject*
PyNumber_Remainder(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 で除算した剰余を返し、失敗すると
NULLを返します。Python の式o1 % o2と同じです。
-
PyObject*
PyNumber_Divmod(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
組み込み関数
divmod()を参照してください。失敗するとNULLを返します。 Python の式divmod(o1, o2)と同じです。
-
PyObject*
PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3)¶ - Return value: New reference.
組み込み関数
pow()を参照してください。失敗するとNULLを返します。 Python の式pow(o1, o2, o3)と同じです。 o3 はオプションです。 o3 を無視させたいなら、Py_Noneを入れてください (o3 にNULLを渡すと、不正なメモリアクセスを引き起こすことがあります)。
-
PyObject*
PyNumber_Negative(PyObject *o)¶ - Return value: New reference.
成功すると o の符号反転を返し、失敗すると
NULLを返します。Python の式-oと同じです。
-
PyObject*
PyNumber_Positive(PyObject *o)¶ - Return value: New reference.
成功すると o を返し、失敗すると
NULLを返します。Python の式+oと同じです。
-
PyObject*
PyNumber_Absolute(PyObject *o)¶ - Return value: New reference.
成功すると o の絶対値を返し、失敗すると
NULLを返します。Python の式abs(o)と同じです。
-
PyObject*
PyNumber_Invert(PyObject *o)¶ - Return value: New reference.
成功すると o のビット単位反転 (bitwise negation) を返し、失敗すると
NULLを返します。Python の式~oと同じです。
-
PyObject*
PyNumber_Lshift(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 だけ左シフトした結果を返し、失敗すると
NULLを返します。Python の式o1 << o2と同じです。
-
PyObject*
PyNumber_Rshift(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 だけ右シフトした結果を返し、失敗すると
NULLを返します。Python の式o1 >> o2と同じです。
-
PyObject*
PyNumber_And(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 の "ビット単位論理積 (bitwise and)" を返し、失敗すると
NULLを返します。Python の式o1 & o2と同じです。
-
PyObject*
PyNumber_Xor(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 の "ビット単位排他的論理和 (bitwise exclusive or)" を返し、失敗すると
NULLを返します。Python の式o1 ^ o2と同じです。
-
PyObject*
PyNumber_Or(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 の "ビット単位論理和 (bitwise or)" を返し失敗すると
NULLを返します。Python の式o1 | o2と同じです。
-
PyObject*
PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 を加算した結果を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 += o2と同じです。
-
PyObject*
PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 から o2 を減算した結果を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 -= o2と同じです。
-
PyObject*
PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 を乗算した結果を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 *= o2と同じです。
-
PyObject*
PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 を行列乗算した結果を返し、失敗すると
NULLを返します。 o1 が in-place 演算をサポートする場合、 in-place 演算を行います。 Python の文o1 @= o2と同じです。バージョン 3.5 で追加.
-
PyObject*
PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 で除算した切捨て値を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 //= o2と同じです。
-
PyObject*
PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
Return a reasonable approximation for the mathematical value of o1 divided by o2, or
NULLon 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 statemento1 /= o2.
-
PyObject*
PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 で除算した剰余を返し、, 失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 %= o2と同じです。
-
PyObject*
PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3)¶ - Return value: New reference.
組み込み関数
pow()を参照してください。失敗するとNULLを返します。 o1 が in-place 演算をサポートする場合、in-place 演算を行います。この関数は o3 がPy_Noneの場合は Python 文o1 **= o2と同じで、それ以外の場合はpow(o1, o2, o3)の in-place 版です。 o3 を無視させたいなら、Py_Noneを入れてください (o3 にNULLを渡すと、不正なメモリアクセスを引き起こすことがあります)。
-
PyObject*
PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 だけ左シフトした結果を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 <<= o2と同じです。
-
PyObject*
PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 を o2 だけ右シフトした結果を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 >>= o2と同じです。
-
PyObject*
PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 の "ビット単位論理積 (bitwise and)" を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 &= o2と同じです。
-
PyObject*
PyNumber_InPlaceXor(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 の "ビット単位排他的論理和 (bitwise exclusive or)" を返し、失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 ^= o2と同じです。
-
PyObject*
PyNumber_InPlaceOr(PyObject *o1, PyObject *o2)¶ - Return value: New reference.
成功すると o1 と o2 の "ビット単位論理和 (bitwise or)" を返し失敗すると
NULLを返します。o1 が in-place 演算をサポートする場合、in-place 演算を行います。Python の文o1 |= o2と同じです。
-
PyObject*
PyNumber_Long(PyObject *o)¶ - Return value: New reference.
成功すると o を整数に変換したものを返し、失敗すると
NULLを返します。Python の式int(o)と同じです。
-
PyObject*
PyNumber_Float(PyObject *o)¶ - Return value: New reference.
成功すると o を浮動小数点数に変換したものを返し、失敗すると
NULLを返します。Python の式float(o)と同じです。
-
PyObject*
PyNumber_Index(PyObject *o)¶ - Return value: New reference.
o をPythonのint型に変換し、成功したらその値を返します。失敗したら
NULLが返され、TypeError例外が送出されます。
-
PyObject*
PyNumber_ToBase(PyObject *n, int base)¶ - Return value: New reference.
base 進数に変換された整数 n を文字列として返します。 base 引数は2, 8, 10または16のいずれかでなければなりません。 基数2、8、16について、返される文字列の先頭には基数マーカー
'0b'、'0o'または'0x'が、それぞれ付与されます。 もし n が Python のint型でなければ、まずPyNumber_Index()で変換されます。
-
Py_ssize_t
PyNumber_AsSsize_t(PyObject *o, PyObject *exc)¶ Returns o converted to a
Py_ssize_tvalue if o can be interpreted as an integer. If the call fails, an exception is raised and-1is returned.If o can be converted to a Python int but the attempt to convert to a
Py_ssize_tvalue would raise anOverflowError, then the exc argument is the type of exception that will be raised (usuallyIndexErrororOverflowError). If exc isNULL, then the exception is cleared and the value is clipped toPY_SSIZE_T_MINfor a negative integer orPY_SSIZE_T_MAXfor a positive integer.