A Python library for Q format representation and overflow handling.
Project description
Introduction
Welcome to the qformat Python library, a powerful tool for formatting floating-point numbers into fixed-point representation with Q notation.
This library supports ARM’s Q format, where QI includes the sign bit.
The main function, qformat, allows users to specify the number of integer bits (QI), fractional bits (QF), whether the number is signed or unsigned, and provides flexibility in choosing rounding and overflow handling methods.
Whether you’re working on embedded systems, signal processing, or any application requiring fixed-point representation, qformat is here to streamline the process.
The example below shows pi being converter to the sQ4.8 format, using Truncation as the rounding method:
>>> from qformatpy import qformat
>>> x = 3.141592653589793
>>> result = qformat(x, qi=4, qf=8, rnd_method='Trunc')
>>> result
array([3.140625])
Installation
The qformatpy library is available via PIP install:
python3 -m venv pyenv
source pyenv/bin/activate
pip install qformatpy
Import the package as shown below:
import qformatpy
Example usage
>>> import numpy as np
>>> import qformatpy
>>> test_array = np.array([1.4, 5.57, 3.14])
>>> qformatpy.rounding(test_array, 'TowardsZero')
array([1, 5, 3])
>>> qformatpy.rounding(test_array, 'HalfDown')
array([1, 6, 3])
Links
Documentation: https://qformatpy.readthedocs.io/en/latest/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qformatpy-0.1.1.tar.gz
.
File metadata
- Download URL: qformatpy-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5af463683b3d71df77b4299e896e09bd32b6933986e86d7001d7710c631d2ba0 |
|
MD5 | 3522be5d56a9aa2370843137bbacde2d |
|
BLAKE2b-256 | e8c649faaaa090f99b10d8430f96c5b1d792fac079b7504883360082d35cef9a |
File details
Details for the file qformatpy-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: qformatpy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57a78f7d7c60a2944320eba97242d7bff32e44a52d67196058492ef31fb8c3a2 |
|
MD5 | 8da8ec295318a1e42dcf0a470f0117d6 |
|
BLAKE2b-256 | db36b71dd018e0ec70f95503c88b8dbc21988413a73736cfea0830babd4b85f8 |