picop.cylong#

Fast int / long C-API helpers.

picop.cylong.int_eq(a, b)#

Return True if a == b — thin alias of long_eq (same semantics).

Parameters:
Return type:

bool

picop.cylong.long_as_double(pylong)#

Return the C double of an integer (PyLong_AsDouble).

Notes

Slower than the plain-Python equivalent float(x) (Tier A 1.03x); hands Cython a C integer type.

Parameters:

pylong (object)

Return type:

float

picop.cylong.long_as_long(pylong)#

Return the C long of an integer (PyLong_AsLong).

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.12x); hands Cython a C integer type.

Parameters:

pylong (object)

Return type:

int

picop.cylong.long_as_long_overflow(pylong)#

Return (value, overflow) via PyLong_AsLongAndOverflow.

Parameters:

pylong (object)

Return type:

tuple[int, int]

picop.cylong.long_as_longlong(pylong)#

Return a long long via PyLong_AsLongLong.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.83x); hands Cython a C integer type.

Parameters:

pylong (object)

Return type:

int

picop.cylong.long_as_ssize(pylong)#

Return the Py_ssize_t of an integer (PyLong_AsSsize_t).

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.13x); hands Cython a C integer type.

Parameters:

pylong (object)

Return type:

int

picop.cylong.long_as_ulong(pylong)#

Return an unsigned long via PyLong_AsUnsignedLong.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.12x); hands Cython a C integer type.

Parameters:

pylong (object)

Return type:

int

picop.cylong.long_as_ulong_mask(io)#

Return PyLong_AsUnsignedLongMask.

Notes

Wraps on overflow and does not raise — trusted-caller. See Safety.

Parameters:

io (object)

Return type:

int

picop.cylong.long_as_ulonglong(pylong)#

Return an unsigned long long via PyLong_AsUnsignedLongLong.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.83x); hands Cython a C integer type.

Parameters:

pylong (object)

Return type:

int

picop.cylong.long_as_ulonglong_mask(io)#

Return PyLong_AsUnsignedLongLongMask.

Notes

Wraps on overflow and does not raise — trusted-caller. See Safety.

Parameters:

io (object)

Return type:

int

picop.cylong.long_check(p)#

Return True if p is an int or subtype (PyLong_Check).

Parameters:

p (object)

Return type:

bool

picop.cylong.long_check_exact(p)#

Return True if type(p) is int (PyLong_CheckExact); False for bool.

Parameters:

p (object)

Return type:

bool

picop.cylong.long_eq(a, b)#

Return True if integers are equal (identity short-circuit + richcompare).

Parameters:
Return type:

bool

picop.cylong.long_from_double(v)#

Return a Python int from a C double (PyLong_FromDouble).

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.04x); hands Cython a C integer type.

Parameters:

v (float)

Return type:

object

picop.cylong.long_from_long(v)#

Return a Python int from a C long (PyLong_FromLong).

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.07x); hands Cython a C integer type.

Parameters:

v (int)

Return type:

object

picop.cylong.long_from_longlong(v)#

Return an int from long long via PyLong_FromLongLong.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.58x); hands Cython a C integer type.

Parameters:

v (int)

Return type:

object

picop.cylong.long_from_size(v)#

Return an int from size_t via PyLong_FromSize_t.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.08x); hands Cython a C integer type.

Parameters:

v (int)

Return type:

object

picop.cylong.long_from_ssize(v)#

Return a Python int from a Py_ssize_t (PyLong_FromSsize_t).

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.09x); hands Cython a C integer type.

Parameters:

v (int)

Return type:

object

picop.cylong.long_from_ulong(v)#

Return an int from an unsigned long via PyLong_FromUnsignedLong.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.06x); hands Cython a C integer type.

Parameters:

v (int)

Return type:

object

picop.cylong.long_from_ulonglong(v)#

Return an int from unsigned long long via PyLong_FromUnsignedLongLong.

Notes

Slower than the plain-Python equivalent int(x) (Tier A 1.59x); hands Cython a C integer type.

Parameters:

v (int)

Return type:

object

picop.cylong.long_is_negative(value)#

Return whether an integer is negative (PyLong_IsNegative).

Parameters:

value (object)

Return type:

bool

picop.cylong.long_is_positive(value)#

Return whether an integer is positive (PyLong_IsPositive).

Parameters:

value (object)

Return type:

bool

picop.cylong.long_is_zero(value)#

Return whether an integer is zero (PyLong_IsZero).

Parameters:

value (object)

Return type:

bool