Skip to main content

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])

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

qformatpy-0.1.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

qformatpy-0.1.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file qformatpy-0.1.2.tar.gz.

File metadata

  • Download URL: qformatpy-0.1.2.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for qformatpy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f9ef7252b027d4b77b071a8c69253837254a700b67617f0bf1bf5b1211f57690
MD5 27b8dc0ec9b71bfc73d591c7cc664586
BLAKE2b-256 542ddfd17a4b3202cf4ef20bc59f4d99f9726ae38211a2e68a925820fe7fd0b1

See more details on using hashes here.

File details

Details for the file qformatpy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: qformatpy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for qformatpy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 56261b583b24c5e597e21a257ae6f9f6237649178dea56fce6cffc0f14a89e8f
MD5 ad39200d000647bd8f2ae3c3ca6ce379
BLAKE2b-256 211a0d5339a3b0d74c7fe23f280fdb4c4ef3ecc212ff0d0c4f150a7dbdb7c029

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page