picop.cyfloat#

Fast float helpers.

picop.cyfloat.float_as_double(pyfloat)#

Return the C double of a Python float (PyFloat_AsDouble).

Notes

Slower than the plain-Python equivalent float(x) (Tier A 1.40–1.51x); hands Cython a C double.

Parameters:

pyfloat (object)

Return type:

float

picop.cyfloat.float_check(p)#

Return True if p is a float or subtype (PyFloat_Check).

Parameters:

p (object)

Return type:

bool

picop.cyfloat.float_check_exact(p)#

Return True if type(p) is float (PyFloat_CheckExact).

Parameters:

p (object)

Return type:

bool

picop.cyfloat.float_eq(a, b)#

Return True if values are equal with Python float parity.

Notes

Matches CPython: NaN != NaN, and +0.0 == -0.0.

Parameters:
Return type:

bool

picop.cyfloat.float_from_cstr(s)#

Return a float parsed from a str/bytes object (PyFloat_FromString).

Notes

Slower than the plain-Python equivalent float(x) (Tier A 1.02x); hands Cython a C double.

Parameters:

s (object)

Return type:

object

picop.cyfloat.float_from_double(v)#

Return a Python float from a C double (PyFloat_FromDouble).

Notes

Slower than the plain-Python equivalent float(x) (Tier A 1.46x); hands Cython a C double.

Parameters:

v (float)

Return type:

object

picop.cyfloat.float_pack2(value, little_endian=True)#

Pack a C double into IEEE half precision.

Parameters:
  • value (float)

  • little_endian (bool, default: True)

Return type:

bytes

picop.cyfloat.float_pack4(value, little_endian=True)#

Pack a C double into 4 bytes (rounded to float precision).

Parameters:
  • value (float)

  • little_endian (bool, default: True)

Return type:

bytes

picop.cyfloat.float_pack8(value, little_endian=True)#

Pack a C double into 8 bytes using the selected byte order.

Parameters:
  • value (float)

  • little_endian (bool, default: True)

Return type:

bytes

picop.cyfloat.float_unpack2(data, little_endian=True)#

Unpack exactly 2 bytes; reject short buffers before raw-pointer access.

Parameters:
  • data (bytes)

  • little_endian (bool, default: True)

Return type:

float

picop.cyfloat.float_unpack4(data, little_endian=True)#

Unpack exactly 4 bytes; reject short buffers before raw-pointer access.

Parameters:
  • data (bytes)

  • little_endian (bool, default: True)

Return type:

float

picop.cyfloat.float_unpack8(data, little_endian=True)#

Unpack exactly 8 bytes; reject short buffers before raw-pointer access.

Parameters:
  • data (bytes)

  • little_endian (bool, default: True)

Return type:

float