number.pxd 11 KB

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