1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
<html xmlns="http://www.w3.org/1999/xhtml">
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>Long Integer Objects — Python 2.7.11 documentation</title>
11
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
14
<script type="text/javascript">
15
var DOCUMENTATION_OPTIONS = {
18
COLLAPSE_INDEX: false,
23
<script type="text/javascript" src="../_static/jquery.js"></script>
24
<script type="text/javascript" src="../_static/underscore.js"></script>
25
<script type="text/javascript" src="../_static/doctools.js"></script>
26
<script type="text/javascript" src="../_static/sidebar.js"></script>
27
<link rel="search" type="application/opensearchdescription+xml"
28
title="Search within Python 2.7.11 documentation"
29
href="../_static/opensearch.xml"/>
30
<link rel="author" title="About these documents" href="../about.html" />
31
<link rel="copyright" title="Copyright" href="../copyright.html" />
32
<link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
<link rel="up" title="Concrete Objects Layer" href="concrete.html" />
34
<link rel="next" title="Floating Point Objects" href="float.html" />
35
<link rel="prev" title="Boolean Objects" href="bool.html" />
36
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
<script type="text/javascript" src="../_static/copybutton.js"></script>
38
<script type="text/javascript" src="../_static/version_switch.js"></script>
43
<body role="document">
44
<div class="related" role="navigation" aria-label="related navigation">
47
<li class="right" style="margin-right: 10px">
48
<a href="../genindex.html" title="General Index"
49
accesskey="I">index</a></li>
51
<a href="../py-modindex.html" title="Python Module Index"
54
<a href="float.html" title="Floating Point Objects"
55
accesskey="N">next</a> |</li>
57
<a href="bool.html" title="Boolean Objects"
58
accesskey="P">previous</a> |</li>
59
<li><img src="../_static/py.png" alt=""
60
style="vertical-align: middle; margin-top: -1px"/></li>
61
<li><a href="https://www.python.org/">Python</a> »</li>
63
<span class="version_switcher_placeholder">2.7.11</span>
64
<a href="../index.html">Documentation</a> »
67
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> »</li>
68
<li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> »</li>
72
<div class="document">
73
<div class="documentwrapper">
74
<div class="bodywrapper">
75
<div class="body" role="main">
77
<div class="section" id="long-integer-objects">
78
<span id="longobjects"></span><h1>Long Integer Objects<a class="headerlink" href="#long-integer-objects" title="Permalink to this headline">¶</a></h1>
79
<span class="target" id="index-0"></span><dl class="type">
80
<dt id="c.PyLongObject">
81
<code class="descname">PyLongObject</code><a class="headerlink" href="#c.PyLongObject" title="Permalink to this definition">¶</a></dt>
82
<dd><p>This subtype of <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal"><span class="pre">PyObject</span></code></a> represents a Python long integer object.</p>
86
<dt id="c.PyLong_Type">
87
<a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a> <code class="descname">PyLong_Type</code><a class="headerlink" href="#c.PyLong_Type" title="Permalink to this definition">¶</a></dt>
88
<dd><p id="index-1">This instance of <a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject"><code class="xref c c-type docutils literal"><span class="pre">PyTypeObject</span></code></a> represents the Python long integer type.
89
This is the same object as <code class="docutils literal"><span class="pre">long</span></code> and <code class="docutils literal"><span class="pre">types.LongType</span></code>.</p>
93
<dt id="c.PyLong_Check">
94
int <code class="descname">PyLong_Check</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_Check" title="Permalink to this definition">¶</a></dt>
95
<dd><p>Return true if its argument is a <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> or a subtype of
96
<a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a>.</p>
97
<div class="versionchanged">
98
<p><span class="versionmodified">Changed in version 2.2: </span>Allowed subtypes to be accepted.</p>
102
<dl class="function">
103
<dt id="c.PyLong_CheckExact">
104
int <code class="descname">PyLong_CheckExact</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_CheckExact" title="Permalink to this definition">¶</a></dt>
105
<dd><p>Return true if its argument is a <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a>, but not a subtype of
106
<a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a>.</p>
107
<div class="versionadded">
108
<p><span class="versionmodified">New in version 2.2.</span></p>
112
<dl class="function">
113
<dt id="c.PyLong_FromLong">
114
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromLong</code><span class="sig-paren">(</span>long<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromLong" title="Permalink to this definition">¶</a></dt>
115
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from <em>v</em>, or <em>NULL</em> on failure.</p>
118
<dl class="function">
119
<dt id="c.PyLong_FromUnsignedLong">
120
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromUnsignedLong</code><span class="sig-paren">(</span>unsigned long<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromUnsignedLong" title="Permalink to this definition">¶</a></dt>
121
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from a C <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span></code>, or
122
<em>NULL</em> on failure.</p>
125
<dl class="function">
126
<dt id="c.PyLong_FromSsize_t">
127
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromSsize_t</code><span class="sig-paren">(</span>Py_ssize_t<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromSsize_t" title="Permalink to this definition">¶</a></dt>
128
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from a C <code class="xref c c-type docutils literal"><span class="pre">Py_ssize_t</span></code>, or
129
<em>NULL</em> on failure.</p>
130
<div class="versionadded">
131
<p><span class="versionmodified">New in version 2.6.</span></p>
135
<dl class="function">
136
<dt id="c.PyLong_FromSize_t">
137
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromSize_t</code><span class="sig-paren">(</span>size_t<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromSize_t" title="Permalink to this definition">¶</a></dt>
138
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from a C <code class="xref c c-type docutils literal"><span class="pre">size_t</span></code>, or
139
<em>NULL</em> on failure.</p>
140
<div class="versionadded">
141
<p><span class="versionmodified">New in version 2.6.</span></p>
145
<dl class="function">
146
<dt id="c.PyLong_FromLongLong">
147
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromLongLong</code><span class="sig-paren">(</span>PY_LONG_LONG<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromLongLong" title="Permalink to this definition">¶</a></dt>
148
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from a C <code class="xref c c-type docutils literal"><span class="pre">long</span> <span class="pre">long</span></code>, or <em>NULL</em>
152
<dl class="function">
153
<dt id="c.PyLong_FromUnsignedLongLong">
154
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromUnsignedLongLong</code><span class="sig-paren">(</span>unsigned PY_LONG_LONG<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromUnsignedLongLong" title="Permalink to this definition">¶</a></dt>
155
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from a C <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">long</span></code>,
156
or <em>NULL</em> on failure.</p>
159
<dl class="function">
160
<dt id="c.PyLong_FromDouble">
161
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromDouble</code><span class="sig-paren">(</span>double<em> v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromDouble" title="Permalink to this definition">¶</a></dt>
162
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> object from the integer part of <em>v</em>, or
163
<em>NULL</em> on failure.</p>
166
<dl class="function">
167
<dt id="c.PyLong_FromString">
168
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromString</code><span class="sig-paren">(</span>char<em> *str</em>, char<em> **pend</em>, int<em> base</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromString" title="Permalink to this definition">¶</a></dt>
169
<dd><em class="refcount">Return value: New reference.</em><p>Return a new <a class="reference internal" href="#c.PyLongObject" title="PyLongObject"><code class="xref c c-type docutils literal"><span class="pre">PyLongObject</span></code></a> based on the string value in <em>str</em>, which is
170
interpreted according to the radix in <em>base</em>. If <em>pend</em> is non-<em>NULL</em>,
171
<em>*pend</em> will point to the first character in <em>str</em> which follows the
172
representation of the number. If <em>base</em> is <code class="docutils literal"><span class="pre">0</span></code>, the radix will be determined
173
based on the leading characters of <em>str</em>: if <em>str</em> starts with <code class="docutils literal"><span class="pre">'0x'</span></code> or
174
<code class="docutils literal"><span class="pre">'0X'</span></code>, radix 16 will be used; if <em>str</em> starts with <code class="docutils literal"><span class="pre">'0'</span></code>, radix 8 will be
175
used; otherwise radix 10 will be used. If <em>base</em> is not <code class="docutils literal"><span class="pre">0</span></code>, it must be
176
between <code class="docutils literal"><span class="pre">2</span></code> and <code class="docutils literal"><span class="pre">36</span></code>, inclusive. Leading spaces are ignored. If there are
177
no digits, <a class="reference internal" href="../library/exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> will be raised.</p>
180
<dl class="function">
181
<dt id="c.PyLong_FromUnicode">
182
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromUnicode</code><span class="sig-paren">(</span><a class="reference internal" href="unicode.html#c.Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em> *u</em>, Py_ssize_t<em> length</em>, int<em> base</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromUnicode" title="Permalink to this definition">¶</a></dt>
183
<dd><em class="refcount">Return value: New reference.</em><p>Convert a sequence of Unicode digits to a Python long integer value. The first
184
parameter, <em>u</em>, points to the first character of the Unicode string, <em>length</em>
185
gives the number of characters, and <em>base</em> is the radix for the conversion. The
186
radix must be in the range [2, 36]; if it is out of range, <a class="reference internal" href="../library/exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a>
188
<div class="versionadded">
189
<p><span class="versionmodified">New in version 1.6.</span></p>
191
<div class="versionchanged">
192
<p><span class="versionmodified">Changed in version 2.5: </span>This function used an <code class="xref c c-type docutils literal"><span class="pre">int</span></code> for <em>length</em>. This might require
193
changes in your code for properly supporting 64-bit systems.</p>
197
<dl class="function">
198
<dt id="c.PyLong_FromVoidPtr">
199
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyLong_FromVoidPtr</code><span class="sig-paren">(</span>void<em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_FromVoidPtr" title="Permalink to this definition">¶</a></dt>
200
<dd><em class="refcount">Return value: New reference.</em><p>Create a Python integer or long integer from the pointer <em>p</em>. The pointer value
201
can be retrieved from the resulting value using <a class="reference internal" href="#c.PyLong_AsVoidPtr" title="PyLong_AsVoidPtr"><code class="xref c c-func docutils literal"><span class="pre">PyLong_AsVoidPtr()</span></code></a>.</p>
202
<div class="versionadded">
203
<p><span class="versionmodified">New in version 1.5.2.</span></p>
205
<div class="versionchanged">
206
<p><span class="versionmodified">Changed in version 2.5: </span>If the integer is larger than LONG_MAX, a positive long integer is returned.</p>
210
<dl class="function">
211
<dt id="c.PyLong_AsLong">
212
long <code class="descname">PyLong_AsLong</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsLong" title="Permalink to this definition">¶</a></dt>
213
<dd><p id="index-2">Return a C <code class="xref c c-type docutils literal"><span class="pre">long</span></code> representation of the contents of <em>pylong</em>. If
214
<em>pylong</em> is greater than <code class="xref py py-const docutils literal"><span class="pre">LONG_MAX</span></code>, an <a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> is raised
215
and <code class="docutils literal"><span class="pre">-1</span></code> will be returned.</p>
218
<dl class="function">
219
<dt id="c.PyLong_AsLongAndOverflow">
220
long <code class="descname">PyLong_AsLongAndOverflow</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em>, int<em> *overflow</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsLongAndOverflow" title="Permalink to this definition">¶</a></dt>
221
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">long</span></code> representation of the contents of
222
<em>pylong</em>. If <em>pylong</em> is greater than <code class="xref py py-const docutils literal"><span class="pre">LONG_MAX</span></code> or less
223
than <code class="xref py py-const docutils literal"><span class="pre">LONG_MIN</span></code>, set <em>*overflow</em> to <code class="docutils literal"><span class="pre">1</span></code> or <code class="docutils literal"><span class="pre">-1</span></code>,
224
respectively, and return <code class="docutils literal"><span class="pre">-1</span></code>; otherwise, set <em>*overflow</em> to
225
<code class="docutils literal"><span class="pre">0</span></code>. If any other exception occurs (for example a TypeError or
226
MemoryError), then <code class="docutils literal"><span class="pre">-1</span></code> will be returned and <em>*overflow</em> will
227
be <code class="docutils literal"><span class="pre">0</span></code>.</p>
228
<div class="versionadded">
229
<p><span class="versionmodified">New in version 2.7.</span></p>
233
<dl class="function">
234
<dt id="c.PyLong_AsLongLongAndOverflow">
235
PY_LONG_LONG <code class="descname">PyLong_AsLongLongAndOverflow</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em>, int<em> *overflow</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsLongLongAndOverflow" title="Permalink to this definition">¶</a></dt>
236
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">long</span> <span class="pre">long</span></code> representation of the contents of
237
<em>pylong</em>. If <em>pylong</em> is greater than <code class="xref py py-const docutils literal"><span class="pre">PY_LLONG_MAX</span></code> or less
238
than <code class="xref py py-const docutils literal"><span class="pre">PY_LLONG_MIN</span></code>, set <em>*overflow</em> to <code class="docutils literal"><span class="pre">1</span></code> or <code class="docutils literal"><span class="pre">-1</span></code>,
239
respectively, and return <code class="docutils literal"><span class="pre">-1</span></code>; otherwise, set <em>*overflow</em> to
240
<code class="docutils literal"><span class="pre">0</span></code>. If any other exception occurs (for example a TypeError or
241
MemoryError), then <code class="docutils literal"><span class="pre">-1</span></code> will be returned and <em>*overflow</em> will
242
be <code class="docutils literal"><span class="pre">0</span></code>.</p>
243
<div class="versionadded">
244
<p><span class="versionmodified">New in version 2.7.</span></p>
248
<dl class="function">
249
<dt id="c.PyLong_AsSsize_t">
250
Py_ssize_t <code class="descname">PyLong_AsSsize_t</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsSsize_t" title="Permalink to this definition">¶</a></dt>
251
<dd><p id="index-3">Return a C <code class="xref c c-type docutils literal"><span class="pre">Py_ssize_t</span></code> representation of the contents of <em>pylong</em>. If
252
<em>pylong</em> is greater than <code class="xref py py-const docutils literal"><span class="pre">PY_SSIZE_T_MAX</span></code>, an <a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> is raised
253
and <code class="docutils literal"><span class="pre">-1</span></code> will be returned.</p>
254
<div class="versionadded">
255
<p><span class="versionmodified">New in version 2.6.</span></p>
259
<dl class="function">
260
<dt id="c.PyLong_AsUnsignedLong">
261
unsigned long <code class="descname">PyLong_AsUnsignedLong</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsUnsignedLong" title="Permalink to this definition">¶</a></dt>
262
<dd><p id="index-4">Return a C <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span></code> representation of the contents of <em>pylong</em>.
263
If <em>pylong</em> is greater than <code class="xref py py-const docutils literal"><span class="pre">ULONG_MAX</span></code>, an <a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> is
267
<dl class="function">
268
<dt id="c.PyLong_AsLongLong">
269
PY_LONG_LONG <code class="descname">PyLong_AsLongLong</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsLongLong" title="Permalink to this definition">¶</a></dt>
270
<dd><p id="index-5">Return a C <code class="xref c c-type docutils literal"><span class="pre">long</span> <span class="pre">long</span></code> from a Python long integer. If
271
<em>pylong</em> cannot be represented as a <code class="xref c c-type docutils literal"><span class="pre">long</span> <span class="pre">long</span></code>, an
272
<a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> is raised and <code class="docutils literal"><span class="pre">-1</span></code> is returned.</p>
273
<div class="versionadded">
274
<p><span class="versionmodified">New in version 2.2.</span></p>
278
<dl class="function">
279
<dt id="c.PyLong_AsUnsignedLongLong">
280
unsigned PY_LONG_LONG <code class="descname">PyLong_AsUnsignedLongLong</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsUnsignedLongLong" title="Permalink to this definition">¶</a></dt>
281
<dd><p id="index-6">Return a C <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">long</span></code> from a Python long integer. If
282
<em>pylong</em> cannot be represented as an <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">long</span></code>, an
283
<a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> is raised and <code class="docutils literal"><span class="pre">(unsigned</span> <span class="pre">long</span> <span class="pre">long)-1</span></code> is
285
<div class="versionadded">
286
<p><span class="versionmodified">New in version 2.2.</span></p>
288
<div class="versionchanged">
289
<p><span class="versionmodified">Changed in version 2.7: </span>A negative <em>pylong</em> now raises <a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a>, not
290
<a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>.</p>
294
<dl class="function">
295
<dt id="c.PyLong_AsUnsignedLongMask">
296
unsigned long <code class="descname">PyLong_AsUnsignedLongMask</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *io</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsUnsignedLongMask" title="Permalink to this definition">¶</a></dt>
297
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span></code> from a Python long integer, without checking
299
<div class="versionadded">
300
<p><span class="versionmodified">New in version 2.3.</span></p>
304
<dl class="function">
305
<dt id="c.PyLong_AsUnsignedLongLongMask">
306
unsigned PY_LONG_LONG <code class="descname">PyLong_AsUnsignedLongLongMask</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *io</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsUnsignedLongLongMask" title="Permalink to this definition">¶</a></dt>
307
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">long</span></code> from a Python long integer, without
308
checking for overflow.</p>
309
<div class="versionadded">
310
<p><span class="versionmodified">New in version 2.3.</span></p>
314
<dl class="function">
315
<dt id="c.PyLong_AsDouble">
316
double <code class="descname">PyLong_AsDouble</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsDouble" title="Permalink to this definition">¶</a></dt>
317
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">double</span></code> representation of the contents of <em>pylong</em>. If
318
<em>pylong</em> cannot be approximately represented as a <code class="xref c c-type docutils literal"><span class="pre">double</span></code>, an
319
<a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> exception is raised and <code class="docutils literal"><span class="pre">-1.0</span></code> will be returned.</p>
322
<dl class="function">
323
<dt id="c.PyLong_AsVoidPtr">
324
void* <code class="descname">PyLong_AsVoidPtr</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *pylong</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyLong_AsVoidPtr" title="Permalink to this definition">¶</a></dt>
325
<dd><p>Convert a Python integer or long integer <em>pylong</em> to a C <code class="xref c c-type docutils literal"><span class="pre">void</span></code> pointer.
326
If <em>pylong</em> cannot be converted, an <a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><code class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></code></a> will be raised. This
327
is only assured to produce a usable <code class="xref c c-type docutils literal"><span class="pre">void</span></code> pointer for values created
328
with <a class="reference internal" href="#c.PyLong_FromVoidPtr" title="PyLong_FromVoidPtr"><code class="xref c c-func docutils literal"><span class="pre">PyLong_FromVoidPtr()</span></code></a>.</p>
329
<div class="versionadded">
330
<p><span class="versionmodified">New in version 1.5.2.</span></p>
332
<div class="versionchanged">
333
<p><span class="versionmodified">Changed in version 2.5: </span>For values outside 0..LONG_MAX, both signed and unsigned integers are accepted.</p>
343
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
344
<div class="sphinxsidebarwrapper">
345
<h4>Previous topic</h4>
346
<p class="topless"><a href="bool.html"
347
title="previous chapter">Boolean Objects</a></p>
349
<p class="topless"><a href="float.html"
350
title="next chapter">Floating Point Objects</a></p>
352
<ul class="this-page-menu">
353
<li><a href="../bugs.html">Report a Bug</a></li>
354
<li><a href="../_sources/c-api/long.txt"
355
rel="nofollow">Show Source</a></li>
358
<div id="searchbox" style="display: none" role="search">
359
<h3>Quick search</h3>
360
<form class="search" action="../search.html" method="get">
361
<input type="text" name="q" />
362
<input type="submit" value="Go" />
363
<input type="hidden" name="check_keywords" value="yes" />
364
<input type="hidden" name="area" value="default" />
366
<p class="searchtip" style="font-size: 90%">
367
Enter search terms or a module, class or function name.
370
<script type="text/javascript">$('#searchbox').show(0);</script>
373
<div class="clearer"></div>
375
<div class="related" role="navigation" aria-label="related navigation">
378
<li class="right" style="margin-right: 10px">
379
<a href="../genindex.html" title="General Index"
382
<a href="../py-modindex.html" title="Python Module Index"
385
<a href="float.html" title="Floating Point Objects"
388
<a href="bool.html" title="Boolean Objects"
390
<li><img src="../_static/py.png" alt=""
391
style="vertical-align: middle; margin-top: -1px"/></li>
392
<li><a href="https://www.python.org/">Python</a> »</li>
394
<span class="version_switcher_placeholder">2.7.11</span>
395
<a href="../index.html">Documentation</a> »
398
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> »</li>
399
<li class="nav-item nav-item-2"><a href="concrete.html" >Concrete Objects Layer</a> »</li>
403
© <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
405
The Python Software Foundation is a non-profit corporation.
406
<a href="https://www.python.org/psf/donations/">Please donate.</a>
408
Last updated on Jan 23, 2016.
409
<a href="../bugs.html">Found a bug</a>?
411
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
b'\\ No newline at end of file'