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.2.tar.gz
(6.5 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.2.tar.gz.
File metadata
- Download URL: csignum_fast-1.0.2.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07b1054a31092827b5f81c6b992ce84a7d2adba338eb6eeaf5ab1e1516c03c6f
|
|
| MD5 |
b5d3bb05f26f43ab2813ad24f6285699
|
|
| BLAKE2b-256 |
1a37b89026446e13cc81fa78b079bfcd26d1257b03ce3edeaca745b488c04939
|
File details
Details for the file csignum_fast-1.0.2-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: csignum_fast-1.0.2-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 |
853d6e0ef121df22c76fad843a0cc3bfe098b6c2a72f3c77b49cc86d334beece
|
|
| MD5 |
230732484c9faad7e88fd794a42f6dc8
|
|
| BLAKE2b-256 |
2db96596c10316d421a1355f5f344bad01bb71809266145ca304d46dc55e74a0
|