Issue 1577: shutil.move() where destination is a directory was doing a
[python.git] / Doc / c-api / long.rst
blob49a5e6f766b29fd63c84ada8630f57ad367c9b1f
1 .. highlightlang:: c
3 .. _longobjects:
5 Long Integer Objects
6 --------------------
8 .. index:: object: long integer
11 .. ctype:: PyLongObject
13    This subtype of :ctype:`PyObject` represents a Python long integer object.
16 .. cvar:: PyTypeObject PyLong_Type
18    .. index:: single: LongType (in modules types)
20    This instance of :ctype:`PyTypeObject` represents the Python long integer type.
21    This is the same object as ``long`` and ``types.LongType``.
24 .. cfunction:: int PyLong_Check(PyObject *p)
26    Return true if its argument is a :ctype:`PyLongObject` or a subtype of
27    :ctype:`PyLongObject`.
29    .. versionchanged:: 2.2
30       Allowed subtypes to be accepted.
33 .. cfunction:: int PyLong_CheckExact(PyObject *p)
35    Return true if its argument is a :ctype:`PyLongObject`, but not a subtype of
36    :ctype:`PyLongObject`.
38    .. versionadded:: 2.2
41 .. cfunction:: PyObject* PyLong_FromLong(long v)
43    Return a new :ctype:`PyLongObject` object from *v*, or *NULL* on failure.
46 .. cfunction:: PyObject* PyLong_FromUnsignedLong(unsigned long v)
48    Return a new :ctype:`PyLongObject` object from a C :ctype:`unsigned long`, or
49    *NULL* on failure.
52 .. cfunction:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v)
54    Return a new :ctype:`PyLongObject` object from a C :ctype:`long long`, or *NULL*
55    on failure.
58 .. cfunction:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v)
60    Return a new :ctype:`PyLongObject` object from a C :ctype:`unsigned long long`,
61    or *NULL* on failure.
64 .. cfunction:: PyObject* PyLong_FromDouble(double v)
66    Return a new :ctype:`PyLongObject` object from the integer part of *v*, or
67    *NULL* on failure.
70 .. cfunction:: PyObject* PyLong_FromString(char *str, char **pend, int base)
72    Return a new :ctype:`PyLongObject` based on the string value in *str*, which is
73    interpreted according to the radix in *base*.  If *pend* is non-*NULL*,
74    ``*pend`` will point to the first character in *str* which follows the
75    representation of the number.  If *base* is ``0``, the radix will be determined
76    based on the leading characters of *str*: if *str* starts with ``'0x'`` or
77    ``'0X'``, radix 16 will be used; if *str* starts with ``'0'``, radix 8 will be
78    used; otherwise radix 10 will be used.  If *base* is not ``0``, it must be
79    between ``2`` and ``36``, inclusive.  Leading spaces are ignored.  If there are
80    no digits, :exc:`ValueError` will be raised.
83 .. cfunction:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
85    Convert a sequence of Unicode digits to a Python long integer value.  The first
86    parameter, *u*, points to the first character of the Unicode string, *length*
87    gives the number of characters, and *base* is the radix for the conversion.  The
88    radix must be in the range [2, 36]; if it is out of range, :exc:`ValueError`
89    will be raised.
91    .. versionadded:: 1.6
94 .. cfunction:: PyObject* PyLong_FromVoidPtr(void *p)
96    Create a Python integer or long integer from the pointer *p*. The pointer value
97    can be retrieved from the resulting value using :cfunc:`PyLong_AsVoidPtr`.
99    .. versionadded:: 1.5.2
101    .. versionchanged:: 2.5
102       If the integer is larger than LONG_MAX, a positive long integer is returned.
105 .. cfunction:: long PyLong_AsLong(PyObject *pylong)
107    .. index::
108       single: LONG_MAX
109       single: OverflowError (built-in exception)
111    Return a C :ctype:`long` representation of the contents of *pylong*.  If
112    *pylong* is greater than :const:`LONG_MAX`, an :exc:`OverflowError` is raised.
115 .. cfunction:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
117    .. index::
118       single: ULONG_MAX
119       single: OverflowError (built-in exception)
121    Return a C :ctype:`unsigned long` representation of the contents of *pylong*.
122    If *pylong* is greater than :const:`ULONG_MAX`, an :exc:`OverflowError` is
123    raised.
126 .. cfunction:: PY_LONG_LONG PyLong_AsLongLong(PyObject *pylong)
128    Return a C :ctype:`long long` from a Python long integer.  If *pylong* cannot be
129    represented as a :ctype:`long long`, an :exc:`OverflowError` will be raised.
131    .. versionadded:: 2.2
134 .. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
136    Return a C :ctype:`unsigned long long` from a Python long integer. If *pylong*
137    cannot be represented as an :ctype:`unsigned long long`, an :exc:`OverflowError`
138    will be raised if the value is positive, or a :exc:`TypeError` will be raised if
139    the value is negative.
141    .. versionadded:: 2.2
144 .. cfunction:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io)
146    Return a C :ctype:`unsigned long` from a Python long integer, without checking
147    for overflow.
149    .. versionadded:: 2.3
152 .. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io)
154    Return a C :ctype:`unsigned long long` from a Python long integer, without
155    checking for overflow.
157    .. versionadded:: 2.3
160 .. cfunction:: double PyLong_AsDouble(PyObject *pylong)
162    Return a C :ctype:`double` representation of the contents of *pylong*.  If
163    *pylong* cannot be approximately represented as a :ctype:`double`, an
164    :exc:`OverflowError` exception is raised and ``-1.0`` will be returned.
167 .. cfunction:: void* PyLong_AsVoidPtr(PyObject *pylong)
169    Convert a Python integer or long integer *pylong* to a C :ctype:`void` pointer.
170    If *pylong* cannot be converted, an :exc:`OverflowError` will be raised.  This
171    is only assured to produce a usable :ctype:`void` pointer for values created
172    with :cfunc:`PyLong_FromVoidPtr`.
174    .. versionadded:: 1.5.2
176    .. versionchanged:: 2.5
177       For values outside 0..LONG_MAX, both signed and unsigned integers are accepted.