Skip to content

PyPI Version Python Build Documentation Coverage Status python-versions semantic-versioning

Contributors PRs welcome Issues PRs open PRs done

Easy-to-use fixed-point library

qformatpy is a lightweight Python library for converting numbers to fixed-point format using the ARM-style Qm.n notation. It is designed to be simple, readable, and easy to integrate into simulation, modeling, or hardware verification pipelines.

The library provides a single function, qformat, that lets you control integer and fractional precision, signedness, rounding behavior, and overflow handling — all without the complexity of a full fixed-point arithmetic suite.

Whether you're developing embedded systems, DSP algorithms, or just need fast fixed-point conversion, qformatpy keeps things straightforward.

To get started, check the example of a fixed-point integrator implemented using the library.

Features

  • Support for Numba Optimized with optional Numba acceleration for fast, JIT-compiled conversions.

  • Native NumPy Array Support Seamlessly handles numpy.ndarray inputs for efficient batch processing.

  • Flexible Rounding Modes Choose from 9 rounding modes, including truncation, ceiling, rounding to nearest (with tie-breaking), and more.

  • Customizable Overflow Handling Select between wraparound, saturation, or error-on-overflow behavior.

  • Signed and Unsigned Formats Easily switch between signed and unsigned representations using the signed parameter.

  • Consistent Q-Format Notation Follows ARM-style Qm.n notation for compatibility with DSP and embedded tools.

  • Well-Suited for Embedded and DSP Simulation Ideal for preparing and validating fixed-point behavior before deploying to hardware.

Installation

Installing it is pretty easy:

pip install qformatpy