Skip to main content

High-performance universal sign function

Project description

csignum-fast

Python Version License Status Tests PyPI Version

A robust, high-performance C++ implementation of the universal sign function for Python. Released on December 25, 2025 — The Christmas Edition.

Key Features

  1. Uniform Results: Always returns only -1, 0, or 1 as an int for valid numeric comparisons.
  2. Correct Edge Case Handling:
    • sign(+0.0) and sign(-0.0) return 0.
    • sign(inf) returns 1, sign(-inf) returns -1.
    • For any NaN (float NaN, Decimal NaN, etc.), it returns math.nan (float).
  3. Comprehensive Duck Typing: Delegates comparisons to the argument's class. Works seamlessly with:
    • Built-in int (including arbitrary-precision), bool, and float.
    • fractions.Fraction and decimal.Decimal.
    • Any existing and future objects that support rich comparisons with numbers.
  4. Informative Error Handling for Easy Debugging: Provides clear, descriptive TypeError messages when passed non-numeric, non-scalar, or incomparable arguments.
  5. High Performance: Implemented in C++ using a branchless ternary logic approach (no if-else chains), ensuring maximum execution speed.
  6. 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


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)

Uploaded Source

Built Distribution

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

csignum_fast-1.0.2-cp313-cp313-win_amd64.whl (9.1 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Hashes for csignum_fast-1.0.2.tar.gz
Algorithm Hash digest
SHA256 07b1054a31092827b5f81c6b992ce84a7d2adba338eb6eeaf5ab1e1516c03c6f
MD5 b5d3bb05f26f43ab2813ad24f6285699
BLAKE2b-256 1a37b89026446e13cc81fa78b079bfcd26d1257b03ce3edeaca745b488c04939

See more details on using hashes here.

File details

Details for the file csignum_fast-1.0.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for csignum_fast-1.0.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 853d6e0ef121df22c76fad843a0cc3bfe098b6c2a72f3c77b49cc86d334beece
MD5 230732484c9faad7e88fd794a42f6dc8
BLAKE2b-256 2db96596c10316d421a1355f5f344bad01bb71809266145ca304d46dc55e74a0

See more details on using hashes here.

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