Skip to main content

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.

  5. The to_csdnnz_i function is a variant of the to_csd_i 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/.

Metadata

Release files for csdigit 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csdigit 0.6
File Size Uploaded Provenance Actions
csdigit-0.6.tar.gz 683.5 kB With provenance Details for csdigit-0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for csdigit 0.6
File Interpreter ABI Platform Actions
csdigit-0.6-py3-none-any.whl Python 3 none any Details for csdigit-0.6-py3-none-any.whl

Total release size: 712.4 kB

Release files / csdigit-0.6.tar.gz

Download URL csdigit-0.6.tar.gz
Size 683.5 kB
Tags Source
SHA-256 checksum
How to use checksums
93067d1ff53fc4cca165cee7e1dc3c300ad39fdad55d69673b51121075ee88e3
BLAKE2b-256 checksum
How to use checksums
afa8ad52f950dc25db958600d1744e1bcf81fa2873a4a829ba16952a6792f218
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / csdigit-0.6-py3-none-any.whl

Download URL csdigit-0.6-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2baf4fc9793b25bbad615cafb00681ccc1e8bb264c9203389533d0136461a36
BLAKE2b-256 checksum
How to use checksums
e172ec122b58f1e7bd479a126954ce87be9b45bd91d5bd5082b8549ab95677fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for csdigit 0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for csdigit-0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page