flexfloat 0.4.0__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.bumpversion.cfg +1 -1
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/manual-release.yml +18 -6
- flexfloat-1.0.0/CHANGELOG.md +69 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/MANIFEST.in +1 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/PKG-INFO +182 -52
- {flexfloat-0.4.0 → flexfloat-1.0.0}/README.md +177 -49
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/conf.py +3 -7
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/index.rst +59 -13
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/installation.rst +21 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/quickstart.rst +55 -16
- flexfloat-1.0.0/flexfloat/__init__.py +51 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/core.py +198 -20
- flexfloat-1.0.0/flexfloat/math/__init__.py +145 -0
- flexfloat-1.0.0/flexfloat/math/constants.py +61 -0
- flexfloat-1.0.0/flexfloat/math/exponential.py +176 -0
- flexfloat-1.0.0/flexfloat/math/floating_point.py +107 -0
- flexfloat-1.0.0/flexfloat/math/hyperbolic.py +266 -0
- flexfloat-1.0.0/flexfloat/math/logarithmic.py +222 -0
- flexfloat-1.0.0/flexfloat/math/sqrt.py +261 -0
- flexfloat-1.0.0/flexfloat/math/trigonometric.py +680 -0
- flexfloat-1.0.0/flexfloat/math/utility.py +1163 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat.egg-info/PKG-INFO +182 -52
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat.egg-info/SOURCES.txt +20 -3
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat.egg-info/requires.txt +1 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/pyproject.toml +8 -3
- flexfloat-1.0.0/tests/math/__init__.py +165 -0
- flexfloat-1.0.0/tests/math/test_exponential.py +242 -0
- flexfloat-1.0.0/tests/math/test_floating_point.py +214 -0
- flexfloat-1.0.0/tests/math/test_hyperbolic.py +360 -0
- flexfloat-1.0.0/tests/math/test_logarithmic.py +149 -0
- flexfloat-1.0.0/tests/math/test_sqrt.py +122 -0
- flexfloat-1.0.0/tests/math/test_trigonometric.py +645 -0
- flexfloat-1.0.0/tests/math/test_utility.py +660 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_bigint_bitarray.py +2 -3
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_bitarray.py +5 -7
- flexfloat-1.0.0/tests/test_conversions.py +323 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_subtraction.py +1 -3
- flexfloat-1.0.0/tests/test_to_int.py +254 -0
- flexfloat-0.4.0/flexfloat/__init__.py +0 -38
- flexfloat-0.4.0/flexfloat/math.py +0 -1088
- flexfloat-0.4.0/tests/test_conversions.py +0 -119
- flexfloat-0.4.0/tests/test_math.py +0 -1207
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/build-check.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/docs.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/pr-labeler.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/release.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/test.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/version-bump.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.github/workflows/version-check.yml +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/.gitignore +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/LICENSE +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/Makefile +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/README.md +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/make.bat +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_autosummary/flexfloat.BigIntBitArray.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_autosummary/flexfloat.BitArray.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_autosummary/flexfloat.FlexFloat.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_autosummary/flexfloat.ListBoolBitArray.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_autosummary/flexfloat.ListInt64BitArray.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_autosummary/flexfloat.math.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_static/custom.css +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_templates/autosummary/class.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/_templates/layout.html +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/api/bitarray.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/api/core.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/api/math.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/api/types.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/examples/index.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/user_guide/concepts.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/docs/source/user_guide/index.rst +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/bitarray/__init__.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/bitarray/bitarray.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/bitarray/bitarray_bigint.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/bitarray/bitarray_bool.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/bitarray/bitarray_int64.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/bitarray/bitarray_mixins.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/py.typed +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat/types.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat.egg-info/dependency_links.txt +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/flexfloat.egg-info/top_level.txt +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/scripts/validate_cicd.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/scripts/version_manager.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/setup.cfg +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/setup.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/__init__.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_addition.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_bitarray_implementations.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_comparison.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_division.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_flexfloat.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_multiplication.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_power.py +0 -0
- {flexfloat-0.4.0 → flexfloat-1.0.0}/tests/test_str_representation.py +0 -0
|
@@ -3,6 +3,11 @@ name: Manual Release
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
5
5
|
inputs:
|
|
6
|
+
skip_version_bump:
|
|
7
|
+
description: "Skip version bump and release with current version"
|
|
8
|
+
required: false
|
|
9
|
+
default: false
|
|
10
|
+
type: boolean
|
|
6
11
|
version_bump:
|
|
7
12
|
description: "Version bump type"
|
|
8
13
|
required: true
|
|
@@ -70,19 +75,25 @@ jobs:
|
|
|
70
75
|
- name: Bump or set version
|
|
71
76
|
id: bump_version
|
|
72
77
|
run: |
|
|
73
|
-
if [
|
|
78
|
+
if [ "${{ github.event.inputs.skip_version_bump }}" = "true" ]; then
|
|
79
|
+
# Skip version bump, use current version
|
|
80
|
+
CURRENT_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
|
81
|
+
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
82
|
+
echo "Skipping version bump, using current version: $CURRENT_VERSION"
|
|
83
|
+
elif [ -n "${{ steps.set_new_version.outputs.new_version }}" ]; then
|
|
74
84
|
# Set version directly
|
|
75
85
|
bump2version --new-version ${{ steps.set_new_version.outputs.new_version }} patch
|
|
86
|
+
NEW_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
|
87
|
+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
88
|
+
echo "New version: $NEW_VERSION"
|
|
76
89
|
else
|
|
77
90
|
# Bump version as per input
|
|
78
91
|
bump2version ${{ github.event.inputs.version_bump }}
|
|
92
|
+
NEW_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
|
93
|
+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
94
|
+
echo "New version: $NEW_VERSION"
|
|
79
95
|
fi
|
|
80
96
|
|
|
81
|
-
# Get new version
|
|
82
|
-
NEW_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
|
83
|
-
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
84
|
-
echo "New version: $NEW_VERSION"
|
|
85
|
-
|
|
86
97
|
- name: Run tests
|
|
87
98
|
run: |
|
|
88
99
|
pip install -e ".[dev]"
|
|
@@ -93,6 +104,7 @@ jobs:
|
|
|
93
104
|
python -m build
|
|
94
105
|
|
|
95
106
|
- name: Commit version bump
|
|
107
|
+
if: ${{ github.event.inputs.skip_version_bump != 'true' }}
|
|
96
108
|
run: |
|
|
97
109
|
git add pyproject.toml flexfloat/__init__.py .bumpversion.cfg
|
|
98
110
|
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }} [skip ci]"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to FlexFloat will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2025-08-03
|
|
6
|
+
|
|
7
|
+
### 🎉 First Stable Release
|
|
8
|
+
|
|
9
|
+
FlexFloat 1.0.0 marks the first stable release with a complete implementation of arbitrary precision floating-point arithmetic and a comprehensive mathematical function library.
|
|
10
|
+
|
|
11
|
+
### ✨ Features
|
|
12
|
+
|
|
13
|
+
#### Core Arithmetic
|
|
14
|
+
- ✅ Full arithmetic operations: addition, subtraction, multiplication, division, power
|
|
15
|
+
- ✅ IEEE 754 compatible special value handling (NaN, ±infinity, zero)
|
|
16
|
+
- ✅ Growable exponents for handling extremely large/small numbers
|
|
17
|
+
- ✅ Fixed 52-bit fraction precision for consistency
|
|
18
|
+
- ✅ Multiple BitArray backend implementations for performance optimization
|
|
19
|
+
|
|
20
|
+
#### Complete Mathematical Function Library
|
|
21
|
+
- ✅ **Trigonometric functions**: `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`
|
|
22
|
+
- ✅ **Exponential functions**: `exp`, `expm1`, `pow`
|
|
23
|
+
- ✅ **Logarithmic functions**: `log`, `log10`, `log2`, `log1p`
|
|
24
|
+
- ✅ **Hyperbolic functions**: `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`
|
|
25
|
+
- ✅ **Square root functions**: `sqrt`, `cbrt`
|
|
26
|
+
- ✅ **Mathematical constants**: `pi`, `e`, `tau`, `inf`, `nan`
|
|
27
|
+
- ✅ **Utility functions**: `ceil`, `floor`, `fabs`, `fmod`, `copysign`, and more
|
|
28
|
+
|
|
29
|
+
#### BitArray Implementations
|
|
30
|
+
- ✅ `ListBoolBitArray`: Simple bool-list implementation for debugging
|
|
31
|
+
- ✅ `ListInt64BitArray`: Optimized int64-list implementation for performance
|
|
32
|
+
- ✅ `BigIntBitArray`: Python int-based implementation for maximum flexibility
|
|
33
|
+
|
|
34
|
+
#### API and Usability
|
|
35
|
+
- ✅ Pythonic interface with natural mathematical syntax
|
|
36
|
+
- ✅ Comprehensive type hints and documentation
|
|
37
|
+
- ✅ Full test coverage with extensive edge case testing
|
|
38
|
+
- ✅ Clear error handling and special case behavior
|
|
39
|
+
|
|
40
|
+
### 📊 Technical Details
|
|
41
|
+
|
|
42
|
+
- **Precision**: IEEE 754 compatible 52-bit fraction precision
|
|
43
|
+
- **Range**: Dynamically growable exponents prevent overflow/underflow
|
|
44
|
+
- **Performance**: Multiple backend implementations for different use cases
|
|
45
|
+
- **Compatibility**: Python 3.11+ support
|
|
46
|
+
|
|
47
|
+
### 📚 Documentation
|
|
48
|
+
|
|
49
|
+
- ✅ Complete API documentation
|
|
50
|
+
- ✅ User guide with examples
|
|
51
|
+
- ✅ Mathematical function reference
|
|
52
|
+
- ✅ Performance optimization guide
|
|
53
|
+
|
|
54
|
+
### 🧪 Testing
|
|
55
|
+
|
|
56
|
+
- ✅ Comprehensive test suite with >95% code coverage
|
|
57
|
+
- ✅ Mathematical function accuracy verified against Python's `math` module
|
|
58
|
+
- ✅ Edge case testing for special values (NaN, infinity, zero)
|
|
59
|
+
- ✅ Extreme value testing for very large/small numbers
|
|
60
|
+
|
|
61
|
+
### 🏗️ Architecture
|
|
62
|
+
|
|
63
|
+
The library is built with a modular architecture:
|
|
64
|
+
- `flexfloat.core`: Main FlexFloat class and arithmetic operations
|
|
65
|
+
- `flexfloat.math`: Complete mathematical function library
|
|
66
|
+
- `flexfloat.bitarray`: Multiple BitArray backend implementations
|
|
67
|
+
- `flexfloat.types`: Type definitions and protocols
|
|
68
|
+
|
|
69
|
+
This release represents a production-ready library suitable for scientific computing, financial calculations, and any application requiring high-precision floating-point arithmetic beyond the limitations of standard IEEE 754 double precision.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexfloat
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A library for arbitrary precision floating
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A high-precision Python library for arbitrary precision floating-point arithmetic with growable exponents and fixed-size fractions
|
|
5
5
|
Author: Ferran Sanchez Llado
|
|
6
6
|
License: MIT
|
|
7
|
-
Classifier: Development Status ::
|
|
7
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
8
8
|
Classifier: Intended Audience :: Developers
|
|
9
9
|
Classifier: Intended Audience :: Science/Research
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -12,6 +12,7 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
16
|
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
17
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
18
|
Requires-Python: >=3.11
|
|
@@ -20,6 +21,7 @@ License-File: LICENSE
|
|
|
20
21
|
Provides-Extra: dev
|
|
21
22
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
22
23
|
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-xdist>=3.0; extra == "dev"
|
|
23
25
|
Requires-Dist: black>=23.0; extra == "dev"
|
|
24
26
|
Requires-Dist: isort>=5.0; extra == "dev"
|
|
25
27
|
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
@@ -39,7 +41,7 @@ Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "docs"
|
|
|
39
41
|
Requires-Dist: requests>=2.25.0; extra == "docs"
|
|
40
42
|
Dynamic: license-file
|
|
41
43
|
|
|
42
|
-
# FlexFloat
|
|
44
|
+
# FlexFloat 1.0.0
|
|
43
45
|
|
|
44
46
|
[](https://www.python.org/downloads/)
|
|
45
47
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -50,8 +52,9 @@ A high-precision Python library for arbitrary precision floating-point arithmeti
|
|
|
50
52
|
## ✨ Key Features
|
|
51
53
|
|
|
52
54
|
- **🔢 Growable Exponents**: Dynamically expand exponent size to handle extremely large (>10^308) or small (<10^-308) numbers
|
|
53
|
-
- **🎯 Fixed-Size Fractions**: Maintain IEEE 754-compatible 52-bit fraction precision for consistent accuracy
|
|
55
|
+
- **🎯 Fixed-Size Fractions**: Maintain IEEE 754-compatible 52-bit fraction precision for consistent accuracy
|
|
54
56
|
- **⚡ Full Arithmetic Support**: Addition, subtraction, multiplication, division, and power operations
|
|
57
|
+
- **📐 Complete Math Library**: Comprehensive mathematical functions including trigonometric, logarithmic, exponential, and hyperbolic functions
|
|
55
58
|
- **🔧 Multiple BitArray Backends**: Choose between bool-list, int64-list, and big-integer implementations for optimal performance
|
|
56
59
|
- **🌟 Special Value Handling**: Complete support for NaN, ±infinity, and zero values
|
|
57
60
|
- **🛡️ Overflow Protection**: Automatic exponent growth prevents overflow/underflow errors
|
|
@@ -88,38 +91,45 @@ print(f"Exponent bits: {len(large_result.exponent)}") # > 11 (grown beyond IEEE
|
|
|
88
91
|
print(f"Can represent: {large_result}") # No overflow!
|
|
89
92
|
```
|
|
90
93
|
|
|
91
|
-
### Advanced
|
|
94
|
+
### Advanced Mathematical Functions
|
|
92
95
|
|
|
93
96
|
```python
|
|
94
|
-
from flexfloat import FlexFloat
|
|
95
|
-
|
|
96
|
-
# Use different BitArray implementations for specific needs
|
|
97
|
-
FlexFloat.set_bitarray_implementation(BigIntBitArray)
|
|
97
|
+
from flexfloat import FlexFloat
|
|
98
|
+
from flexfloat.math import sin, cos, log, exp, sqrt, sinh, cosh
|
|
98
99
|
|
|
99
|
-
#
|
|
100
|
+
# Create FlexFloat instances
|
|
100
101
|
x = FlexFloat.from_float(2.0)
|
|
101
102
|
y = FlexFloat.from_float(3.0)
|
|
102
103
|
|
|
103
|
-
#
|
|
104
|
+
# Trigonometric functions
|
|
105
|
+
angle = FlexFloat.from_float(1.5708) # π/2 radians
|
|
106
|
+
sin_result = sin(angle)
|
|
107
|
+
cos_result = cos(angle)
|
|
108
|
+
print(f"sin(π/2) = {sin_result.to_float()}") # ≈ 1.0
|
|
109
|
+
print(f"cos(π/2) = {cos_result.to_float()}") # ≈ 0.0
|
|
110
|
+
|
|
111
|
+
# Logarithmic and exponential functions
|
|
112
|
+
log_result = log(x) # Natural logarithm
|
|
113
|
+
exp_result = exp(x) # e^x
|
|
114
|
+
sqrt_result = sqrt(x) # √x
|
|
115
|
+
print(f"ln(2) = {log_result.to_float()}")
|
|
116
|
+
print(f"e^2 = {exp_result.to_float()}")
|
|
117
|
+
print(f"√2 = {sqrt_result.to_float()}")
|
|
118
|
+
|
|
119
|
+
# Hyperbolic functions
|
|
120
|
+
sinh_result = sinh(x)
|
|
121
|
+
cosh_result = cosh(x)
|
|
122
|
+
print(f"sinh(2) = {sinh_result.to_float()}")
|
|
123
|
+
print(f"cosh(2) = {cosh_result.to_float()}")
|
|
124
|
+
|
|
125
|
+
# Power operations with extreme precision
|
|
104
126
|
power_result = x ** y # 2^3 = 8
|
|
105
|
-
print(power_result.to_float())
|
|
127
|
+
print(f"2^3 = {power_result.to_float()}")
|
|
106
128
|
|
|
107
|
-
#
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
# Absolute value operations
|
|
112
|
-
abs_result = abs(FlexFloat.from_float(-42.0))
|
|
113
|
-
print(f"|-42| = {abs_result.to_float()}") # 42.0
|
|
114
|
-
|
|
115
|
-
# Working with extreme values
|
|
116
|
-
huge = FlexFloat.from_float(1e300)
|
|
117
|
-
extreme_product = huge * huge
|
|
118
|
-
print(f"Product: {extreme_product.to_float()}") # Still computable!
|
|
119
|
-
|
|
120
|
-
# Precision demonstration
|
|
121
|
-
precise_calc = FlexFloat.from_float(1.0) / FlexFloat.from_float(3.0)
|
|
122
|
-
print(f"1/3 with 52-bit precision: {precise_calc}")
|
|
129
|
+
# Working with mathematical constants
|
|
130
|
+
from flexfloat.math import pi, e
|
|
131
|
+
circle_area = pi * (x ** FlexFloat.from_float(2.0)) # π * r²
|
|
132
|
+
print(f"Area of circle with radius 2: {circle_area.to_float()}")
|
|
123
133
|
```
|
|
124
134
|
|
|
125
135
|
## 🔧 BitArray Backends
|
|
@@ -166,21 +176,71 @@ bigint_array = BigIntBitArray.from_bits(bits)
|
|
|
166
176
|
```python
|
|
167
177
|
# Construction
|
|
168
178
|
FlexFloat.from_float(value: float) -> FlexFloat
|
|
179
|
+
FlexFloat.from_int(value: int) -> FlexFloat
|
|
169
180
|
FlexFloat(sign: bool, exponent: BitArray, fraction: BitArray)
|
|
170
181
|
|
|
171
182
|
# Conversion
|
|
172
183
|
flexfloat.to_float() -> float
|
|
184
|
+
flexfloat.to_int() -> int
|
|
173
185
|
|
|
174
|
-
# Arithmetic
|
|
186
|
+
# Arithmetic Operations
|
|
175
187
|
a + b, a - b, a * b, a / b, a ** b
|
|
176
188
|
abs(a), -a
|
|
177
189
|
|
|
178
|
-
#
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
190
|
+
# Comparison Operations
|
|
191
|
+
a == b, a != b, a < b, a <= b, a > b, a >= b
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Mathematical Functions
|
|
195
|
+
|
|
196
|
+
FlexFloat provides a comprehensive math library similar to Python's `math` module:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from flexfloat.math import *
|
|
200
|
+
|
|
201
|
+
# Exponential and Power Functions
|
|
202
|
+
exp(x) # e^x
|
|
203
|
+
expm1(x) # exp(x) - 1 (accurate for small x)
|
|
204
|
+
pow(x, y) # x^y
|
|
205
|
+
|
|
206
|
+
# Logarithmic Functions
|
|
207
|
+
log(x) # Natural logarithm (base e)
|
|
208
|
+
log10(x) # Base-10 logarithm
|
|
209
|
+
log2(x) # Base-2 logarithm
|
|
210
|
+
log1p(x) # log(1 + x) (accurate for small x)
|
|
211
|
+
|
|
212
|
+
# Trigonometric Functions
|
|
213
|
+
sin(x), cos(x), tan(x) # Basic trig functions
|
|
214
|
+
asin(x), acos(x), atan(x) # Inverse trig functions
|
|
215
|
+
atan2(y, x) # Two-argument arctangent
|
|
216
|
+
degrees(x), radians(x) # Angle conversion
|
|
217
|
+
|
|
218
|
+
# Hyperbolic Functions
|
|
219
|
+
sinh(x), cosh(x), tanh(x) # Hyperbolic functions
|
|
220
|
+
asinh(x), acosh(x), atanh(x) # Inverse hyperbolic functions
|
|
221
|
+
|
|
222
|
+
# Square Root Functions
|
|
223
|
+
sqrt(x) # Square root
|
|
224
|
+
cbrt(x) # Cube root
|
|
225
|
+
|
|
226
|
+
# Mathematical Constants
|
|
227
|
+
pi, e, tau # π, Euler's number, τ (2π)
|
|
228
|
+
inf, nan # Positive infinity, Not a Number
|
|
229
|
+
|
|
230
|
+
# Utility Functions
|
|
231
|
+
ceil(x), floor(x) # Ceiling and floor
|
|
232
|
+
fmod(x, y) # Floating-point remainder
|
|
233
|
+
fabs(x) # Absolute value
|
|
234
|
+
copysign(x, y) # Copy sign from y to x
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### BitArray Configuration
|
|
182
238
|
|
|
183
|
-
|
|
239
|
+
```python
|
|
240
|
+
from flexfloat import FlexFloat
|
|
241
|
+
from flexfloat.math import sin, cos, pi
|
|
242
|
+
|
|
243
|
+
# Configure FlexFloat to use a specific BitArray implementation
|
|
184
244
|
FlexFloat.set_bitarray_implementation(implementation: Type[BitArray])
|
|
185
245
|
```
|
|
186
246
|
|
|
@@ -192,7 +252,7 @@ from flexfloat import FlexFloat
|
|
|
192
252
|
# Create special values
|
|
193
253
|
nan_val = FlexFloat.nan()
|
|
194
254
|
inf_val = FlexFloat.infinity()
|
|
195
|
-
neg_inf = FlexFloat.negative_infinity()
|
|
255
|
+
neg_inf = FlexFloat.negative_infinity()
|
|
196
256
|
zero_val = FlexFloat.zero()
|
|
197
257
|
|
|
198
258
|
# Check for special values
|
|
@@ -200,6 +260,8 @@ if result.is_nan():
|
|
|
200
260
|
print("Result is Not a Number")
|
|
201
261
|
if result.is_infinite():
|
|
202
262
|
print("Result is infinite")
|
|
263
|
+
if result.is_zero():
|
|
264
|
+
print("Result is zero")
|
|
203
265
|
```
|
|
204
266
|
|
|
205
267
|
## 🧪 Development & Testing
|
|
@@ -248,10 +310,19 @@ flake8 flexfloat/
|
|
|
248
310
|
|
|
249
311
|
### Scientific Computing
|
|
250
312
|
```python
|
|
251
|
-
# Handle calculations that would overflow standard floats
|
|
252
313
|
from flexfloat import FlexFloat
|
|
314
|
+
from flexfloat.math import sin, cos, pi, exp, log
|
|
315
|
+
|
|
316
|
+
# High-precision trigonometric calculations
|
|
317
|
+
def calculate_wave_interference(amplitude, frequency, time):
|
|
318
|
+
ff_amp = FlexFloat.from_float(amplitude)
|
|
319
|
+
ff_freq = FlexFloat.from_float(frequency)
|
|
320
|
+
ff_time = FlexFloat.from_float(time)
|
|
321
|
+
|
|
322
|
+
wave = ff_amp * sin(ff_freq * ff_time * pi)
|
|
323
|
+
return wave
|
|
253
324
|
|
|
254
|
-
#
|
|
325
|
+
# Handle calculations that would overflow standard floats
|
|
255
326
|
def flex_factorial(n):
|
|
256
327
|
result = FlexFloat.from_float(1.0)
|
|
257
328
|
for i in range(1, n + 1):
|
|
@@ -263,23 +334,53 @@ large_factorial = flex_factorial(1000) # No overflow!
|
|
|
263
334
|
|
|
264
335
|
### Financial Calculations
|
|
265
336
|
```python
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
rate = FlexFloat.from_float(1.05) # 5% annual return
|
|
269
|
-
years = FlexFloat.from_float(100)
|
|
337
|
+
from flexfloat import FlexFloat
|
|
338
|
+
from flexfloat.math import log, exp
|
|
270
339
|
|
|
271
|
-
#
|
|
272
|
-
|
|
340
|
+
# High-precision compound interest calculations
|
|
341
|
+
def compound_interest(principal, rate, years, compounds_per_year):
|
|
342
|
+
p = FlexFloat.from_float(principal)
|
|
343
|
+
r = FlexFloat.from_float(rate)
|
|
344
|
+
n = FlexFloat.from_float(compounds_per_year)
|
|
345
|
+
t = FlexFloat.from_float(years)
|
|
346
|
+
|
|
347
|
+
# A = P(1 + r/n)^(nt)
|
|
348
|
+
rate_per_period = r / n
|
|
349
|
+
exponent = n * t
|
|
350
|
+
base = FlexFloat.from_float(1.0) + rate_per_period
|
|
351
|
+
|
|
352
|
+
final_amount = p * (base ** exponent)
|
|
353
|
+
return final_amount
|
|
354
|
+
|
|
355
|
+
# Calculate compound interest over very long periods with high precision
|
|
356
|
+
result = compound_interest(1000000.0, 0.05, 100, 12)
|
|
273
357
|
```
|
|
274
358
|
|
|
275
359
|
### Physics Simulations
|
|
276
360
|
```python
|
|
361
|
+
from flexfloat import FlexFloat
|
|
362
|
+
from flexfloat.math import sqrt, pi, exp
|
|
363
|
+
|
|
277
364
|
# Handle extreme values in physics calculations
|
|
278
|
-
c = FlexFloat.from_float(299792458) # Speed of light
|
|
279
|
-
mass = FlexFloat.from_float(1e-30) # Atomic mass
|
|
365
|
+
c = FlexFloat.from_float(299792458) # Speed of light (m/s)
|
|
366
|
+
mass = FlexFloat.from_float(1e-30) # Atomic mass (kg)
|
|
280
367
|
|
|
281
368
|
# E = mc² with extreme precision
|
|
282
369
|
energy = mass * c * c
|
|
370
|
+
|
|
371
|
+
# Quantum mechanics - wave function calculations
|
|
372
|
+
def gaussian_wave_packet(x, x0, sigma, k0):
|
|
373
|
+
ff_x = FlexFloat.from_float(x)
|
|
374
|
+
ff_x0 = FlexFloat.from_float(x0)
|
|
375
|
+
ff_sigma = FlexFloat.from_float(sigma)
|
|
376
|
+
ff_k0 = FlexFloat.from_float(k0)
|
|
377
|
+
|
|
378
|
+
# ψ(x) = exp(-(x-x0)²/(4σ²)) * exp(ik0x)
|
|
379
|
+
displacement = ff_x - ff_x0
|
|
380
|
+
gaussian = exp(-(displacement * displacement) / (FlexFloat.from_float(4.0) * ff_sigma * ff_sigma))
|
|
381
|
+
phase = ff_k0 * ff_x
|
|
382
|
+
|
|
383
|
+
return gaussian # Real part only for this example
|
|
283
384
|
```
|
|
284
385
|
|
|
285
386
|
## 🏗️ Architecture
|
|
@@ -288,8 +389,18 @@ FlexFloat is built with a modular architecture:
|
|
|
288
389
|
|
|
289
390
|
```
|
|
290
391
|
flexfloat/
|
|
291
|
-
├── core.py # Main FlexFloat class
|
|
292
|
-
├── types.py # Type definitions
|
|
392
|
+
├── core.py # Main FlexFloat class and arithmetic operations
|
|
393
|
+
├── types.py # Type definitions and protocols
|
|
394
|
+
├── math/ # Complete mathematical function library
|
|
395
|
+
│ ├── __init__.py # Math module exports
|
|
396
|
+
│ ├── constants.py # Mathematical constants (π, e, etc.)
|
|
397
|
+
│ ├── exponential.py # exp, expm1, pow functions
|
|
398
|
+
│ ├── logarithmic.py # log, log10, log2, log1p functions
|
|
399
|
+
│ ├── trigonometric.py # sin, cos, tan and inverse functions
|
|
400
|
+
│ ├── hyperbolic.py # sinh, cosh, tanh and inverse functions
|
|
401
|
+
│ ├── sqrt.py # sqrt, cbrt functions
|
|
402
|
+
│ ├── floating_point.py # IEEE 754 utilities
|
|
403
|
+
│ └── utility.py # ceil, floor, fmod and other utilities
|
|
293
404
|
├── bitarray/ # BitArray implementations
|
|
294
405
|
│ ├── bitarray.py # Abstract base class
|
|
295
406
|
│ ├── bitarray_bool.py # List[bool] implementation
|
|
@@ -302,10 +413,12 @@ flexfloat/
|
|
|
302
413
|
### Design Principles
|
|
303
414
|
|
|
304
415
|
1. **IEEE 754 Compatibility**: Start with standard double-precision format
|
|
305
|
-
2. **Graceful Scaling**: Automatically expand exponent when needed
|
|
416
|
+
2. **Graceful Scaling**: Automatically expand exponent when needed
|
|
306
417
|
3. **Precision Preservation**: Keep fraction size fixed for consistent accuracy
|
|
307
418
|
4. **Performance Options**: Multiple backends for different use cases
|
|
308
419
|
5. **Pythonic Interface**: Natural syntax for mathematical operations
|
|
420
|
+
6. **Comprehensive Math Library**: Complete set of mathematical functions matching Python's math module
|
|
421
|
+
7. **Special Value Handling**: Proper IEEE 754 semantics for NaN, infinity, and zero
|
|
309
422
|
|
|
310
423
|
## 📊 Performance Considerations
|
|
311
424
|
|
|
@@ -326,6 +439,7 @@ flexfloat/
|
|
|
326
439
|
|
|
327
440
|
```python
|
|
328
441
|
from flexfloat import FlexFloat, ListInt64BitArray, BigIntBitArray
|
|
442
|
+
from flexfloat.math import sin, cos, pi
|
|
329
443
|
|
|
330
444
|
# Choose the right BitArray implementation for your use case
|
|
331
445
|
# For standard operations with moderate precision
|
|
@@ -334,6 +448,10 @@ FlexFloat.set_bitarray_implementation(ListInt64BitArray)
|
|
|
334
448
|
# For most use cases, Python's int is already optimized
|
|
335
449
|
FlexFloat.set_bitarray_implementation(BigIntBitArray)
|
|
336
450
|
|
|
451
|
+
# Use mathematical constants from the math module
|
|
452
|
+
from flexfloat.math import pi, e
|
|
453
|
+
circle_area = pi * radius * radius # More accurate than FlexFloat.from_float(3.14159...)
|
|
454
|
+
|
|
337
455
|
# Batch operations when possible
|
|
338
456
|
values = [FlexFloat.from_float(x) for x in range(1000)]
|
|
339
457
|
sum_result = sum(values, FlexFloat.zero())
|
|
@@ -345,11 +463,23 @@ if value_in_standard_range:
|
|
|
345
463
|
|
|
346
464
|
## 📋 Roadmap
|
|
347
465
|
|
|
348
|
-
|
|
349
|
-
- [
|
|
466
|
+
### ✅ Version 1.0.0 - Complete Core Features
|
|
467
|
+
- [x] Initial release with basic arithmetic and special values
|
|
468
|
+
- [x] Complete mathematical function library (trigonometric, logarithmic, exponential, hyperbolic)
|
|
469
|
+
- [x] Square root and power functions
|
|
470
|
+
- [x] Mathematical constants (π, e, τ)
|
|
471
|
+
- [x] Comprehensive test suite with high coverage
|
|
472
|
+
- [x] Multiple BitArray backend implementations
|
|
473
|
+
- [x] IEEE 754 compatibility and special value handling
|
|
474
|
+
|
|
475
|
+
### 🚧 Future Enhancements
|
|
350
476
|
- [ ] Performance optimizations for large arrays
|
|
351
|
-
- [ ]
|
|
477
|
+
- [ ] Serialization support (JSON, pickle)
|
|
352
478
|
- [ ] Decimal mode for exact decimal representation
|
|
479
|
+
- [ ] Complex number support (FlexComplex class)
|
|
480
|
+
- [ ] Additional utility functions (gamma, erf, etc.)
|
|
481
|
+
- [ ] GPU acceleration support
|
|
482
|
+
- [ ] Integration with NumPy arrays
|
|
353
483
|
|
|
354
484
|
|
|
355
485
|
## 📄 License
|