Skip to main content

A library for arbitrary precision floating point arithmetic

Project description

FlexFloat

A Python library for arbitrary precision floating point arithmetic with a flexible exponent and fixed-size fraction.

Features

  • Growable Exponents: Handle very large or very small numbers by dynamically adjusting the exponent size
  • Fixed-Size Fractions: Maintain precision consistency with IEEE 754-compatible 52-bit fractions
  • IEEE 754 Compatibility: Follows IEEE 754 double-precision format as the baseline
  • Special Value Support: Handles NaN, positive/negative infinity, and zero values
  • Arithmetic Operations: Addition and subtraction with proper overflow/underflow handling

Installation

pip install flexfloat

Development Installation

pip install -e ".[dev]"

Usage

from flexfloat import FlexFloat

# Create FlexFloat instances
a = FlexFloat.from_float(1.5)
b = FlexFloat.from_float(2.5)

# Perform arithmetic operations
result = a + b
print(result.to_float())  # 4.0

# Handle very large numbers
large_a = FlexFloat.from_float(1e308)
large_b = FlexFloat.from_float(1e308)
large_result = large_a + large_b
# Result has grown exponent to handle overflow
print(len(large_result.exponent))  # > 11 (grows beyond IEEE 754 standard)

Running Tests

python -m pytest tests

License

MIT License

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

flexfloat-0.1.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

flexfloat-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file flexfloat-0.1.0.tar.gz.

File metadata

  • Download URL: flexfloat-0.1.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for flexfloat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9b61405b4df94f62baace9b7d0b8b6241eb38670592eb1e0807518bbd6239d31
MD5 9f835fc38acd36ae50d51cdabf8236fe
BLAKE2b-256 3b25812712a9daaa336c08b3606d5c12c0f6b501b5e986fd83bf0cc48b719569

See more details on using hashes here.

File details

Details for the file flexfloat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flexfloat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for flexfloat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5506846c2594596a3cdb7aba37c801667fa41a40df85c3ff4aad828177b3154f
MD5 e0945d6feb66d52d0302437f2dbcee2c
BLAKE2b-256 e4c48d8f1da588341b8e5726b5e1fbdb8b2d9de1473afb6d1da63135044eb797

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