Registry / ai-ml / fxpmath

fxpmath

JSON →
library0.4.10pypypi✓ verified 89d ago

A Python library for fractional fixed-point (base 2) arithmetic and binary manipulation with NumPy compatibility. Current version 0.4.10 (latest stable), released roughly every few months. Supports Python >=3.7. Widely used in digital signal processing and hardware emulation contexts.

pip install fxpmath
INSTALL
IMPORT
SIG · FXPMATH
F
fxpmath
ai-mlpythonv0.4.10
Install
3.5s avg
Import
243ms
Disk
89MB
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.4.10 · 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.236s · 89.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.5s · import 0.250s · 86MB
89MB installed
● package 89MB
Code
Verified usage

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

Fxp
✓ from fxpmath import Fxp
✗ import fxpmath; fxpmath.Fxp
While that works, direct import is idiomatic.

Create two fixed-point numbers with 8-bit word length and 7 fractional bits, add them, and show the result.

from fxpmath import Fxp x = Fxp(0.5, signed=True, n_word=8, n_frac=7) y = Fxp(0.75, signed=True, n_word=8, n_frac=7) z = x + y print(z) # Returns 1.25 print(z.bin()) # Binary representation: 01.0100000
Debug
Known issues
gotchaDefault word length overflow wraps silently without warning unless you set config.rounding or check the overflow flag explicitly. Always specify signed, n_word, n_frac to avoid unexpected bits.
fix
Always pass explicit fixed-point format arguments: Fxp(value, signed=True, n_word=16, n_frac=8). Use config.overflow='wrap' or 'saturate' to control behavior.
affects: <=0.4.10
gotchaOperations between Fxp objects with different formats may silently coerce to larger word lengths if config.op_input_size is not set to 'consistent' or 'best'. This can lead to unexpected bit growth.
fix
Set fxpmath.config.op_input_size = 'consistent' to require identical formats, or explicitly manage operand formats.
affects: <=0.4.10
breakingIn v0.4.9, the behavior of the wrap function changed for values exceeding n_word_max (64 bits). Previously it might have truncated; now it raises an error or wraps differently. This can break code that relied on raw binary manipulation beyond 64 bits.
fix
Set config.n_word_max to a higher value if you need >64 bits, or use the `Fxp` constructor with explicit word lengths rather than relying on wrap. Check the wrap utility documentation.
affects: >=0.4.9
deprecatedThe `from_bin` function was introduced in 0.4.9; older code using `Fxp(val, dtype=...)` with binary string might break or produce wrong results.
fix
Use `Fxp.from_bin(binary_string, ...)` for binary string input. Update to fxpmath >=0.4.9.
affects: <0.4.9
Errors
Common errors & fixes
ValueError: invalid literal for int() with base 2: '...'
Passing a binary string with spaces or invalid characters (e.g., '0101 0110') directly to Fxp().
fix
Use `Fxp.from_bin('01010110', ...)` which handles spaces and proper parsing.
OverflowError: number of bits > n_word_max (64 bits) and no config to increase it
Attempting to create an Fxp with a value that requires more than 64 bits without setting config.n_word_max.
fix
Set `fxpmath.config.n_word_max = 128` (or required size) before creation.
TypeError: unsupported operand type(s) for +: 'Fxp' and 'float'
Trying to add a Python float to an Fxp object without conversion.
fix
Convert float to Fxp first: `float_val = Fxp(2.5, signed=True, n_word=8, n_frac=4)` then add.
Upgrade
Version history
0.4.10latest on PyPI · released Mar 24, 2026
Audit
Dependencies
numpyrequiredCore dependency for array operations and numerical precision.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
fxpmath — pip install fxpmath · libregistry