OLD | NEW |
(Empty) | |
| 1 from cpython.ref cimport PyObject |
| 2 |
| 3 cdef extern from "Python.h": |
| 4 |
| 5 ##################################################################### |
| 6 # 6.2 Number Protocol |
| 7 ##################################################################### |
| 8 |
| 9 bint PyNumber_Check(object o) |
| 10 # Returns 1 if the object o provides numeric protocols, and false |
| 11 # otherwise. This function always succeeds. |
| 12 |
| 13 object PyNumber_Add(object o1, object o2) |
| 14 # Return value: New reference. |
| 15 # Returns the result of adding o1 and o2, or NULL on failure. This |
| 16 # is the equivalent of the Python expression "o1 + o2". |
| 17 |
| 18 object PyNumber_Subtract(object o1, object o2) |
| 19 # Return value: New reference. |
| 20 # Returns the result of subtracting o2 from o1, or NULL on |
| 21 # failure. This is the equivalent of the Python expression "o1 - |
| 22 # o2". |
| 23 |
| 24 object PyNumber_Multiply(object o1, object o2) |
| 25 # Return value: New reference. |
| 26 # Returns the result of multiplying o1 and o2, or NULL on |
| 27 # failure. This is the equivalent of the Python expression "o1 * |
| 28 # o2". |
| 29 |
| 30 object PyNumber_Divide(object o1, object o2) |
| 31 # Return value: New reference. |
| 32 # Returns the result of dividing o1 by o2, or NULL on |
| 33 # failure. This is the equivalent of the Python expression "o1 / |
| 34 # o2". |
| 35 |
| 36 object PyNumber_FloorDivide(object o1, object o2) |
| 37 # Return value: New reference. |
| 38 # Return the floor of o1 divided by o2, or NULL on failure. This |
| 39 # is equivalent to the ``classic'' division of integers. |
| 40 |
| 41 object PyNumber_TrueDivide(object o1, object o2) |
| 42 # Return value: New reference. |
| 43 # Return a reasonable approximation for the mathematical value of |
| 44 # o1 divided by o2, or NULL on failure. The return value is |
| 45 # ``approximate'' because binary floating point numbers are |
| 46 # approximate; it is not possible to represent all real numbers in |
| 47 # base two. This function can return a floating point value when |
| 48 # passed two integers. |
| 49 |
| 50 object PyNumber_Remainder(object o1, object o2) |
| 51 # Return value: New reference. |
| 52 # Returns the remainder of dividing o1 by o2, or NULL on |
| 53 # failure. This is the equivalent of the Python expression "o1 % |
| 54 # o2". |
| 55 |
| 56 object PyNumber_Divmod(object o1, object o2) |
| 57 # Return value: New reference. |
| 58 # See the built-in function divmod(). Returns NULL on |
| 59 # failure. This is the equivalent of the Python expression |
| 60 # "divmod(o1, o2)". |
| 61 |
| 62 object PyNumber_Power(object o1, object o2, object o3) |
| 63 # Return value: New reference. |
| 64 # See the built-in function pow(). Returns NULL on failure. This |
| 65 # is the equivalent of the Python expression "pow(o1, o2, o3)", |
| 66 # where o3 is optional. If o3 is to be ignored, pass Py_None in |
| 67 # its place (passing NULL for o3 would cause an illegal memory |
| 68 # access). |
| 69 |
| 70 object PyNumber_Negative(object o) |
| 71 # Return value: New reference. |
| 72 # Returns the negation of o on success, or NULL on failure. This |
| 73 # is the equivalent of the Python expression "-o". |
| 74 |
| 75 object PyNumber_Positive(object o) |
| 76 # Return value: New reference. |
| 77 # Returns o on success, or NULL on failure. This is the equivalent |
| 78 # of the Python expression "+o". |
| 79 |
| 80 object PyNumber_Absolute(object o) |
| 81 # Return value: New reference. |
| 82 # Returns the absolute value of o, or NULL on failure. This is the |
| 83 # equivalent of the Python expression "abs(o)". |
| 84 |
| 85 object PyNumber_Invert(object o) |
| 86 # Return value: New reference. |
| 87 # Returns the bitwise negation of o on success, or NULL on |
| 88 # failure. This is the equivalent of the Python expression "~o". |
| 89 |
| 90 object PyNumber_Lshift(object o1, object o2) |
| 91 # Return value: New reference. |
| 92 # Returns the result of left shifting o1 by o2 on success, or NULL |
| 93 # on failure. This is the equivalent of the Python expression "o1 |
| 94 # << o2". |
| 95 |
| 96 object PyNumber_Rshift(object o1, object o2) |
| 97 # Return value: New reference. |
| 98 # Returns the result of right shifting o1 by o2 on success, or |
| 99 # NULL on failure. This is the equivalent of the Python expression |
| 100 # "o1 >> o2". |
| 101 |
| 102 object PyNumber_And(object o1, object o2) |
| 103 # Return value: New reference. |
| 104 # Returns the ``bitwise and'' of o1 and o2 on success and NULL on |
| 105 # failure. This is the equivalent of the Python expression "o1 & |
| 106 # o2". |
| 107 |
| 108 object PyNumber_Xor(object o1, object o2) |
| 109 # Return value: New reference. |
| 110 # Returns the ``bitwise exclusive or'' of o1 by o2 on success, or |
| 111 # NULL on failure. This is the equivalent of the Python expression |
| 112 # "o1 ^ o2". |
| 113 |
| 114 object PyNumber_Or(object o1, object o2) |
| 115 # Return value: New reference. |
| 116 # Returns the ``bitwise or'' of o1 and o2 on success, or NULL on failure. Th
is is the equivalent of the Python expression "o1 | o2". |
| 117 |
| 118 object PyNumber_InPlaceAdd(object o1, object o2) |
| 119 # Return value: New reference. |
| 120 # Returns the result of adding o1 and o2, or NULL on failure. The |
| 121 # operation is done in-place when o1 supports it. This is the |
| 122 # equivalent of the Python statement "o1 += o2". |
| 123 |
| 124 object PyNumber_InPlaceSubtract(object o1, object o2) |
| 125 # Return value: New reference. |
| 126 # Returns the result of subtracting o2 from o1, or NULL on |
| 127 # failure. The operation is done in-place when o1 supports |
| 128 # it. This is the equivalent of the Python statement "o1 -= o2". |
| 129 |
| 130 object PyNumber_InPlaceMultiply(object o1, object o2) |
| 131 # Return value: New reference. |
| 132 # Returns the result of multiplying o1 and o2, or NULL on |
| 133 # failure. The operation is done in-place when o1 supports |
| 134 # it. This is the equivalent of the Python statement "o1 *= o2". |
| 135 |
| 136 object PyNumber_InPlaceDivide(object o1, object o2) |
| 137 # Return value: New reference. |
| 138 # Returns the result of dividing o1 by o2, or NULL on failure. The |
| 139 # operation is done in-place when o1 supports it. This is the |
| 140 # equivalent of the Python statement "o1 /= o2". |
| 141 |
| 142 object PyNumber_InPlaceFloorDivide(object o1, object o2) |
| 143 # Return value: New reference. |
| 144 # Returns the mathematical floor of dividing o1 by o2, or NULL on |
| 145 # failure. The operation is done in-place when o1 supports |
| 146 # it. This is the equivalent of the Python statement "o1 //= |
| 147 # o2". |
| 148 |
| 149 object PyNumber_InPlaceTrueDivide(object o1, object o2) |
| 150 # Return value: New reference. |
| 151 # Return a reasonable approximation for the mathematical value of |
| 152 # o1 divided by o2, or NULL on failure. The return value is |
| 153 # ``approximate'' because binary floating point numbers are |
| 154 # approximate; it is not possible to represent all real numbers in |
| 155 # base two. This function can return a floating point value when |
| 156 # passed two integers. The operation is done in-place when o1 |
| 157 # supports it. |
| 158 |
| 159 object PyNumber_InPlaceRemainder(object o1, object o2) |
| 160 # Return value: New reference. |
| 161 # Returns the remainder of dividing o1 by o2, or NULL on |
| 162 # failure. The operation is done in-place when o1 supports |
| 163 # it. This is the equivalent of the Python statement "o1 %= o2". |
| 164 |
| 165 object PyNumber_InPlacePower(object o1, object o2, object o3) |
| 166 # Return value: New reference. |
| 167 # See the built-in function pow(). Returns NULL on failure. The |
| 168 # operation is done in-place when o1 supports it. This is the |
| 169 # equivalent of the Python statement "o1 **= o2" when o3 is |
| 170 # Py_None, or an in-place variant of "pow(o1, o2, o3)" |
| 171 # otherwise. If o3 is to be ignored, pass Py_None in its place |
| 172 # (passing NULL for o3 would cause an illegal memory access). |
| 173 |
| 174 object PyNumber_InPlaceLshift(object o1, object o2) |
| 175 # Return value: New reference. |
| 176 # Returns the result of left shifting o1 by o2 on success, or NULL |
| 177 # on failure. The operation is done in-place when o1 supports |
| 178 # it. This is the equivalent of the Python statement "o1 <<= o2". |
| 179 |
| 180 object PyNumber_InPlaceRshift(object o1, object o2) |
| 181 # Return value: New reference. |
| 182 # Returns the result of right shifting o1 by o2 on success, or |
| 183 # NULL on failure. The operation is done in-place when o1 supports |
| 184 # it. This is the equivalent of the Python statement "o1 >>= o2". |
| 185 |
| 186 object PyNumber_InPlaceAnd(object o1, object o2) |
| 187 # Return value: New reference. |
| 188 # Returns the ``bitwise and'' of o1 and o2 on success and NULL on |
| 189 # failure. The operation is done in-place when o1 supports |
| 190 # it. This is the equivalent of the Python statement "o1 &= o2". |
| 191 |
| 192 object PyNumber_InPlaceXor(object o1, object o2) |
| 193 # Return value: New reference. |
| 194 # Returns the ``bitwise exclusive or'' of o1 by o2 on success, or |
| 195 # NULL on failure. The operation is done in-place when o1 supports |
| 196 # it. This is the equivalent of the Python statement "o1 ^= o2". |
| 197 |
| 198 object PyNumber_InPlaceOr(object o1, object o2) |
| 199 # Return value: New reference. |
| 200 # Returns the ``bitwise or'' of o1 and o2 on success, or NULL on |
| 201 # failure. The operation is done in-place when o1 supports |
| 202 # it. This is the equivalent of the Python statement "o1 |= o2". |
| 203 |
| 204 int PyNumber_Coerce(PyObject **p1, PyObject **p2) except -1 |
| 205 # This function takes the addresses of two variables of type |
| 206 # PyObject*. If the objects pointed to by *p1 and *p2 have the |
| 207 # same type, increment their reference count and return 0 |
| 208 # (success). If the objects can be converted to a common numeric |
| 209 # type, replace *p1 and *p2 by their converted value (with 'new' |
| 210 # reference counts), and return 0. If no conversion is possible, |
| 211 # or if some other error occurs, return -1 (failure) and don't |
| 212 # increment the reference counts. The call PyNumber_Coerce(&o1, |
| 213 # &o2) is equivalent to the Python statement "o1, o2 = coerce(o1, |
| 214 # o2)". |
| 215 |
| 216 object PyNumber_Int(object o) |
| 217 # Return value: New reference. |
| 218 # Returns the o converted to an integer object on success, or NULL |
| 219 # on failure. If the argument is outside the integer range a long |
| 220 # object will be returned instead. This is the equivalent of the |
| 221 # Python expression "int(o)". |
| 222 |
| 223 object PyNumber_Long(object o) |
| 224 # Return value: New reference. |
| 225 # Returns the o converted to a long integer object on success, or |
| 226 # NULL on failure. This is the equivalent of the Python expression |
| 227 # "long(o)". |
| 228 |
| 229 object PyNumber_Float(object o) |
| 230 # Return value: New reference. |
| 231 # Returns the o converted to a float object on success, or NULL on |
| 232 # failure. This is the equivalent of the Python expression |
| 233 # "float(o)". |
| 234 |
| 235 object PyNumber_Index(object o) |
| 236 # Returns the o converted to a Python int or long on success or |
| 237 # NULL with a TypeError exception raised on failure. |
| 238 |
| 239 Py_ssize_t PyNumber_AsSsize_t(object o, object exc) except? -1 |
| 240 # Returns o converted to a Py_ssize_t value if o can be |
| 241 # interpreted as an integer. If o can be converted to a Python int |
| 242 # or long but the attempt to convert to a Py_ssize_t value would |
| 243 # raise an OverflowError, then the exc argument is the type of |
| 244 # exception that will be raised (usually IndexError or |
| 245 # OverflowError). If exc is NULL, then the exception is cleared |
| 246 # and the value is clipped to PY_SSIZE_T_MIN for a negative |
| 247 # integer or PY_SSIZE_T_MAX for a positive integer. |
| 248 |
| 249 bint PyIndex_Check "__Pyx_PyIndex_Check" (object) |
| 250 # Returns True if o is an index integer (has the nb_index slot of |
| 251 # the tp_as_number structure filled in). |
OLD | NEW |