-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.html
More file actions
476 lines (418 loc) · 44 KB
/
number.html
File metadata and controls
476 lines (418 loc) · 44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_TW">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Number Protocol — Python 3.7.0 說明文件</title>
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/translations.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.7.0 說明文件 中搜尋"
href="../_static/opensearch.xml"/>
<link rel="author" title="關於這些文件" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜尋" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Sequence Protocol" href="sequence.html" />
<link rel="prev" title="Object Protocol" href="object.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/c-api/number.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="sequence.html" title="Sequence Protocol"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="object.html" title="Object Protocol"
accesskey="P">上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python / C API 參考手冊</a> »</li>
<li class="nav-item nav-item-2"><a href="abstract.html" accesskey="U">抽象物件層</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="number-protocol">
<span id="number"></span><h1>Number Protocol<a class="headerlink" href="#number-protocol" title="本標題的永久連結">¶</a></h1>
<dl class="function">
<dt id="c.PyNumber_Check">
int <code class="descname">PyNumber_Check</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Check" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">1</span></code> if the object <em>o</em> provides numeric protocols, and false otherwise.
This function always succeeds.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Add">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Add</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Add" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of adding <em>o1</em> and <em>o2</em>, or <em>NULL</em> on failure. This is the
equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">+</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Subtract">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Subtract</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Subtract" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of subtracting <em>o2</em> from <em>o1</em>, or <em>NULL</em> on failure. This is
the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">-</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Multiply">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Multiply</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Multiply" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of multiplying <em>o1</em> and <em>o2</em>, or <em>NULL</em> on failure. This is
the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">*</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_MatrixMultiply">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_MatrixMultiply</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_MatrixMultiply" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the result of matrix multiplication on <em>o1</em> and <em>o2</em>, or <em>NULL</em> on
failure. This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">@</span> <span class="pre">o2</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">3.5 版新加入.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_FloorDivide">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_FloorDivide</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_FloorDivide" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Return the floor of <em>o1</em> divided by <em>o2</em>, or <em>NULL</em> on failure. This is
equivalent to the 「classic」 division of integers.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_TrueDivide">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_TrueDivide</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_TrueDivide" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Return a reasonable approximation for the mathematical value of <em>o1</em> divided by
<em>o2</em>, or <em>NULL</em> 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.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Remainder">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Remainder</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Remainder" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the remainder of dividing <em>o1</em> by <em>o2</em>, or <em>NULL</em> on failure. This is
the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">%</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Divmod">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Divmod</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Divmod" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-0">See the built-in function <a class="reference internal" href="../library/functions.html#divmod" title="divmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">divmod()</span></code></a>. Returns <em>NULL</em> on failure. This is
the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">divmod(o1,</span> <span class="pre">o2)</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Power">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Power</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o3</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Power" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-1">See the built-in function <a class="reference internal" href="../library/functions.html#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a>. Returns <em>NULL</em> on failure. This is the
equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">pow(o1,</span> <span class="pre">o2,</span> <span class="pre">o3)</span></code>, where <em>o3</em> is optional.
If <em>o3</em> is to be ignored, pass <a class="reference internal" href="none.html#c.Py_None" title="Py_None"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a> in its place (passing <em>NULL</em> for
<em>o3</em> would cause an illegal memory access).</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Negative">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Negative</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Negative" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the negation of <em>o</em> on success, or <em>NULL</em> on failure. This is the
equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">-o</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Positive">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Positive</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Positive" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns <em>o</em> on success, or <em>NULL</em> on failure. This is the equivalent of the
Python expression <code class="docutils literal notranslate"><span class="pre">+o</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Absolute">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Absolute</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Absolute" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-2">Returns the absolute value of <em>o</em>, or <em>NULL</em> on failure. This is the equivalent
of the Python expression <code class="docutils literal notranslate"><span class="pre">abs(o)</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Invert">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Invert</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Invert" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the bitwise negation of <em>o</em> on success, or <em>NULL</em> on failure. This is
the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">~o</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Lshift">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Lshift</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Lshift" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of left shifting <em>o1</em> by <em>o2</em> on success, or <em>NULL</em> on
failure. This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre"><<</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Rshift">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Rshift</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Rshift" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of right shifting <em>o1</em> by <em>o2</em> on success, or <em>NULL</em> on
failure. This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">>></span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_And">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_And</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_And" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the 「bitwise and」 of <em>o1</em> and <em>o2</em> on success and <em>NULL</em> on failure.
This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">&</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Xor">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Xor</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Xor" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the 「bitwise exclusive or」 of <em>o1</em> by <em>o2</em> on success, or <em>NULL</em> on
failure. This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">^</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Or">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Or</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Or" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the 「bitwise or」 of <em>o1</em> and <em>o2</em> on success, or <em>NULL</em> on failure.
This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">|</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceAdd">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceAdd</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceAdd" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of adding <em>o1</em> and <em>o2</em>, or <em>NULL</em> on failure. The operation
is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of the Python
statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">+=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceSubtract">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceSubtract</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceSubtract" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of subtracting <em>o2</em> from <em>o1</em>, or <em>NULL</em> on failure. The
operation is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of
the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">-=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceMultiply">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceMultiply</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceMultiply" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of multiplying <em>o1</em> and <em>o2</em>, or <em>NULL</em> on failure. The
operation is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of
the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">*=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceMatrixMultiply">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceMatrixMultiply</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceMatrixMultiply" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the result of matrix multiplication on <em>o1</em> and <em>o2</em>, or <em>NULL</em> on
failure. The operation is done <em>in-place</em> when <em>o1</em> supports it. This is
the equivalent of the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">@=</span> <span class="pre">o2</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">3.5 版新加入.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceFloorDivide">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceFloorDivide</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceFloorDivide" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the mathematical floor of dividing <em>o1</em> by <em>o2</em>, or <em>NULL</em> on failure.
The operation is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent
of the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">//=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceTrueDivide">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceTrueDivide</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceTrueDivide" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Return a reasonable approximation for the mathematical value of <em>o1</em> divided by
<em>o2</em>, or <em>NULL</em> 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 <em>in-place</em> when <em>o1</em> supports it.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceRemainder">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceRemainder</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceRemainder" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the remainder of dividing <em>o1</em> by <em>o2</em>, or <em>NULL</em> on failure. The
operation is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of
the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">%=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlacePower">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlacePower</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o3</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlacePower" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-3">See the built-in function <a class="reference internal" href="../library/functions.html#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a>. Returns <em>NULL</em> on failure. The operation
is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of the Python
statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">**=</span> <span class="pre">o2</span></code> when o3 is <a class="reference internal" href="none.html#c.Py_None" title="Py_None"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a>, or an in-place variant of
<code class="docutils literal notranslate"><span class="pre">pow(o1,</span> <span class="pre">o2,</span> <span class="pre">o3)</span></code> otherwise. If <em>o3</em> is to be ignored, pass <a class="reference internal" href="none.html#c.Py_None" title="Py_None"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a>
in its place (passing <em>NULL</em> for <em>o3</em> would cause an illegal memory access).</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceLshift">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceLshift</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceLshift" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of left shifting <em>o1</em> by <em>o2</em> on success, or <em>NULL</em> on
failure. The operation is done <em>in-place</em> when <em>o1</em> supports it. This is the
equivalent of the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre"><<=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceRshift">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceRshift</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceRshift" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the result of right shifting <em>o1</em> by <em>o2</em> on success, or <em>NULL</em> on
failure. The operation is done <em>in-place</em> when <em>o1</em> supports it. This is the
equivalent of the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">>>=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceAnd">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceAnd</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceAnd" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the 「bitwise and」 of <em>o1</em> and <em>o2</em> on success and <em>NULL</em> on failure. The
operation is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of
the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">&=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceXor">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceXor</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceXor" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the 「bitwise exclusive or」 of <em>o1</em> by <em>o2</em> on success, or <em>NULL</em> on
failure. The operation is done <em>in-place</em> when <em>o1</em> supports it. This is the
equivalent of the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">^=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_InPlaceOr">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_InPlaceOr</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_InPlaceOr" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Returns the 「bitwise or」 of <em>o1</em> and <em>o2</em> on success, or <em>NULL</em> on failure. The
operation is done <em>in-place</em> when <em>o1</em> supports it. This is the equivalent of
the Python statement <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">|=</span> <span class="pre">o2</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Long">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Long</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Long" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-4">Returns the <em>o</em> converted to an integer object on success, or <em>NULL</em> on
failure. This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">int(o)</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Float">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Float</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Float" title="本定義的永久連結">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-5">Returns the <em>o</em> converted to a float object on success, or <em>NULL</em> on failure.
This is the equivalent of the Python expression <code class="docutils literal notranslate"><span class="pre">float(o)</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_Index">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_Index</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_Index" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the <em>o</em> converted to a Python int on success or <em>NULL</em> with a
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> exception raised on failure.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_ToBase">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyNumber_ToBase</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *n</em>, int<em> base</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_ToBase" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the integer <em>n</em> converted to base <em>base</em> as a string. The <em>base</em>
argument must be one of 2, 8, 10, or 16. For base 2, 8, or 16, the
returned string is prefixed with a base marker of <code class="docutils literal notranslate"><span class="pre">'0b'</span></code>, <code class="docutils literal notranslate"><span class="pre">'0o'</span></code>, or
<code class="docutils literal notranslate"><span class="pre">'0x'</span></code>, respectively. If <em>n</em> is not a Python int, it is converted with
<a class="reference internal" href="#c.PyNumber_Index" title="PyNumber_Index"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Index()</span></code></a> first.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyNumber_AsSsize_t">
Py_ssize_t <code class="descname">PyNumber_AsSsize_t</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *exc</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyNumber_AsSsize_t" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns <em>o</em> converted to a Py_ssize_t value if <em>o</em> can be interpreted as an
integer. If the call fails, an exception is raised and <code class="docutils literal notranslate"><span class="pre">-1</span></code> is returned.</p>
<p>If <em>o</em> can be converted to a Python int but the attempt to
convert to a Py_ssize_t value would raise an <a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a>, then the
<em>exc</em> argument is the type of exception that will be raised (usually
<a class="reference internal" href="../library/exceptions.html#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a> or <a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a>). If <em>exc</em> is <em>NULL</em>, then the
exception is cleared and the value is clipped to <em>PY_SSIZE_T_MIN</em> for a negative
integer or <em>PY_SSIZE_T_MAX</em> for a positive integer.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyIndex_Check">
int <code class="descname">PyIndex_Check</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyIndex_Check" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">1</span></code> if <em>o</em> is an index integer (has the nb_index slot of the
tp_as_number structure filled in), and <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise.</p>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>上個主題</h4>
<p class="topless"><a href="object.html"
title="上一章">Object Protocol</a></p>
<h4>下個主題</h4>
<p class="topless"><a href="sequence.html"
title="下一章">Sequence Protocol</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.7/Doc/c-api/number.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="sequence.html" title="Sequence Protocol"
>下一頁</a> |</li>
<li class="right" >
<a href="object.html" title="Object Protocol"
>上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python / C API 參考手冊</a> »</li>
<li class="nav-item nav-item-2"><a href="abstract.html" >抽象物件層</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 2001-2018, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on 8月 22, 2018.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.7.
</div>
</body>
</html>