High-performance universal sign function
Project description
csignum-fast
A robust, high-performance C++ implementation of the universal sign function for Python. Released on December 25, 2025 — The Christmas Edition.
Key Features
- Uniform Results: Always returns only
-1,0, or1as anintfor valid numeric comparisons. - Correct Edge Case Handling:
sign(+0.0)andsign(-0.0)return0.sign(inf)returns1,sign(-inf)returns-1.- For any NaN (float NaN, Decimal NaN, etc.), it returns
math.nan(float).
- Comprehensive Duck Typing: Delegates comparisons to the argument's class. Works seamlessly with:
- Built-in
int(including arbitrary-precision),bool, andfloat. fractions.Fractionanddecimal.Decimal.- Any existing and future objects that support rich comparisons with numbers.
- Built-in
- Informative Error Handling for Easy Debugging: Provides clear, descriptive
TypeErrormessages when passed non-numeric, non-scalar, or incomparable arguments. - High Performance: Implemented in C++ using a branchless ternary logic approach (no
if-elsechains), ensuring maximum execution speed. - Thoroughly Tested: Tested on 51 cases including different types, edge cases, new custom class, and inappropriate arguments.
Installation
pip install csignum-fast
Usage
from signum import sign
from decimal import Decimal
print(sign(-10**100)) # -1
print(sign(3.14)) # 1
print(sign(Decimal("0.0"))) # 0
print(sign(float('-nan'))) # nan
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
csignum_fast-1.0.1.tar.gz
(7.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csignum_fast-1.0.1.tar.gz.
File metadata
- Download URL: csignum_fast-1.0.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b32e39deff6f028d3572dda9e53a67806cd3176c9a8fd553eb86228e069b5272
|
|
| MD5 |
e6ea727f56d9f87d50d3be18d96abcf8
|
|
| BLAKE2b-256 |
4c17df9a7ccd118555f2e914197e13d661ca82ec86b58eb16578379b61cfa961
|
File details
Details for the file csignum_fast-1.0.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: csignum_fast-1.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 9.1 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2516829deb49dc7a081f32faf8cbc4096baed9649385ba97dbafda9e8183225
|
|
| MD5 |
ec862bcb6ab53828156503bd6670df6a
|
|
| BLAKE2b-256 |
8beacba814dfff7cbebfdc0ca62ac3b785cfbc4f88c212c7c2841c6a60cd1359
|