# pyfxp > pyfxp is a bit-true fixed-point arithmetic library for Python. Values stay plain floats and NumPy arrays: fxp(x, Q(qi, qf, signed, rnd, ovf)) quantizes them to an ARM-style Q format (the sign bit counts in qi) with one of nine rounding modes and wrap / saturate / error on overflow. It is compiled with Numba and also works inside user @njit code. - Install: `pip install pyfxp`. Import: `from pyfxp import Q, fxp, fxpt, FxpSpec, to_int, from_int, to_hex`. - `Q(qi, qf, signed=True, rnd=TRUNC, ovf=WRAP)` builds an `FxpSpec`; `fxp(x, spec)` quantizes; `fxpt(x, qi, qf, signed, rnd, ovf)` does the same without a spec. - Q format is ARM style: `qi` includes the sign bit. `Q(1, 15)` is a 16-bit signed fraction in [-1, 1). - Results are floats / float64 arrays on the 2**-qf grid, not a custom type. Arrays of any shape work. - Complex inputs (`fxp`, `fxpt`): real and imaginary parts are quantized separately with the same spec and return complex / complex128. `to_int`, `to_bin`, `to_hex` reject complex: convert `z.real` and `z.imag`. - Modes live in `pyfxp.constants`: rounding `TRUNC, CEIL, TO_ZERO, AWAY, HALF_UP, HALF_DOWN, HALF_EVEN, HALF_ZERO, HALF_AWAY`; overflow `WRAP, SAT, ERROR`. They are IntEnums (`Rounding`, `Overflow`). - Widths up to 64 bits (signed) / 63 bits (unsigned). NaN propagates; +-inf saturates with SAT. - Bit growth: `a.add(b)`, `a.sub(b)`, `a.mul(b)`, `a.neg()`, `a.acc(n)` return the full-precision result format. - Raw integers for HDL: `to_int`, `from_int`, `to_bin`, `to_hex`, `from_bin`, `from_hex`. - Fast paths: call `fxp` on whole arrays, or call it per sample inside a Numba `@njit` function. Calling it per value from plain Python costs about 1 us per call. ## Docs - [pyfxp](https://pyfxp.readthedocs.io/en/stable/) - [Getting started](https://pyfxp.readthedocs.io/en/stable/getting-started/) - [Simple fixed-point integrator](https://pyfxp.readthedocs.io/en/stable/examples/example_int/) - [Comparison with other libraries](https://pyfxp.readthedocs.io/en/stable/comparison/) - [API Overview](https://pyfxp.readthedocs.io/en/stable/api/) - [fxp](https://pyfxp.readthedocs.io/en/stable/api/fxp/) - [fxpt](https://pyfxp.readthedocs.io/en/stable/api/fxpt/) - [Q](https://pyfxp.readthedocs.io/en/stable/api/Q/) - [FxpSpec](https://pyfxp.readthedocs.io/en/stable/api/FxpSpec/) - [Raw integers and test vectors](https://pyfxp.readthedocs.io/en/stable/api/raw/) - [Constants](https://pyfxp.readthedocs.io/en/stable/api/constants/) - [Precision of float results](https://pyfxp.readthedocs.io/en/stable/api/precision/) - [Public API and versioning](https://pyfxp.readthedocs.io/en/stable/api/stability/) - [CONTRIBUTING](https://pyfxp.readthedocs.io/en/stable/contributing/) - [Changelog](https://pyfxp.readthedocs.io/en/stable/changelog/) ## Optional - [Full documentation as one text file](https://pyfxp.readthedocs.io/en/stable/llms-full.txt)