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.1.tar.gz (7.2 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.1-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.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

Hashes for csignum_fast-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b32e39deff6f028d3572dda9e53a67806cd3176c9a8fd553eb86228e069b5272
MD5 e6ea727f56d9f87d50d3be18d96abcf8
BLAKE2b-256 4c17df9a7ccd118555f2e914197e13d661ca82ec86b58eb16578379b61cfa961

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for csignum_fast-1.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c2516829deb49dc7a081f32faf8cbc4096baed9649385ba97dbafda9e8183225
MD5 ec862bcb6ab53828156503bd6670df6a
BLAKE2b-256 8beacba814dfff7cbebfdc0ca62ac3b785cfbc4f88c212c7c2841c6a60cd1359

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