Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="api.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="api.html" title='Python/C API Reference Manual' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="sequence.html" /> | |
13 | <link rel="prev" href="object.html" /> | |
14 | <link rel="parent" href="abstract.html" /> | |
15 | <link rel="next" href="sequence.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.2 Number Protocol </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.1 Object Protocol" | |
25 | href="object.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Abstract Objects Layer" | |
28 | href="abstract.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.3 Sequence Protocol" | |
31 | href="sequence.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python/C API Reference Manual</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><img src='../icons/blank.png' | |
38 | border='0' height='32' alt='' width='32' /></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="object.html">6.1 Object Protocol</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="abstract.html">6. Abstract Objects Layer</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="sequence.html">6.3 Sequence Protocol</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION008200000000000000000"></A><A NAME="number"></A> | |
56 | <BR> | |
57 | 6.2 Number Protocol | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-264' xml:id='l2h-264' class="cfunction">PyNumber_Check</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
62 | <dd> | |
63 | Returns <code>1</code> if the object <var>o</var> provides numeric protocols, | |
64 | and false otherwise. This function always succeeds. | |
65 | </dd></dl> | |
66 | ||
67 | <P> | |
68 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-265' xml:id='l2h-265' class="cfunction">PyNumber_Add</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
69 | <dd> | |
70 | <div class="refcount-info"> | |
71 | <span class="label">Return value:</span> | |
72 | <span class="value">New reference.</span> | |
73 | </div> | |
74 | Returns the result of adding <var>o1</var> and <var>o2</var>, or <tt class="constant">NULL</tt> on | |
75 | failure. This is the equivalent of the Python expression | |
76 | "<tt class="samp"><var>o1</var> + <var>o2</var></tt>". | |
77 | </dd></dl> | |
78 | ||
79 | <P> | |
80 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-266' xml:id='l2h-266' class="cfunction">PyNumber_Subtract</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | <div class="refcount-info"> | |
83 | <span class="label">Return value:</span> | |
84 | <span class="value">New reference.</span> | |
85 | </div> | |
86 | Returns the result of subtracting <var>o2</var> from <var>o1</var>, or <tt class="constant">NULL</tt> | |
87 | on failure. This is the equivalent of the Python expression | |
88 | "<tt class="samp"><var>o1</var> - <var>o2</var></tt>". | |
89 | </dd></dl> | |
90 | ||
91 | <P> | |
92 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-267' xml:id='l2h-267' class="cfunction">PyNumber_Multiply</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
93 | <dd> | |
94 | <div class="refcount-info"> | |
95 | <span class="label">Return value:</span> | |
96 | <span class="value">New reference.</span> | |
97 | </div> | |
98 | Returns the result of multiplying <var>o1</var> and <var>o2</var>, or <tt class="constant">NULL</tt> | |
99 | on failure. This is the equivalent of the Python expression | |
100 | "<tt class="samp"><var>o1</var> * <var>o2</var></tt>". | |
101 | </dd></dl> | |
102 | ||
103 | <P> | |
104 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-268' xml:id='l2h-268' class="cfunction">PyNumber_Divide</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
105 | <dd> | |
106 | <div class="refcount-info"> | |
107 | <span class="label">Return value:</span> | |
108 | <span class="value">New reference.</span> | |
109 | </div> | |
110 | Returns the result of dividing <var>o1</var> by <var>o2</var>, or <tt class="constant">NULL</tt> on | |
111 | failure. This is the equivalent of the Python expression | |
112 | "<tt class="samp"><var>o1</var> / <var>o2</var></tt>". | |
113 | </dd></dl> | |
114 | ||
115 | <P> | |
116 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-269' xml:id='l2h-269' class="cfunction">PyNumber_FloorDivide</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
117 | <dd> | |
118 | <div class="refcount-info"> | |
119 | <span class="label">Return value:</span> | |
120 | <span class="value">New reference.</span> | |
121 | </div> | |
122 | Return the floor of <var>o1</var> divided by <var>o2</var>, or <tt class="constant">NULL</tt> on | |
123 | failure. This is equivalent to the ``classic'' division of | |
124 | integers. | |
125 | ||
126 | <span class="versionnote">New in version 2.2.</span> | |
127 | ||
128 | </dd></dl> | |
129 | ||
130 | <P> | |
131 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-270' xml:id='l2h-270' class="cfunction">PyNumber_TrueDivide</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
132 | <dd> | |
133 | <div class="refcount-info"> | |
134 | <span class="label">Return value:</span> | |
135 | <span class="value">New reference.</span> | |
136 | </div> | |
137 | Return a reasonable approximation for the mathematical value of | |
138 | <var>o1</var> divided by <var>o2</var>, or <tt class="constant">NULL</tt> on failure. The return | |
139 | value is ``approximate'' because binary floating point numbers are | |
140 | approximate; it is not possible to represent all real numbers in | |
141 | base two. This function can return a floating point value when | |
142 | passed two integers. | |
143 | ||
144 | <span class="versionnote">New in version 2.2.</span> | |
145 | ||
146 | </dd></dl> | |
147 | ||
148 | <P> | |
149 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-271' xml:id='l2h-271' class="cfunction">PyNumber_Remainder</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
150 | <dd> | |
151 | <div class="refcount-info"> | |
152 | <span class="label">Return value:</span> | |
153 | <span class="value">New reference.</span> | |
154 | </div> | |
155 | Returns the remainder of dividing <var>o1</var> by <var>o2</var>, or <tt class="constant">NULL</tt> | |
156 | on failure. This is the equivalent of the Python expression | |
157 | "<tt class="samp"><var>o1</var> % <var>o2</var></tt>". | |
158 | </dd></dl> | |
159 | ||
160 | <P> | |
161 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-272' xml:id='l2h-272' class="cfunction">PyNumber_Divmod</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
162 | <dd> | |
163 | <div class="refcount-info"> | |
164 | <span class="label">Return value:</span> | |
165 | <span class="value">New reference.</span> | |
166 | </div> | |
167 | See the built-in function <tt class="function">divmod()</tt><a id='l2h-273' xml:id='l2h-273'></a>. | |
168 | Returns <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python | |
169 | expression "<tt class="samp">divmod(<var>o1</var>, <var>o2</var>)</tt>". | |
170 | </dd></dl> | |
171 | ||
172 | <P> | |
173 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-274' xml:id='l2h-274' class="cfunction">PyNumber_Power</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
174 | PyObject *<var>o2</var>, PyObject *<var>o3</var>)</td></tr></table></dt> | |
175 | <dd> | |
176 | <div class="refcount-info"> | |
177 | <span class="label">Return value:</span> | |
178 | <span class="value">New reference.</span> | |
179 | </div> | |
180 | See the built-in function <tt class="function">pow()</tt><a id='l2h-275' xml:id='l2h-275'></a>. | |
181 | Returns <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python | |
182 | expression "<tt class="samp">pow(<var>o1</var>, <var>o2</var>, <var>o3</var>)</tt>", where <var>o3</var> | |
183 | is optional. If <var>o3</var> is to be ignored, pass <tt class="cdata">Py_None</tt> in | |
184 | its place (passing <tt class="constant">NULL</tt> for <var>o3</var> would cause an illegal | |
185 | memory access). | |
186 | </dd></dl> | |
187 | ||
188 | <P> | |
189 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-276' xml:id='l2h-276' class="cfunction">PyNumber_Negative</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
190 | <dd> | |
191 | <div class="refcount-info"> | |
192 | <span class="label">Return value:</span> | |
193 | <span class="value">New reference.</span> | |
194 | </div> | |
195 | Returns the negation of <var>o</var> on success, or <tt class="constant">NULL</tt> on failure. | |
196 | This is the equivalent of the Python expression "<tt class="samp">-<var>o</var></tt>". | |
197 | </dd></dl> | |
198 | ||
199 | <P> | |
200 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-277' xml:id='l2h-277' class="cfunction">PyNumber_Positive</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
201 | <dd> | |
202 | <div class="refcount-info"> | |
203 | <span class="label">Return value:</span> | |
204 | <span class="value">New reference.</span> | |
205 | </div> | |
206 | Returns <var>o</var> on success, or <tt class="constant">NULL</tt> on failure. This is the | |
207 | equivalent of the Python expression "<tt class="samp">+<var>o</var></tt>". | |
208 | </dd></dl> | |
209 | ||
210 | <P> | |
211 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-278' xml:id='l2h-278' class="cfunction">PyNumber_Absolute</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
212 | <dd> | |
213 | <div class="refcount-info"> | |
214 | <span class="label">Return value:</span> | |
215 | <span class="value">New reference.</span> | |
216 | </div> | |
217 | Returns the absolute value of <var>o</var>, or <tt class="constant">NULL</tt> on failure. This | |
218 | is the equivalent of the Python expression "<tt class="samp">abs(<var>o</var>)</tt>". | |
219 | <a id='l2h-279' xml:id='l2h-279'></a></dd></dl> | |
220 | ||
221 | <P> | |
222 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-280' xml:id='l2h-280' class="cfunction">PyNumber_Invert</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
223 | <dd> | |
224 | <div class="refcount-info"> | |
225 | <span class="label">Return value:</span> | |
226 | <span class="value">New reference.</span> | |
227 | </div> | |
228 | Returns the bitwise negation of <var>o</var> on success, or <tt class="constant">NULL</tt> on | |
229 | failure. This is the equivalent of the Python expression | |
230 | "<tt class="samp">~<var>o</var></tt>". | |
231 | </dd></dl> | |
232 | ||
233 | <P> | |
234 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-281' xml:id='l2h-281' class="cfunction">PyNumber_Lshift</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
235 | <dd> | |
236 | <div class="refcount-info"> | |
237 | <span class="label">Return value:</span> | |
238 | <span class="value">New reference.</span> | |
239 | </div> | |
240 | Returns the result of left shifting <var>o1</var> by <var>o2</var> on success, | |
241 | or <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python | |
242 | expression "<tt class="samp"><var>o1</var> <<code><</code> <var>o2</var></tt>". | |
243 | </dd></dl> | |
244 | ||
245 | <P> | |
246 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-282' xml:id='l2h-282' class="cfunction">PyNumber_Rshift</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
247 | <dd> | |
248 | <div class="refcount-info"> | |
249 | <span class="label">Return value:</span> | |
250 | <span class="value">New reference.</span> | |
251 | </div> | |
252 | Returns the result of right shifting <var>o1</var> by <var>o2</var> on | |
253 | success, or <tt class="constant">NULL</tt> on failure. This is the equivalent of the | |
254 | Python expression "<tt class="samp"><var>o1</var> ><code>></code> <var>o2</var></tt>". | |
255 | </dd></dl> | |
256 | ||
257 | <P> | |
258 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-283' xml:id='l2h-283' class="cfunction">PyNumber_And</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
259 | <dd> | |
260 | <div class="refcount-info"> | |
261 | <span class="label">Return value:</span> | |
262 | <span class="value">New reference.</span> | |
263 | </div> | |
264 | Returns the ``bitwise and'' of <var>o1</var> and <var>o2</var> on success and | |
265 | <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python expression | |
266 | "<tt class="samp"><var>o1</var> & <var>o2</var></tt>". | |
267 | </dd></dl> | |
268 | ||
269 | <P> | |
270 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-284' xml:id='l2h-284' class="cfunction">PyNumber_Xor</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
271 | <dd> | |
272 | <div class="refcount-info"> | |
273 | <span class="label">Return value:</span> | |
274 | <span class="value">New reference.</span> | |
275 | </div> | |
276 | Returns the ``bitwise exclusive or'' of <var>o1</var> by <var>o2</var> on | |
277 | success, or <tt class="constant">NULL</tt> on failure. This is the equivalent of the | |
278 | Python expression "<tt class="samp"><var>o1</var> ^ <var>o2</var></tt>". | |
279 | </dd></dl> | |
280 | ||
281 | <P> | |
282 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-285' xml:id='l2h-285' class="cfunction">PyNumber_Or</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
283 | <dd> | |
284 | <div class="refcount-info"> | |
285 | <span class="label">Return value:</span> | |
286 | <span class="value">New reference.</span> | |
287 | </div> | |
288 | Returns the ``bitwise or'' of <var>o1</var> and <var>o2</var> on success, or | |
289 | <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python expression | |
290 | "<tt class="samp"><var>o1</var> | <var>o2</var></tt>". | |
291 | </dd></dl> | |
292 | ||
293 | <P> | |
294 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-286' xml:id='l2h-286' class="cfunction">PyNumber_InPlaceAdd</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
295 | <dd> | |
296 | <div class="refcount-info"> | |
297 | <span class="label">Return value:</span> | |
298 | <span class="value">New reference.</span> | |
299 | </div> | |
300 | Returns the result of adding <var>o1</var> and <var>o2</var>, or <tt class="constant">NULL</tt> on | |
301 | failure. The operation is done <em>in-place</em> when <var>o1</var> | |
302 | supports it. This is the equivalent of the Python statement | |
303 | "<tt class="samp"><var>o1</var> += <var>o2</var></tt>". | |
304 | </dd></dl> | |
305 | ||
306 | <P> | |
307 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-287' xml:id='l2h-287' class="cfunction">PyNumber_InPlaceSubtract</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
308 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
309 | <dd> | |
310 | <div class="refcount-info"> | |
311 | <span class="label">Return value:</span> | |
312 | <span class="value">New reference.</span> | |
313 | </div> | |
314 | Returns the result of subtracting <var>o2</var> from <var>o1</var>, or <tt class="constant">NULL</tt> | |
315 | on failure. The operation is done <em>in-place</em> when <var>o1</var> | |
316 | supports it. This is the equivalent of the Python statement | |
317 | "<tt class="samp"><var>o1</var> -= <var>o2</var></tt>". | |
318 | </dd></dl> | |
319 | ||
320 | <P> | |
321 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-288' xml:id='l2h-288' class="cfunction">PyNumber_InPlaceMultiply</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
322 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
323 | <dd> | |
324 | <div class="refcount-info"> | |
325 | <span class="label">Return value:</span> | |
326 | <span class="value">New reference.</span> | |
327 | </div> | |
328 | Returns the result of multiplying <var>o1</var> and <var>o2</var>, or <tt class="constant">NULL</tt> | |
329 | on failure. The operation is done <em>in-place</em> when <var>o1</var> | |
330 | supports it. This is the equivalent of the Python statement | |
331 | "<tt class="samp"><var>o1</var> *= <var>o2</var></tt>". | |
332 | </dd></dl> | |
333 | ||
334 | <P> | |
335 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-289' xml:id='l2h-289' class="cfunction">PyNumber_InPlaceDivide</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
336 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
337 | <dd> | |
338 | <div class="refcount-info"> | |
339 | <span class="label">Return value:</span> | |
340 | <span class="value">New reference.</span> | |
341 | </div> | |
342 | Returns the result of dividing <var>o1</var> by <var>o2</var>, or <tt class="constant">NULL</tt> on | |
343 | failure. The operation is done <em>in-place</em> when <var>o1</var> | |
344 | supports it. This is the equivalent of the Python statement | |
345 | "<tt class="samp"><var>o1</var> /= <var>o2</var></tt>". | |
346 | </dd></dl> | |
347 | ||
348 | <P> | |
349 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-290' xml:id='l2h-290' class="cfunction">PyNumber_InPlaceFloorDivide</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
350 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
351 | <dd> | |
352 | <div class="refcount-info"> | |
353 | <span class="label">Return value:</span> | |
354 | <span class="value">New reference.</span> | |
355 | </div> | |
356 | Returns the mathematical floor of dividing <var>o1</var> by <var>o2</var>, or | |
357 | <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em> when | |
358 | <var>o1</var> supports it. This is the equivalent of the Python | |
359 | statement "<tt class="samp"><var>o1</var> //= <var>o2</var></tt>". | |
360 | ||
361 | <span class="versionnote">New in version 2.2.</span> | |
362 | ||
363 | </dd></dl> | |
364 | ||
365 | <P> | |
366 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-291' xml:id='l2h-291' class="cfunction">PyNumber_InPlaceTrueDivide</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
367 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
368 | <dd> | |
369 | <div class="refcount-info"> | |
370 | <span class="label">Return value:</span> | |
371 | <span class="value">New reference.</span> | |
372 | </div> | |
373 | Return a reasonable approximation for the mathematical value of | |
374 | <var>o1</var> divided by <var>o2</var>, or <tt class="constant">NULL</tt> on failure. The return | |
375 | value is ``approximate'' because binary floating point numbers are | |
376 | approximate; it is not possible to represent all real numbers in | |
377 | base two. This function can return a floating point value when | |
378 | passed two integers. The operation is done <em>in-place</em> when | |
379 | <var>o1</var> supports it. | |
380 | ||
381 | <span class="versionnote">New in version 2.2.</span> | |
382 | ||
383 | </dd></dl> | |
384 | ||
385 | <P> | |
386 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-292' xml:id='l2h-292' class="cfunction">PyNumber_InPlaceRemainder</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
387 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
388 | <dd> | |
389 | <div class="refcount-info"> | |
390 | <span class="label">Return value:</span> | |
391 | <span class="value">New reference.</span> | |
392 | </div> | |
393 | Returns the remainder of dividing <var>o1</var> by <var>o2</var>, or <tt class="constant">NULL</tt> | |
394 | on failure. The operation is done <em>in-place</em> when <var>o1</var> | |
395 | supports it. This is the equivalent of the Python statement | |
396 | "<tt class="samp"><var>o1</var> %= <var>o2</var></tt>". | |
397 | </dd></dl> | |
398 | ||
399 | <P> | |
400 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-293' xml:id='l2h-293' class="cfunction">PyNumber_InPlacePower</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
401 | PyObject *<var>o2</var>, PyObject *<var>o3</var>)</td></tr></table></dt> | |
402 | <dd> | |
403 | <div class="refcount-info"> | |
404 | <span class="label">Return value:</span> | |
405 | <span class="value">New reference.</span> | |
406 | </div> | |
407 | See the built-in function <tt class="function">pow()</tt>.<a id='l2h-294' xml:id='l2h-294'></a> Returns <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em> | |
408 | when <var>o1</var> supports it. This is the equivalent of the Python | |
409 | statement "<tt class="samp"><var>o1</var> **= <var>o2</var></tt>" when o3 is <tt class="cdata">Py_None</tt>, | |
410 | or an in-place variant of "<tt class="samp">pow(<var>o1</var>, <var>o2</var>, <var>o3</var>)</tt>" otherwise. If <var>o3</var> is to be ignored, pass <tt class="cdata">Py_None</tt> in its | |
411 | place (passing <tt class="constant">NULL</tt> for <var>o3</var> would cause an illegal memory | |
412 | access). | |
413 | </dd></dl> | |
414 | ||
415 | <P> | |
416 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-295' xml:id='l2h-295' class="cfunction">PyNumber_InPlaceLshift</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
417 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
418 | <dd> | |
419 | <div class="refcount-info"> | |
420 | <span class="label">Return value:</span> | |
421 | <span class="value">New reference.</span> | |
422 | </div> | |
423 | Returns the result of left shifting <var>o1</var> by <var>o2</var> on success, | |
424 | or <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em> when | |
425 | <var>o1</var> supports it. This is the equivalent of the Python | |
426 | statement "<tt class="samp"><var>o1</var> <<code><=</code> <var>o2</var></tt>". | |
427 | </dd></dl> | |
428 | ||
429 | <P> | |
430 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-296' xml:id='l2h-296' class="cfunction">PyNumber_InPlaceRshift</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, | |
431 | PyObject *<var>o2</var>)</td></tr></table></dt> | |
432 | <dd> | |
433 | <div class="refcount-info"> | |
434 | <span class="label">Return value:</span> | |
435 | <span class="value">New reference.</span> | |
436 | </div> | |
437 | Returns the result of right shifting <var>o1</var> by <var>o2</var> on | |
438 | success, or <tt class="constant">NULL</tt> on failure. The operation is done | |
439 | <em>in-place</em> when <var>o1</var> supports it. This is the equivalent | |
440 | of the Python statement "<tt class="samp"><var>o1</var> ><code>>=</code> <var>o2</var></tt>". | |
441 | </dd></dl> | |
442 | ||
443 | <P> | |
444 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-297' xml:id='l2h-297' class="cfunction">PyNumber_InPlaceAnd</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
445 | <dd> | |
446 | <div class="refcount-info"> | |
447 | <span class="label">Return value:</span> | |
448 | <span class="value">New reference.</span> | |
449 | </div> | |
450 | Returns the ``bitwise and'' of <var>o1</var> and <var>o2</var> on success and | |
451 | <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em> when | |
452 | <var>o1</var> supports it. This is the equivalent of the Python | |
453 | statement "<tt class="samp"><var>o1</var> &= <var>o2</var></tt>". | |
454 | </dd></dl> | |
455 | ||
456 | <P> | |
457 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-298' xml:id='l2h-298' class="cfunction">PyNumber_InPlaceXor</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
458 | <dd> | |
459 | <div class="refcount-info"> | |
460 | <span class="label">Return value:</span> | |
461 | <span class="value">New reference.</span> | |
462 | </div> | |
463 | Returns the ``bitwise exclusive or'' of <var>o1</var> by <var>o2</var> on | |
464 | success, or <tt class="constant">NULL</tt> on failure. The operation is done | |
465 | <em>in-place</em> when <var>o1</var> supports it. This is the equivalent | |
466 | of the Python statement "<tt class="samp"><var>o1</var> ^= <var>o2</var></tt>". | |
467 | </dd></dl> | |
468 | ||
469 | <P> | |
470 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-299' xml:id='l2h-299' class="cfunction">PyNumber_InPlaceOr</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt> | |
471 | <dd> | |
472 | <div class="refcount-info"> | |
473 | <span class="label">Return value:</span> | |
474 | <span class="value">New reference.</span> | |
475 | </div> | |
476 | Returns the ``bitwise or'' of <var>o1</var> and <var>o2</var> on success, or | |
477 | <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em> when | |
478 | <var>o1</var> supports it. This is the equivalent of the Python | |
479 | statement "<tt class="samp"><var>o1</var> |= <var>o2</var></tt>". | |
480 | </dd></dl> | |
481 | ||
482 | <P> | |
483 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-300' xml:id='l2h-300' class="cfunction">PyNumber_Coerce</tt></b>(</nobr></td><td>PyObject **<var>p1</var>, PyObject **<var>p2</var>)</td></tr></table></dt> | |
484 | <dd> | |
485 | This function takes the addresses of two variables of type | |
486 | <tt class="ctype">PyObject*</tt>. If the objects pointed to by <code>*<var>p1</var></code> | |
487 | and <code>*<var>p2</var></code> have the same type, increment their reference | |
488 | count and return <code>0</code> (success). If the objects can be converted | |
489 | to a common numeric type, replace <code>*p1</code> and <code>*p2</code> by their | |
490 | converted value (with 'new' reference counts), and return <code>0</code>. | |
491 | If no conversion is possible, or if some other error occurs, return | |
492 | <code>-1</code> (failure) and don't increment the reference counts. The | |
493 | call <code>PyNumber_Coerce(&o1, &o2)</code> is equivalent to the Python | |
494 | statement "<tt class="samp"><var>o1</var>, <var>o2</var> = coerce(<var>o1</var>, <var>o2</var>)</tt>". | |
495 | <a id='l2h-301' xml:id='l2h-301'></a></dd></dl> | |
496 | ||
497 | <P> | |
498 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-302' xml:id='l2h-302' class="cfunction">PyNumber_Int</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
499 | <dd> | |
500 | <div class="refcount-info"> | |
501 | <span class="label">Return value:</span> | |
502 | <span class="value">New reference.</span> | |
503 | </div> | |
504 | Returns the <var>o</var> converted to an integer object on success, or | |
505 | <tt class="constant">NULL</tt> on failure. If the argument is outside the integer range | |
506 | a long object will be returned instead. This is the equivalent | |
507 | of the Python expression "<tt class="samp">int(<var>o</var>)</tt>".<a id='l2h-303' xml:id='l2h-303'></a></dd></dl> | |
508 | ||
509 | <P> | |
510 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-304' xml:id='l2h-304' class="cfunction">PyNumber_Long</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
511 | <dd> | |
512 | <div class="refcount-info"> | |
513 | <span class="label">Return value:</span> | |
514 | <span class="value">New reference.</span> | |
515 | </div> | |
516 | Returns the <var>o</var> converted to a long integer object on success, | |
517 | or <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python | |
518 | expression "<tt class="samp">long(<var>o</var>)</tt>".<a id='l2h-305' xml:id='l2h-305'></a></dd></dl> | |
519 | ||
520 | <P> | |
521 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-306' xml:id='l2h-306' class="cfunction">PyNumber_Float</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> | |
522 | <dd> | |
523 | <div class="refcount-info"> | |
524 | <span class="label">Return value:</span> | |
525 | <span class="value">New reference.</span> | |
526 | </div> | |
527 | Returns the <var>o</var> converted to a float object on success, or | |
528 | <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python expression | |
529 | "<tt class="samp">float(<var>o</var>)</tt>".<a id='l2h-307' xml:id='l2h-307'></a></dd></dl> | |
530 | ||
531 | <P> | |
532 | ||
533 | <DIV CLASS="navigation"> | |
534 | <div class='online-navigation'> | |
535 | <p></p><hr /> | |
536 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
537 | <tr> | |
538 | <td class='online-navigation'><a rel="prev" title="6.1 Object Protocol" | |
539 | href="object.html"><img src='../icons/previous.png' | |
540 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
541 | <td class='online-navigation'><a rel="parent" title="6. Abstract Objects Layer" | |
542 | href="abstract.html"><img src='../icons/up.png' | |
543 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
544 | <td class='online-navigation'><a rel="next" title="6.3 Sequence Protocol" | |
545 | href="sequence.html"><img src='../icons/next.png' | |
546 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
547 | <td align="center" width="100%">Python/C API Reference Manual</td> | |
548 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
549 | href="contents.html"><img src='../icons/contents.png' | |
550 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
551 | <td class='online-navigation'><img src='../icons/blank.png' | |
552 | border='0' height='32' alt='' width='32' /></td> | |
553 | <td class='online-navigation'><a rel="index" title="Index" | |
554 | href="genindex.html"><img src='../icons/index.png' | |
555 | border='0' height='32' alt='Index' width='32' /></A></td> | |
556 | </tr></table> | |
557 | <div class='online-navigation'> | |
558 | <b class="navlabel">Previous:</b> | |
559 | <a class="sectref" rel="prev" href="object.html">6.1 Object Protocol</A> | |
560 | <b class="navlabel">Up:</b> | |
561 | <a class="sectref" rel="parent" href="abstract.html">6. Abstract Objects Layer</A> | |
562 | <b class="navlabel">Next:</b> | |
563 | <a class="sectref" rel="next" href="sequence.html">6.3 Sequence Protocol</A> | |
564 | </div> | |
565 | </div> | |
566 | <hr /> | |
567 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
568 | </DIV> | |
569 | <!--End of Navigation Panel--> | |
570 | <ADDRESS> | |
571 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
572 | </ADDRESS> | |
573 | </BODY> | |
574 | </HTML> |