Skip to main content

Add a short description here!

Project description

Project generated with PyScaffold ReadTheDocs codecov

🔄 csdigit

Canonical Signed Digit Conversion in Python

A Canonical Signed Digit (CSD) is a specific form of signed-digit representation of numbers. In the context of CSD, each digit is constrained to a value of -1, 0, or 1, and no two consecutive digits are permitted to be non-zero. This representation has the advantage of being unique and having a minimal number of non-zero digits. CSD is frequently employed in digital signal processing applications, such as filter design, due to its capacity for the efficient implementation of arithmetic operations through the use of straightforward adders and subtractors. The number of adders and subtracters necessary to implement a CSD coefficient is equal to the number of non-zero digits in the library, minus one.

The objective of this library is to facilitate the conversion of numbers between decimal format and a special representation known as Canonical Signed Digit (CSD). CSD is a method of representing numbers using a mere three symbols: The symbols "0," "+," and "-" are used. It is particularly advantageous in specific domains within computer science and digital signal processing.

The primary objective of this library is to provide the necessary functions for the conversion of decimal numbers to CSD format and vice versa. The library accepts decimal numbers in their standard form (e.g., 28.5 or -0.5) and converts them to CSD strings (e.g., "+00-00.+" or "0.-"). It is also capable of performing the inverse operation, transforming CSD strings into decimal numbers.

The library contains a number of functions, each with a specific role.

  1. to_csd: This function takes a decimal number and the number of decimal places desired, and outputs a CSD string. To illustrate, the function can be used to convert the decimal number 28.5 to the CSD string "+00-00.+0," with two decimal places.

  2. to_csd_i: This function is analogous to to_csd, but it is designed for use with integers. The function converts whole numbers to CSD format, omitting the decimal point.

  3. The functions to_decimal_using_pow and to_decimal perform the inverse of the to_csd function. They accept a CSD string as input and return a decimal number.

  4. The to_csdnnz function is a variant of the to_csd function that allows the user to specify the maximum number of non-zero digits in the result.

The library fulfills its intended function through a sequence of mathematical operations and logical tests. In order to effect a conversion from decimal to CSD, the system employs the use of powers of 2 in order to ascertain which of the three symbols (+, -, or 0) is to be used at each position within the CSD string. The algorithm then performs repeated divisions of the input number by two and compares the result to specific thresholds to determine the appropriate symbol to use.

In order to perform the conversion from CSD to decimal, the algorithm proceeds by multiplying the running total by 2 and then adding, subtracting, or performing no further action based on the value of the symbol in the CSD string. This is done for each symbol in the string, where the symbol values are +, -, or 0. A distinct logic is employed for the integral and fractional parts, respectively.

Furthermore, the library incorporates error-checking mechanisms to guarantee the exclusive utilisation of valid CSD symbols. It also furnishes comprehensive documentation and illustrative examples for each function, thus facilitating user comprehension of the operational procedures.

In conclusion, this library offers a comprehensive set of tools for working with CSD representations, facilitating the conversion between decimal and CSD formats in a variety of ways.

Used By

multiplierless

👀 See also

👉 Note

This project has been set up using PyScaffold 4.5. For details and usage information on PyScaffold see https://pyscaffold.org/.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csdigit-0.1.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csdigit-0.1-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file csdigit-0.1.tar.gz.

File metadata

  • Download URL: csdigit-0.1.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for csdigit-0.1.tar.gz
Algorithm Hash digest
SHA256 ae2dca8910a4c80eb4e7bebffd23f923ffb6f3a7720829fea9f22e49f5a8a6bb
MD5 0a3139dde1c3a4340cc2a9f7574e17d4
BLAKE2b-256 6d541950bdd1c6530803afb008516b389f65c5924f8b96ff28ab9bbd2a993efe

See more details on using hashes here.

Provenance

The following attestation bundles were made for csdigit-0.1.tar.gz:

Publisher: python-publish.yml on luk036/csdigit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file csdigit-0.1-py3-none-any.whl.

File metadata

  • Download URL: csdigit-0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for csdigit-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27184558db1c2661937d15b2e3750abff82eb37e26d280e1bdfd694f51799244
MD5 42606bf2132f578c82158316d1a04ae7
BLAKE2b-256 8da56230bdb6838cde31a6f53559acba2b323d8d13d657bd077d186404b3431a

See more details on using hashes here.

Provenance

The following attestation bundles were made for csdigit-0.1-py3-none-any.whl:

Publisher: python-publish.yml on luk036/csdigit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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