View Source Pythonx.C.PyLong (Pythonx v0.2.4)
All integers are implemented as PyLong.t()
integer objects of arbitrary size.
Summary
Functions
Return a C double
representation of pylong
. pylong
must be an instance of PyLongObject.
Return a C long
representation of obj.
Return a C long
representation of obj.
Return a C long long
representation of obj
.
Return a C long long
representation of obj
.
Return a C size_t
representation of pylong
. pylong
must be an instance of PyLongObject.
Return a C Py_ssize_t
representation of pylong
. pylong
must be an instance of PyLongObject.
Return a C unsigned long
representation of pylong
. pylong
must be an instance of PyLongObject.
Return a C unsigned long long
representation of pylong
. pylong
must be an instance of PyLongObject.
Return a C unsigned long long
representation of pylong
. pylong
must be an instance of PyLongObject.
Return a C unsigned long
representation of pylong
. pylong
must be an instance of PyLongObject.
Return true
if its argument is a PyLongObject or a subtype of PyLongObject.
Return true
if its argument is a PyLongObject, but not a subtype of PyLongObject.
Return a new PyLongObject object from the integer part of v
, or nil
on failure.
Return a new PyLongObject object from v
, or nil
on failure.
Return a new PyLongObject object from a C long long
, or nil
on failure.
Return a new PyLongObject object from a C size_t
, or nil
on failure.
Return a new PyLongObject object from a C Py_ssize_t
, or nil
on failure.
Return a new PyLongObject based on the string value in str
, which is interpreted according to the radix in base
,
or nil
on failure.
Return a new PyLongObject object from a C unsigned long
, or nil
on failure.
Return a new PyLongObject object from a C unsigned long long
, or nil
on failure.
On success, return a read only named tuple, that holds information about Python’s internal representation of integers.
See sys.int_info
for description of individual fields.
Functions
@spec as_double(PyObject.t()) :: float() | PyErr.t()
Return a C double
representation of pylong
. pylong
must be an instance of PyLongObject.
Return PyErr.t()
with OverflowError
if the value of pylong
is out of range for a double
.
If any other exception occurs returns PyErr.t()
.
@spec as_long(PyObject.t()) :: integer() | PyErr.t()
Return a C long
representation of obj.
If obj
is not an instance of PyLongObject, first call its __index__()
method (if present) to convert it to a PyLongObject.
Returns a PyErr.t()
with an OverflowError
if the value of obj
is out of range for a long
.
@spec as_long_and_overflow(PyObject.t()) :: {result :: integer(), overflow :: -1 | 0 | 1} | PyErr.t()
Return a C long
representation of obj.
If obj
is not an instance of PyLongObject, first call its __index__()
method (if present) to convert it to a PyLongObject.
If the value of obj
is greater than LONG_MAX
or less than LONG_MIN
, returns {-1, 1}
as {-1, -1}
, respectively,
otherwise, the second element is set to 0
.
If any other exception occurs returns PyErr.t()
.
@spec as_long_long(PyObject.t()) :: integer() | PyErr.t()
Return a C long long
representation of obj
.
If obj
is not an instance of PyLongObject, first call its __index__()
method (if present) to convert it to a PyLongObject.
Returns PyErr.t()
with OverflowError
if the value of obj
is out of range for a long long
.
@spec as_long_long_and_overflow(PyObject.t()) :: {result :: integer(), overflow :: -1 | 0 | 1} | PyErr.t()
Return a C long long
representation of obj
.
If obj
is not an instance of PyLongObject, first call its __index__()
method (if present) to convert it to a PyLongObject.
If the value of obj
is greater than LLONG_MAX
or less than LLONG_MIN
, , returns {-1, 1}
as {-1, -1}
, respectively,
If any other exception occurs returns PyErr.t()
.
@spec as_size_t(PyObject.t()) :: integer() | PyErr.t()
Return a C size_t
representation of pylong
. pylong
must be an instance of PyLongObject.
Return PyErr.t()
with OverflowError
if the value of pylong
is out of range for a size_t
.
If any other exception occurs returns PyErr.t()
.
@spec as_ssize_t(PyObject.t()) :: integer() | PyErr.t()
Return a C Py_ssize_t
representation of pylong
. pylong
must be an instance of PyLongObject.
Return PyErr.t()
with OverflowError
if the value of pylong
is out of range for a Py_ssize_t
.
If any other exception occurs returns PyErr.t()
.
@spec as_unsigned_long(PyObject.t()) :: integer() | PyErr.t()
Return a C unsigned long
representation of pylong
. pylong
must be an instance of PyLongObject.
Return PyErr.t()
with OverflowError
if the value of pylong
is out of range for a unsigned long
.
If any other exception occurs returns PyErr.t()
.
@spec as_unsigned_long_long(PyObject.t()) :: integer() | PyErr.t()
Return a C unsigned long long
representation of pylong
. pylong
must be an instance of PyLongObject.
Return PyErr.t()
with OverflowError
if the value of pylong
is out of range for a unsigned long long
.
If any other exception occurs returns PyErr.t()
.
@spec as_unsigned_long_long_mask(PyObject.t()) :: integer() | PyErr.t()
Return a C unsigned long long
representation of pylong
. pylong
must be an instance of PyLongObject.
If the value of obj
is out of range for an unsigned long long
, return the reduction of that value modulo ULLONG_MAX + 1
.
If any other exception occurs returns PyErr.t()
.
@spec as_unsigned_long_mask(PyObject.t()) :: integer() | PyErr.t()
Return a C unsigned long
representation of pylong
. pylong
must be an instance of PyLongObject.
If the value of obj
is out of range for an unsigned long
, return the reduction of that value modulo ULONG_MAX + 1
.
If any other exception occurs returns PyErr.t()
.
@spec check(PyObject.t()) :: boolean()
Return true
if its argument is a PyLongObject or a subtype of PyLongObject.
This function always succeeds.
@spec check_exact(PyObject.t()) :: boolean()
Return true
if its argument is a PyLongObject, but not a subtype of PyLongObject.
This function always succeeds.
@spec from_double(number()) :: PyObject.t() | nil
Return a new PyLongObject object from the integer part of v
, or nil
on failure.
Return value: New reference.
@spec from_long(integer()) :: PyObject.t() | nil
Return a new PyLongObject object from v
, or nil
on failure.
The current Python implementation keeps an array of integer objects for all integers between -5
and 256
.
When you create an int in that range you actually just get back a reference to the existing object.
Return value: New reference.
@spec from_long_long(integer()) :: PyObject.t() | nil
Return a new PyLongObject object from a C long long
, or nil
on failure.
Return value: New reference.
@spec from_size_t(non_neg_integer()) :: PyObject.t() | nil
Return a new PyLongObject object from a C size_t
, or nil
on failure.
Return value: New reference.
@spec from_ssize_t(integer()) :: PyObject.t() | nil
Return a new PyLongObject object from a C Py_ssize_t
, or nil
on failure.
Return value: New reference.
Return a new PyLongObject based on the string value in str
, which is interpreted according to the radix in base
,
or nil
on failure.
If base
is 0, str
is interpreted using the Integer literals definition; in this case, leading zeros in a non-zero
decimal number raises a ValueError
.
If base
is not 0, it must be between 2
and 36
, inclusive. Leading and trailing whitespace and single underscores
after a base specifier and between digits are ignored.
If there are no digits or str is not NULL-terminated following the digits and trailing whitespace, ValueError
will be raised.
Return value: New reference.
@spec from_unsigned_long(non_neg_integer()) :: PyObject.t() | nil
Return a new PyLongObject object from a C unsigned long
, or nil
on failure.
Return value: New reference.
@spec from_unsigned_long_long(non_neg_integer()) :: PyObject.t() | nil
Return a new PyLongObject object from a C unsigned long long
, or nil
on failure.
Return value: New reference.
@spec get_info() :: PyObject.t() | PyErr.t()
On success, return a read only named tuple, that holds information about Python’s internal representation of integers.
See sys.int_info
for description of individual fields.
On failure, return PyErr.t()
with an exception set.