Skip to main content

High-performance universal sign function

Project description

csignum-fast

Python Version License Status Tests

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.0.tar.gz (7.0 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.0-cp313-cp313-win_amd64.whl (9.0 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file csignum_fast-1.0.0.tar.gz.

File metadata

  • Download URL: csignum_fast-1.0.0.tar.gz
  • Upload date:
  • Size: 7.0 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.0.tar.gz
Algorithm Hash digest
SHA256 ae76958be2cef77840922592256263e21a6112d67ecee2edb34ed715def493d3
MD5 2eb4bfec4a3bbfa04c3d4ee93e962b2e
BLAKE2b-256 e3641d708708d9881ac432e397d13268ff40f64a0015ac181224dee27304cb81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for csignum_fast-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 88ada08e2e9fabe1ec67628af7aff95d5a1ea35d4ff279b0cfc3d77829736cb5
MD5 392e13d5b87343c0638b99a305ac428d
BLAKE2b-256 c4343f1e6d618191c3b7d4a60e2b48a48903ee1d12011f0a540d1b0a3928a5fc

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