{"id":21367,"library":"fxpmath","title":"fxpmath","description":"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.","status":"active","version":"0.4.10","language":"python","source_language":"en","source_url":"https://github.com/francof2a/fxpmath","tags":["fixed-point","arithmetic","binary","numpy","dsp","rounded","fractional"],"install":[{"cmd":"pip install fxpmath","lang":"bash","label":"Latest stable"}],"dependencies":[{"reason":"Core dependency for array operations and numerical precision.","package":"numpy","optional":false}],"imports":[{"note":"While that works, direct import is idiomatic.","wrong":"import fxpmath; fxpmath.Fxp","symbol":"Fxp","correct":"from fxpmath import Fxp"}],"quickstart":{"code":"from fxpmath import Fxp\n\nx = Fxp(0.5, signed=True, n_word=8, n_frac=7)\ny = Fxp(0.75, signed=True, n_word=8, n_frac=7)\nz = x + y\nprint(z)  # Returns 1.25\nprint(z.bin())  # Binary representation: 01.0100000\n","lang":"python","description":"Create two fixed-point numbers with 8-bit word length and 7 fractional bits, add them, and show the result."},"warnings":[{"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.","message":"Default 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.","severity":"gotcha","affected_versions":"<=0.4.10"},{"fix":"Set fxpmath.config.op_input_size = 'consistent' to require identical formats, or explicitly manage operand formats.","message":"Operations 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.","severity":"gotcha","affected_versions":"<=0.4.10"},{"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.","message":"In 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.","severity":"breaking","affected_versions":">=0.4.9"},{"fix":"Use `Fxp.from_bin(binary_string, ...)` for binary string input. Update to fxpmath >=0.4.9.","message":"The `from_bin` function was introduced in 0.4.9; older code using `Fxp(val, dtype=...)` with binary string might break or produce wrong results.","severity":"deprecated","affected_versions":"<0.4.9"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `Fxp.from_bin('01010110', ...)` which handles spaces and proper parsing.","cause":"Passing a binary string with spaces or invalid characters (e.g., '0101 0110') directly to Fxp().","error":"ValueError: invalid literal for int() with base 2: '...'"},{"fix":"Set `fxpmath.config.n_word_max = 128` (or required size) before creation.","cause":"Attempting to create an Fxp with a value that requires more than 64 bits without setting config.n_word_max.","error":"OverflowError: number of bits > n_word_max (64 bits) and no config to increase it"},{"fix":"Convert float to Fxp first: `float_val = Fxp(2.5, signed=True, n_word=8, n_frac=4)` then add.","cause":"Trying to add a Python float to an Fxp object without conversion.","error":"TypeError: unsupported operand type(s) for +: 'Fxp' and 'float'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}