Registry / serialization / fixedint

fixedint

JSON →
library0.2.0pypypi✓ verified 30d ago

The `fixedint` library provides simple fixed-width integers in Python, allowing for both signed and unsigned types with configurable bit widths. It offers arithmetic and bitwise operations that mimic low-level hardware integer behavior, including silent wrap-around on overflow/underflow. The current version is 0.2.0, and it has a stable but low-cadence release cycle.

pip install fixedint
INSTALL
IMPORT
SIG · FIXEDINT
F
fixedint
serializationpythonv0.2.0
Install
1.6s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 17.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.006s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

UInt16
✓ from fixedint import UInt16
Int32
✓ from fixedint import Int32
UInt64
✓ from fixedint import UInt64
Commonly used types like UInt8, UInt16, Int32, Int64 are directly available.

This example demonstrates how to import and instantiate `UInt16` and `Int32` fixed-width integers, perform basic arithmetic and bitwise operations, and shows the overflow behavior and error handling for out-of-range initial values.

from fixedint import UInt16, Int32 # Unsigned 16-bit integer x = UInt16(65535) print(f"UInt16 max value: {x}") # Signed 32-bit integer y = Int32(-1) print(f"Int32 value: {y}") # Arithmetic operations (demonstrates wrap-around on overflow) a = UInt16(65530) b = UInt16(10) c = a + b # This will overflow UInt16 (65530 + 10 = 65540) print(f"65530 + 10 = {c} (wraps around)") # Expected: 4 # Bitwise operations g = UInt16(0b1010) h = UInt16(0b0101) i = g | h print(f"0b1010 | 0b0101 = {i}") # Expected: 0b1111 (15) try: # Instantiation with out-of-range value raises ValueError j = UInt16(70000) except ValueError as e: print(f"Error creating UInt16 with too large value: {e}")
Debug
Known issues
gotchaArithmetic operations (addition, subtraction, multiplication) on `fixedint` types silently wrap around on overflow or underflow, behaving like modulo arithmetic. This is by design but differs significantly from Python's default arbitrary-precision integer behavior.
fix
Be explicit about desired behavior: understand the wrapping, or implement custom overflow checks if error-raising is preferred. The result is always within the type's defined bit width.
affects: All versions (0.1.x, 0.2.x)
gotchaAttempting arithmetic operations between different `fixedint` types (e.g., `UInt16` and `Int32`) will raise a `TypeError`. Types must match for direct arithmetic.
fix
Explicitly cast or convert one of the operands to match the other type, or perform operations with standard Python integers before assigning the result to a `fixedint` type. For example, `UInt16(val1) + UInt16(val2)`.
affects: All versions (0.1.x, 0.2.x)
gotchaInitializing a `fixedint` type with a Python integer value that exceeds its defined bit width (or signed/unsigned range) will raise a `ValueError`.
fix
Ensure the initial value fits within the range of the chosen fixed-width integer type. For example, a `UInt16` cannot be initialized with a value greater than 65535 or less than 0.
affects: All versions (0.1.x, 0.2.x)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fixedint'
The `fixedint` library is not installed in the Python environment or the Python interpreter cannot find the installed package.
fix
Install the library using pip: `pip install fixedint`
ImportError: cannot import name 'FixedInt' from 'fixedint'
This error typically occurs when trying to import a class or function from the `fixedint` module with an incorrect name or casing, or if the specific class is not directly exposed for import (e.g., trying to import a dynamically generated type without using the factory function if applicable, though for fixedint, common types are directly importable like UInt32).
fix
Ensure the correct class names are used, matching the library's exposed types (e.g., `from fixedint import UInt32` or `from fixedint import FixedInt`). Refer to the `fixedint` documentation for available types.
TypeError: unsupported operand type(s) for +: 'FixedInt' and 'int'
This error arises when attempting to perform arithmetic operations between a `FixedInt` instance and a standard Python `int` (or another incompatible type) in a way that the `fixedint` library does not implicitly handle or when the operation results in a standard Python `int` or `float` where a `FixedInt` was expected, leading to subsequent type-sensitive operations failing. The library documentation notes that some operations like true division return a `float`, and `divmod` returns `plain int`s.
fix
Explicitly cast operands to compatible types where necessary, or be aware of operations that return standard Python types instead of `FixedInt`. For example, `UInt32(my_fixed_int + some_int)` or handle the `int`/`float` result accordingly.
AttributeError: 'FixedInt' object has no attribute 'some_method'
Users encounter this error when attempting to call a method or access an attribute on a `FixedInt` object that does not exist or is not part of its API, potentially confusing its behavior with that of a standard Python `int` or another custom class.
fix
Consult the `fixedint` library's documentation to confirm available methods and attributes for `FixedInt` instances. Ensure you are not trying to use methods specific to Python's built-in `int` that `FixedInt` does not implement.
fixedint unexpected value overflow
This is a common logical problem rather than a Python exception. It occurs when arithmetic operations on `FixedInt` instances exceed their defined bit width (e.g., 8, 16, 32, 64 bits), leading to silent wrap-around (truncation) rather than an explicit error. This results in an unexpected numerical value, mimicking low-level hardware integer behavior, which can be a source of hard-to-debug logical errors if not anticipated.
fix
Be mindful of the bit width and signed/unsigned nature of your `FixedInt` types. Before critical arithmetic operations, you can check if the value will exceed the range using comparison with `FixedInt.min_value` and `FixedInt.max_value` (if provided by the library, or calculate based on bit width) to handle potential overflow/underflow explicitly, or design your logic to correctly account for the wrap-around behavior.
Upgrade
Version history
0.2.0latest on PyPI · released Sep 16, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
fixedint — pip install fixedint · libregistry