Skip to main content

Fast fixed-sized C-like integer types.

Project description

cinc provides fixed-width C-like integer types. The speed of these types are comparable to python ints.

Usage

Signed types are named “intN” and unsigned types are named “uintN”, where “N” is the number of bits. Types for 8, 16, 32 and 64 bits are provided.

cinc integers can be constructed from Python ints or cast from another cinc type. If the source integer has more bits than the cinc type then it is truncated:

>>> x = uint32(0xFFFFFFFF)
>>> x
cinc.uint32(4294967295)
>>> uint16(x)
cinc.uint16(65535)

Arithmetic

cinc integers are compatible with python ints. Comparisons and operators cast the integer to their cinc type before performing the comparison or operation.

The result of the operation has the same type as the left operand:

>>> x = uint32(2)
>>> y = int32(2)
>>> x + y
cinc.uint32(4)
>>> y + x
cinc.int32(4)

This applies to operations with python ints too:

>>> x = uint32(2)
>>> x + 2
cinc.uint32(4)
>>> 2 + x
4

There are also methods for bit rotate operations and bit insertion and extraction:

>>> x = uint32(0x000000ff)
>>> hex(x.rrotate(8))
'0xff000000'
>>> y = uint32(0xff000000)
>>> hex(y.insert(0xff, 8, 8))
'0xff00ff00'
>>> hex(y.extract(16, 16))
'0xff00'

Python Fallback

If no C++ compiler is available during installation, then a Python source module based on ctypes is used instead. The Python version is significantly slower than the compiled C extension.

Changelog

2.0

  • cinc types are now compatible with python ints.

  • A pure Python module was added.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cinc-2.0.post1.tar.gz (10.8 kB view details)

Uploaded Source

File details

Details for the file cinc-2.0.post1.tar.gz.

File metadata

  • Download URL: cinc-2.0.post1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.8

File hashes

Hashes for cinc-2.0.post1.tar.gz
Algorithm Hash digest
SHA256 e63efe6d7954212bb455c2ba540412eeaf968344614d204fb90217af9fcea895
MD5 313b16c132882f0e7ffc1bb705deabc2
BLAKE2b-256 1020123d80d552d08d7b9c2ed4c262f8e2ff101a18acf321f06f85dd9607a7ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page