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.1.tar.gz (21.8 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.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flexfloat-0.1.1.tar.gz
  • Upload date:
  • Size: 21.8 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.1.tar.gz
Algorithm Hash digest
SHA256 d5de08e29736f379afaf69a67021a8d1b246029edb31193aa0146572e20231a0
MD5 68b75cfac556879f7eeed0ca81a5ae2e
BLAKE2b-256 f0b49b73d4f2d819fdadcd48843262a60f44ceed9796eaae1fd1e32ce0b4821c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flexfloat-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4bf06b254e7c1f2f7b138748bcbe08b3ffdccaee97c4e323b1b471787a3c66
MD5 699e620cc60cf32e832548178f6eeac5
BLAKE2b-256 995ff6e2869d3e8ace4151d4fe47501481b510139584b623d5e727965d9d8230

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