flexfloat 0.1.3__tar.gz → 0.3.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.1.3 → flexfloat-0.3.0}/.bumpversion.cfg +1 -1
- {flexfloat-0.1.3 → flexfloat-0.3.0}/.github/workflows/manual-release.yml +1 -4
- {flexfloat-0.1.3 → flexfloat-0.3.0}/.github/workflows/pr-labeler.yml +10 -3
- flexfloat-0.3.0/.github/workflows/release.yml +87 -0
- flexfloat-0.3.0/.github/workflows/version-bump.yml +121 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/.github/workflows/version-check.yml +4 -1
- {flexfloat-0.1.3 → flexfloat-0.3.0}/PKG-INFO +48 -25
- {flexfloat-0.1.3 → flexfloat-0.3.0}/README.md +47 -24
- flexfloat-0.3.0/flexfloat/__init__.py +36 -0
- flexfloat-0.3.0/flexfloat/bitarray/__init__.py +31 -0
- flexfloat-0.3.0/flexfloat/bitarray/bitarray.py +298 -0
- flexfloat-0.3.0/flexfloat/bitarray/bitarray_bigint.py +305 -0
- flexfloat-0.3.0/flexfloat/bitarray/bitarray_bool.py +202 -0
- flexfloat-0.3.0/flexfloat/bitarray/bitarray_int64.py +333 -0
- flexfloat-0.3.0/flexfloat/bitarray/bitarray_mixins.py +156 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat/core.py +215 -113
- flexfloat-0.3.0/flexfloat/types.py +11 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat.egg-info/PKG-INFO +48 -25
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat.egg-info/SOURCES.txt +5 -2
- {flexfloat-0.1.3 → flexfloat-0.3.0}/pyproject.toml +1 -1
- {flexfloat-0.1.3 → flexfloat-0.3.0}/scripts/validate_cicd.py +2 -1
- {flexfloat-0.1.3 → flexfloat-0.3.0}/scripts/version_manager.py +2 -3
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_addition.py +1 -1
- flexfloat-0.3.0/tests/test_bigint_bitarray.py +409 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_bitarray.py +63 -61
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_bitarray_implementations.py +71 -94
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_conversions.py +31 -31
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_division.py +2 -22
- flexfloat-0.1.3/tests/test_bigfloat.py → flexfloat-0.3.0/tests/test_flexfloat.py +60 -13
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_multiplication.py +3 -3
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_power.py +3 -3
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_str_representation.py +6 -6
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/test_subtraction.py +5 -5
- flexfloat-0.1.3/.github/workflows/release.yml +0 -130
- flexfloat-0.1.3/flexfloat/__init__.py +0 -32
- flexfloat-0.1.3/flexfloat/bitarray/__init__.py +0 -90
- flexfloat-0.1.3/flexfloat/bitarray/bitarray.py +0 -198
- flexfloat-0.1.3/flexfloat/bitarray/bitarray_int64.py +0 -308
- flexfloat-0.1.3/flexfloat/bitarray/bitarray_list.py +0 -187
- flexfloat-0.1.3/flexfloat/bitarray/bitarray_mixins.py +0 -93
- flexfloat-0.1.3/flexfloat/types.py +0 -5
- {flexfloat-0.1.3 → flexfloat-0.3.0}/.github/workflows/build-check.yml +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/.github/workflows/test.yml +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/.gitignore +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/LICENSE +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/MANIFEST.in +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat/py.typed +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat.egg-info/dependency_links.txt +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat.egg-info/requires.txt +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/flexfloat.egg-info/top_level.txt +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/setup.cfg +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/setup.py +0 -0
- {flexfloat-0.1.3 → flexfloat-0.3.0}/tests/__init__.py +0 -0
@@ -70,9 +70,6 @@ jobs:
|
|
70
70
|
- name: Bump or set version
|
71
71
|
id: bump_version
|
72
72
|
run: |
|
73
|
-
# Update current version in .bumpversion.cfg
|
74
|
-
# sed -i "s/current_version = .*/current_version = ${{ steps.current_version.outputs.version }}/" .bumpversion.cfg
|
75
|
-
|
76
73
|
if [ -n "${{ steps.set_new_version.outputs.new_version }}" ]; then
|
77
74
|
# Set version directly
|
78
75
|
bump2version --new-version ${{ steps.set_new_version.outputs.new_version }} patch
|
@@ -97,7 +94,7 @@ jobs:
|
|
97
94
|
|
98
95
|
- name: Commit version bump
|
99
96
|
run: |
|
100
|
-
git add pyproject.toml flexfloat/__init__.py
|
97
|
+
git add pyproject.toml flexfloat/__init__.py .bumpversion.cfg
|
101
98
|
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }} [skip ci]"
|
102
99
|
git push origin main
|
103
100
|
|
@@ -67,7 +67,7 @@ jobs:
|
|
67
67
|
}
|
68
68
|
}
|
69
69
|
|
70
|
-
// Add the
|
70
|
+
// Add only the version bump label
|
71
71
|
await github.rest.issues.addLabels({
|
72
72
|
owner: context.repo.owner,
|
73
73
|
repo: context.repo.repo,
|
@@ -93,12 +93,19 @@ jobs:
|
|
93
93
|
| minor | New features, non-breaking changes |
|
94
94
|
| major | Breaking changes, major updates |
|
95
95
|
|
96
|
-
|
96
|
+
**🚀 Release Status**: This PR is labeled with the recommended version bump type. To trigger a release:
|
97
|
+
1. **Add the \`release\` label** to this PR when ready
|
98
|
+
2. The version will be automatically bumped when the \`release\` label is added
|
99
|
+
3. When merged, it will create a Git tag, GitHub release, and publish to PyPI
|
100
|
+
|
101
|
+
**To prevent release**: Simply don\'t add the \`release\` label.
|
102
|
+
|
103
|
+
**To change version bump**: You can manually change the version bump label:
|
97
104
|
- Add \`major\` label for breaking changes
|
98
105
|
- Add \`minor\` label for new features
|
99
106
|
- Add \`patch\` label for bug fixes
|
100
107
|
|
101
|
-
The version will be automatically updated
|
108
|
+
The version will be automatically updated when the \`release\` label is added to this PR.`;
|
102
109
|
|
103
110
|
// Check if we already commented
|
104
111
|
const comments = await github.rest.issues.listComments({
|
@@ -0,0 +1,87 @@
|
|
1
|
+
name: Release
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [closed]
|
6
|
+
branches: [main]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
release:
|
10
|
+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
permissions:
|
13
|
+
contents: write
|
14
|
+
id-token: write # For trusted publishing to PyPI
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- name: Checkout code
|
18
|
+
uses: actions/checkout@v4
|
19
|
+
with:
|
20
|
+
fetch-depth: 0
|
21
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
|
23
|
+
- name: Set up Python
|
24
|
+
uses: actions/setup-python@v5
|
25
|
+
with:
|
26
|
+
python-version: "3.11"
|
27
|
+
|
28
|
+
- name: Install dependencies
|
29
|
+
run: |
|
30
|
+
python -m pip install --upgrade pip
|
31
|
+
pip install build twine bump2version
|
32
|
+
|
33
|
+
- name: Configure Git
|
34
|
+
run: |
|
35
|
+
git config --local user.email "action@github.com"
|
36
|
+
git config --local user.name "GitHub Action"
|
37
|
+
|
38
|
+
- name: Get current version
|
39
|
+
id: current_version
|
40
|
+
run: |
|
41
|
+
VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
42
|
+
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
43
|
+
echo "Current version: $VERSION"
|
44
|
+
|
45
|
+
- name: Run tests
|
46
|
+
run: |
|
47
|
+
pip install -e ".[dev]"
|
48
|
+
pytest tests/
|
49
|
+
|
50
|
+
- name: Build package
|
51
|
+
run: |
|
52
|
+
python -m build
|
53
|
+
|
54
|
+
- name: Create Git tag
|
55
|
+
run: |
|
56
|
+
git tag -a "v${{ steps.current_version.outputs.version }}" -m "Release v${{ steps.current_version.outputs.version }}"
|
57
|
+
git push origin "v${{ steps.current_version.outputs.version }}"
|
58
|
+
|
59
|
+
- name: Create GitHub Release
|
60
|
+
id: create_release
|
61
|
+
uses: softprops/action-gh-release@v2
|
62
|
+
with:
|
63
|
+
tag_name: "v${{ steps.current_version.outputs.version }}"
|
64
|
+
name: "Release v${{ steps.current_version.outputs.version }}"
|
65
|
+
body: |
|
66
|
+
## Changes in v${{ steps.current_version.outputs.version }}
|
67
|
+
|
68
|
+
This release was automatically created from PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}
|
69
|
+
|
70
|
+
### Pull Request Details
|
71
|
+
${{ github.event.pull_request.body }}
|
72
|
+
|
73
|
+
### Artifacts
|
74
|
+
- **Python Wheel**: `flexfloat-${{ steps.current_version.outputs.version }}-py3-none-any.whl`
|
75
|
+
- **Source Distribution**: `flexfloat-${{ steps.current_version.outputs.version }}.tar.gz`
|
76
|
+
|
77
|
+
The package has been automatically published to [PyPI](https://pypi.org/project/flexfloat/${{ steps.current_version.outputs.version }}/).
|
78
|
+
draft: false
|
79
|
+
prerelease: false
|
80
|
+
files: |
|
81
|
+
./dist/flexfloat-${{ steps.current_version.outputs.version }}-py3-none-any.whl
|
82
|
+
./dist/flexfloat-${{ steps.current_version.outputs.version }}.tar.gz
|
83
|
+
|
84
|
+
- name: Publish to PyPI
|
85
|
+
uses: pypa/gh-action-pypi-publish@v1.12.4
|
86
|
+
with:
|
87
|
+
verbose: true
|
@@ -0,0 +1,121 @@
|
|
1
|
+
name: Version Bump
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [labeled, unlabeled]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
version-bump:
|
9
|
+
if: |
|
10
|
+
github.event.action == 'labeled' &&
|
11
|
+
github.event.label.name == 'release' &&
|
12
|
+
github.event.pull_request.merged == false
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
permissions:
|
15
|
+
contents: write
|
16
|
+
pull-requests: write
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- name: Checkout PR branch
|
20
|
+
uses: actions/checkout@v4
|
21
|
+
with:
|
22
|
+
fetch-depth: 0
|
23
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
24
|
+
ref: ${{ github.event.pull_request.head.ref }}
|
25
|
+
|
26
|
+
- name: Set up Python
|
27
|
+
uses: actions/setup-python@v5
|
28
|
+
with:
|
29
|
+
python-version: "3.11"
|
30
|
+
|
31
|
+
- name: Install dependencies
|
32
|
+
run: |
|
33
|
+
python -m pip install --upgrade pip
|
34
|
+
pip install bump2version
|
35
|
+
|
36
|
+
- name: Configure Git
|
37
|
+
run: |
|
38
|
+
git config --local user.email "action@github.com"
|
39
|
+
git config --local user.name "GitHub Action"
|
40
|
+
|
41
|
+
- name: Determine version bump type
|
42
|
+
id: bump_type
|
43
|
+
run: |
|
44
|
+
BUMP_TYPE="patch"
|
45
|
+
LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}"
|
46
|
+
if echo "$LABELS" | grep -q "major"; then
|
47
|
+
BUMP_TYPE="major"
|
48
|
+
elif echo "$LABELS" | grep -q "minor"; then
|
49
|
+
BUMP_TYPE="minor"
|
50
|
+
elif echo "$LABELS" | grep -q "patch"; then
|
51
|
+
BUMP_TYPE="patch"
|
52
|
+
fi
|
53
|
+
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
|
54
|
+
echo "Version bump type: $BUMP_TYPE"
|
55
|
+
|
56
|
+
- name: Bump version
|
57
|
+
id: bump_version
|
58
|
+
run: |
|
59
|
+
bump2version ${{ steps.bump_type.outputs.bump_type }}
|
60
|
+
NEW_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
61
|
+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
62
|
+
echo "New version: $NEW_VERSION"
|
63
|
+
|
64
|
+
- name: Commit version bump to PR branch
|
65
|
+
run: |
|
66
|
+
git add pyproject.toml flexfloat/__init__.py .bumpversion.cfg
|
67
|
+
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }} [skip ci]"
|
68
|
+
git push origin ${{ github.event.pull_request.head.ref }}
|
69
|
+
|
70
|
+
revert-version-bump:
|
71
|
+
if: |
|
72
|
+
github.event.action == 'unlabeled' &&
|
73
|
+
github.event.label.name == 'release' &&
|
74
|
+
github.event.pull_request.merged == false
|
75
|
+
runs-on: ubuntu-latest
|
76
|
+
permissions:
|
77
|
+
contents: write
|
78
|
+
pull-requests: write
|
79
|
+
|
80
|
+
steps:
|
81
|
+
- name: Checkout PR branch
|
82
|
+
uses: actions/checkout@v4
|
83
|
+
with:
|
84
|
+
fetch-depth: 0
|
85
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
86
|
+
ref: ${{ github.event.pull_request.head.ref }}
|
87
|
+
|
88
|
+
- name: Configure Git
|
89
|
+
run: |
|
90
|
+
git config --local user.email "action@github.com"
|
91
|
+
git config --local user.name "GitHub Action"
|
92
|
+
|
93
|
+
- name: Revert version bump commit
|
94
|
+
run: |
|
95
|
+
git fetch origin main
|
96
|
+
BASE_COMMIT=$(git merge-base HEAD origin/main)
|
97
|
+
VERSION_BUMP_COMMITS=()
|
98
|
+
for commit in $(git rev-list $BASE_COMMIT..HEAD); do
|
99
|
+
COMMIT_MSG=$(git log -1 --pretty=format:"%s" $commit)
|
100
|
+
if [[ $COMMIT_MSG == *"Bump version to"* ]] && [[ $COMMIT_MSG == *"[skip ci]"* ]]; then
|
101
|
+
VERSION_BUMP_COMMITS+=($commit)
|
102
|
+
fi
|
103
|
+
done
|
104
|
+
if [ ${#VERSION_BUMP_COMMITS[@]} -gt 0 ]; then
|
105
|
+
FIRST_VERSION_BUMP=${VERSION_BUMP_COMMITS[-1]}
|
106
|
+
RESET_TARGET=$(git rev-parse $FIRST_VERSION_BUMP^)
|
107
|
+
git reset --hard $RESET_TARGET
|
108
|
+
git push --force-with-lease origin ${{ github.event.pull_request.head.ref }}
|
109
|
+
echo "Version bump commits reverted"
|
110
|
+
fi
|
111
|
+
|
112
|
+
- name: Comment on PR
|
113
|
+
uses: actions/github-script@v7
|
114
|
+
with:
|
115
|
+
script: |
|
116
|
+
await github.rest.issues.createComment({
|
117
|
+
owner: context.repo.owner,
|
118
|
+
repo: context.repo.repo,
|
119
|
+
issue_number: context.issue.number,
|
120
|
+
body: '🚫 **Release Cancelled**: The `release` label was removed. Version bump commit has been reverted and this PR will not trigger a release when merged.'
|
121
|
+
});
|
@@ -19,15 +19,18 @@ jobs:
|
|
19
19
|
# Extract versions from different files
|
20
20
|
PYPROJECT_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d'"' -f2)
|
21
21
|
INIT_VERSION=$(grep -E '^__version__ = ' flexfloat/__init__.py | cut -d'"' -f2)
|
22
|
+
BUMPVERSION_VERSION=$(grep -E '^current_version = ' .bumpversion.cfg | cut -d' ' -f3)
|
22
23
|
|
23
24
|
echo "pyproject.toml version: $PYPROJECT_VERSION"
|
24
25
|
echo "flexfloat/__init__.py version: $INIT_VERSION"
|
26
|
+
echo ".bumpversion.cfg current_version: $BUMPVERSION_VERSION"
|
25
27
|
|
26
28
|
# Check if versions match
|
27
|
-
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
|
29
|
+
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ] || [ "$PYPROJECT_VERSION" != "$BUMPVERSION_VERSION" ]; then
|
28
30
|
echo "[NO] Version mismatch detected!"
|
29
31
|
echo "pyproject.toml has version $PYPROJECT_VERSION"
|
30
32
|
echo "flexfloat/__init__.py has version $INIT_VERSION"
|
33
|
+
echo ".bumpversion.cfg has current_version $BUMPVERSION_VERSION"
|
31
34
|
echo "Please ensure all version references are synchronized."
|
32
35
|
exit 1
|
33
36
|
else
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: flexfloat
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.0
|
4
4
|
Summary: A library for arbitrary precision floating point arithmetic
|
5
5
|
Author: Ferran Sanchez Llado
|
6
6
|
License: MIT
|
@@ -45,7 +45,7 @@ A high-precision Python library for arbitrary precision floating-point arithmeti
|
|
45
45
|
- **🔢 Growable Exponents**: Dynamically expand exponent size to handle extremely large (>10^308) or small (<10^-308) numbers
|
46
46
|
- **🎯 Fixed-Size Fractions**: Maintain IEEE 754-compatible 52-bit fraction precision for consistent accuracy
|
47
47
|
- **⚡ Full Arithmetic Support**: Addition, subtraction, multiplication, division, and power operations
|
48
|
-
- **🔧 Multiple BitArray Backends**: Choose between list-
|
48
|
+
- **🔧 Multiple BitArray Backends**: Choose between bool-list, int64-list, and big-integer implementations for optimal performance
|
49
49
|
- **🌟 Special Value Handling**: Complete support for NaN, ±infinity, and zero values
|
50
50
|
- **🛡️ Overflow Protection**: Automatic exponent growth prevents overflow/underflow errors
|
51
51
|
- **📊 IEEE 754 Baseline**: Fully compatible with standard double-precision format as the starting point
|
@@ -81,12 +81,15 @@ print(f"Exponent bits: {len(large_result.exponent)}") # > 11 (grown beyond IEEE
|
|
81
81
|
print(f"Can represent: {large_result}") # No overflow!
|
82
82
|
```
|
83
83
|
|
84
|
-
### Advanced
|
84
|
+
### Advanced Features
|
85
85
|
|
86
86
|
```python
|
87
|
-
from flexfloat import FlexFloat
|
87
|
+
from flexfloat import FlexFloat, BigIntBitArray
|
88
|
+
|
89
|
+
# Use different BitArray implementations for specific needs
|
90
|
+
FlexFloat.set_bitarray_implementation(BigIntBitArray)
|
88
91
|
|
89
|
-
# Mathematical operations
|
92
|
+
# Mathematical operations with unlimited precision
|
90
93
|
x = FlexFloat.from_float(2.0)
|
91
94
|
y = FlexFloat.from_float(3.0)
|
92
95
|
|
@@ -98,10 +101,13 @@ print(power_result.to_float()) # 8.0
|
|
98
101
|
e_result = FlexFloat.e ** x # e^2
|
99
102
|
print(f"e^2 ≈ {e_result.to_float()}")
|
100
103
|
|
104
|
+
# Absolute value operations
|
105
|
+
abs_result = abs(FlexFloat.from_float(-42.0))
|
106
|
+
print(f"|-42| = {abs_result.to_float()}") # 42.0
|
107
|
+
|
101
108
|
# Working with extreme values
|
102
|
-
tiny = FlexFloat.from_float(1e-300)
|
103
109
|
huge = FlexFloat.from_float(1e300)
|
104
|
-
extreme_product =
|
110
|
+
extreme_product = huge * huge
|
105
111
|
print(f"Product: {extreme_product.to_float()}") # Still computable!
|
106
112
|
|
107
113
|
# Precision demonstration
|
@@ -111,35 +117,40 @@ print(f"1/3 with 52-bit precision: {precise_calc}")
|
|
111
117
|
|
112
118
|
## 🔧 BitArray Backends
|
113
119
|
|
114
|
-
FlexFloat supports multiple BitArray implementations for different performance characteristics:
|
120
|
+
FlexFloat supports multiple BitArray implementations for different performance characteristics. You can use them directly or configure FlexFloat to use a specific implementation:
|
115
121
|
|
116
122
|
```python
|
117
123
|
from flexfloat import (
|
118
124
|
FlexFloat,
|
119
|
-
|
120
|
-
|
125
|
+
ListBoolBitArray,
|
126
|
+
ListInt64BitArray,
|
127
|
+
BigIntBitArray
|
121
128
|
)
|
122
129
|
|
123
|
-
#
|
124
|
-
|
125
|
-
|
126
|
-
# Use list-based implementation (default, more flexible)
|
127
|
-
set_default_implementation('list')
|
128
|
-
flex_list = FlexFloat.from_float(42.0)
|
130
|
+
# Configure FlexFloat to use a specific BitArray implementation
|
131
|
+
FlexFloat.set_bitarray_implementation(ListBoolBitArray) # Default
|
132
|
+
flex_bool = FlexFloat.from_float(42.0)
|
129
133
|
|
130
|
-
#
|
131
|
-
set_default_implementation('int64')
|
134
|
+
FlexFloat.set_bitarray_implementation(ListInt64BitArray) # For performance
|
132
135
|
flex_int64 = FlexFloat.from_float(42.0)
|
133
136
|
|
134
|
-
#
|
137
|
+
FlexFloat.set_bitarray_implementation(BigIntBitArray) # For very large arrays
|
138
|
+
flex_bigint = FlexFloat.from_float(42.0)
|
139
|
+
|
140
|
+
# Use BitArray implementations directly
|
141
|
+
bits = [True, False, True, False]
|
142
|
+
bool_array = ListBoolBitArray.from_bits(bits)
|
143
|
+
int64_array = ListInt64BitArray.from_bits(bits)
|
144
|
+
bigint_array = BigIntBitArray.from_bits(bits)
|
135
145
|
```
|
136
146
|
|
137
147
|
### Implementation Comparison
|
138
148
|
|
139
149
|
| Implementation | Best For | Pros | Cons |
|
140
150
|
|---------------|----------|------|------|
|
141
|
-
| `
|
142
|
-
| `
|
151
|
+
| `ListBoolBitArray` | Testing and development | Simple, flexible, easy to debug | Slower for large operations |
|
152
|
+
| `ListInt64BitArray` | Standard operations | Fast for medium-sized arrays, memory efficient | Some overhead for very small arrays |
|
153
|
+
| `BigIntBitArray` | Any usescases | Python already optimizes it | Overhead for small arrays |
|
143
154
|
|
144
155
|
## 📚 API Reference
|
145
156
|
|
@@ -159,6 +170,11 @@ abs(a), -a
|
|
159
170
|
|
160
171
|
# Mathematical functions
|
161
172
|
FlexFloat.e ** x # Exponential function
|
173
|
+
flexfloat.exp() # Natural exponential
|
174
|
+
flexfloat.abs() # Absolute value
|
175
|
+
|
176
|
+
# BitArray configuration
|
177
|
+
FlexFloat.set_bitarray_implementation(implementation: Type[BitArray])
|
162
178
|
```
|
163
179
|
|
164
180
|
### Special Values
|
@@ -269,8 +285,9 @@ flexfloat/
|
|
269
285
|
├── types.py # Type definitions
|
270
286
|
├── bitarray/ # BitArray implementations
|
271
287
|
│ ├── bitarray.py # Abstract base class
|
272
|
-
│ ├──
|
273
|
-
│ ├── bitarray_int64.py #
|
288
|
+
│ ├── bitarray_bool.py # List[bool] implementation
|
289
|
+
│ ├── bitarray_int64.py # List[int64] implementation
|
290
|
+
│ ├── bitarray_bigint.py # Python int implementation
|
274
291
|
│ └── bitarray_mixins.py # Common functionality
|
275
292
|
└── __init__.py # Public API exports
|
276
293
|
```
|
@@ -301,8 +318,14 @@ flexfloat/
|
|
301
318
|
### Optimization Tips
|
302
319
|
|
303
320
|
```python
|
304
|
-
|
305
|
-
|
321
|
+
from flexfloat import FlexFloat, ListInt64BitArray, BigIntBitArray
|
322
|
+
|
323
|
+
# Choose the right BitArray implementation for your use case
|
324
|
+
# For standard operations with moderate precision
|
325
|
+
FlexFloat.set_bitarray_implementation(ListInt64BitArray)
|
326
|
+
|
327
|
+
# For most use cases, Python's int is already optimized
|
328
|
+
FlexFloat.set_bitarray_implementation(BigIntBitArray)
|
306
329
|
|
307
330
|
# Batch operations when possible
|
308
331
|
values = [FlexFloat.from_float(x) for x in range(1000)]
|
@@ -11,7 +11,7 @@ A high-precision Python library for arbitrary precision floating-point arithmeti
|
|
11
11
|
- **🔢 Growable Exponents**: Dynamically expand exponent size to handle extremely large (>10^308) or small (<10^-308) numbers
|
12
12
|
- **🎯 Fixed-Size Fractions**: Maintain IEEE 754-compatible 52-bit fraction precision for consistent accuracy
|
13
13
|
- **⚡ Full Arithmetic Support**: Addition, subtraction, multiplication, division, and power operations
|
14
|
-
- **🔧 Multiple BitArray Backends**: Choose between list-
|
14
|
+
- **🔧 Multiple BitArray Backends**: Choose between bool-list, int64-list, and big-integer implementations for optimal performance
|
15
15
|
- **🌟 Special Value Handling**: Complete support for NaN, ±infinity, and zero values
|
16
16
|
- **🛡️ Overflow Protection**: Automatic exponent growth prevents overflow/underflow errors
|
17
17
|
- **📊 IEEE 754 Baseline**: Fully compatible with standard double-precision format as the starting point
|
@@ -47,12 +47,15 @@ print(f"Exponent bits: {len(large_result.exponent)}") # > 11 (grown beyond IEEE
|
|
47
47
|
print(f"Can represent: {large_result}") # No overflow!
|
48
48
|
```
|
49
49
|
|
50
|
-
### Advanced
|
50
|
+
### Advanced Features
|
51
51
|
|
52
52
|
```python
|
53
|
-
from flexfloat import FlexFloat
|
53
|
+
from flexfloat import FlexFloat, BigIntBitArray
|
54
|
+
|
55
|
+
# Use different BitArray implementations for specific needs
|
56
|
+
FlexFloat.set_bitarray_implementation(BigIntBitArray)
|
54
57
|
|
55
|
-
# Mathematical operations
|
58
|
+
# Mathematical operations with unlimited precision
|
56
59
|
x = FlexFloat.from_float(2.0)
|
57
60
|
y = FlexFloat.from_float(3.0)
|
58
61
|
|
@@ -64,10 +67,13 @@ print(power_result.to_float()) # 8.0
|
|
64
67
|
e_result = FlexFloat.e ** x # e^2
|
65
68
|
print(f"e^2 ≈ {e_result.to_float()}")
|
66
69
|
|
70
|
+
# Absolute value operations
|
71
|
+
abs_result = abs(FlexFloat.from_float(-42.0))
|
72
|
+
print(f"|-42| = {abs_result.to_float()}") # 42.0
|
73
|
+
|
67
74
|
# Working with extreme values
|
68
|
-
tiny = FlexFloat.from_float(1e-300)
|
69
75
|
huge = FlexFloat.from_float(1e300)
|
70
|
-
extreme_product =
|
76
|
+
extreme_product = huge * huge
|
71
77
|
print(f"Product: {extreme_product.to_float()}") # Still computable!
|
72
78
|
|
73
79
|
# Precision demonstration
|
@@ -77,35 +83,40 @@ print(f"1/3 with 52-bit precision: {precise_calc}")
|
|
77
83
|
|
78
84
|
## 🔧 BitArray Backends
|
79
85
|
|
80
|
-
FlexFloat supports multiple BitArray implementations for different performance characteristics:
|
86
|
+
FlexFloat supports multiple BitArray implementations for different performance characteristics. You can use them directly or configure FlexFloat to use a specific implementation:
|
81
87
|
|
82
88
|
```python
|
83
89
|
from flexfloat import (
|
84
90
|
FlexFloat,
|
85
|
-
|
86
|
-
|
91
|
+
ListBoolBitArray,
|
92
|
+
ListInt64BitArray,
|
93
|
+
BigIntBitArray
|
87
94
|
)
|
88
95
|
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
# Use list-based implementation (default, more flexible)
|
93
|
-
set_default_implementation('list')
|
94
|
-
flex_list = FlexFloat.from_float(42.0)
|
96
|
+
# Configure FlexFloat to use a specific BitArray implementation
|
97
|
+
FlexFloat.set_bitarray_implementation(ListBoolBitArray) # Default
|
98
|
+
flex_bool = FlexFloat.from_float(42.0)
|
95
99
|
|
96
|
-
#
|
97
|
-
set_default_implementation('int64')
|
100
|
+
FlexFloat.set_bitarray_implementation(ListInt64BitArray) # For performance
|
98
101
|
flex_int64 = FlexFloat.from_float(42.0)
|
99
102
|
|
100
|
-
#
|
103
|
+
FlexFloat.set_bitarray_implementation(BigIntBitArray) # For very large arrays
|
104
|
+
flex_bigint = FlexFloat.from_float(42.0)
|
105
|
+
|
106
|
+
# Use BitArray implementations directly
|
107
|
+
bits = [True, False, True, False]
|
108
|
+
bool_array = ListBoolBitArray.from_bits(bits)
|
109
|
+
int64_array = ListInt64BitArray.from_bits(bits)
|
110
|
+
bigint_array = BigIntBitArray.from_bits(bits)
|
101
111
|
```
|
102
112
|
|
103
113
|
### Implementation Comparison
|
104
114
|
|
105
115
|
| Implementation | Best For | Pros | Cons |
|
106
116
|
|---------------|----------|------|------|
|
107
|
-
| `
|
108
|
-
| `
|
117
|
+
| `ListBoolBitArray` | Testing and development | Simple, flexible, easy to debug | Slower for large operations |
|
118
|
+
| `ListInt64BitArray` | Standard operations | Fast for medium-sized arrays, memory efficient | Some overhead for very small arrays |
|
119
|
+
| `BigIntBitArray` | Any usescases | Python already optimizes it | Overhead for small arrays |
|
109
120
|
|
110
121
|
## 📚 API Reference
|
111
122
|
|
@@ -125,6 +136,11 @@ abs(a), -a
|
|
125
136
|
|
126
137
|
# Mathematical functions
|
127
138
|
FlexFloat.e ** x # Exponential function
|
139
|
+
flexfloat.exp() # Natural exponential
|
140
|
+
flexfloat.abs() # Absolute value
|
141
|
+
|
142
|
+
# BitArray configuration
|
143
|
+
FlexFloat.set_bitarray_implementation(implementation: Type[BitArray])
|
128
144
|
```
|
129
145
|
|
130
146
|
### Special Values
|
@@ -235,8 +251,9 @@ flexfloat/
|
|
235
251
|
├── types.py # Type definitions
|
236
252
|
├── bitarray/ # BitArray implementations
|
237
253
|
│ ├── bitarray.py # Abstract base class
|
238
|
-
│ ├──
|
239
|
-
│ ├── bitarray_int64.py #
|
254
|
+
│ ├── bitarray_bool.py # List[bool] implementation
|
255
|
+
│ ├── bitarray_int64.py # List[int64] implementation
|
256
|
+
│ ├── bitarray_bigint.py # Python int implementation
|
240
257
|
│ └── bitarray_mixins.py # Common functionality
|
241
258
|
└── __init__.py # Public API exports
|
242
259
|
```
|
@@ -267,8 +284,14 @@ flexfloat/
|
|
267
284
|
### Optimization Tips
|
268
285
|
|
269
286
|
```python
|
270
|
-
|
271
|
-
|
287
|
+
from flexfloat import FlexFloat, ListInt64BitArray, BigIntBitArray
|
288
|
+
|
289
|
+
# Choose the right BitArray implementation for your use case
|
290
|
+
# For standard operations with moderate precision
|
291
|
+
FlexFloat.set_bitarray_implementation(ListInt64BitArray)
|
292
|
+
|
293
|
+
# For most use cases, Python's int is already optimized
|
294
|
+
FlexFloat.set_bitarray_implementation(BigIntBitArray)
|
272
295
|
|
273
296
|
# Batch operations when possible
|
274
297
|
values = [FlexFloat.from_float(x) for x in range(1000)]
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"""FlexFloat - A library for arbitrary precision floating point arithmetic.
|
2
|
+
|
3
|
+
This package provides the FlexFloat class for handling floating-point numbers with
|
4
|
+
growable exponents and fixed-size fractions. It also provides several BitArray
|
5
|
+
implementations for efficient bit manipulation.
|
6
|
+
|
7
|
+
Example:
|
8
|
+
from flexfloat import FlexFloat
|
9
|
+
x = FlexFloat(1.5, exponent_length=8, fraction_length=23)
|
10
|
+
print(x)
|
11
|
+
# Output: FlexFloat(sign=False, exponent=..., fraction=...)
|
12
|
+
|
13
|
+
Modules:
|
14
|
+
core: Main FlexFloat class implementation
|
15
|
+
bitarray: BitArray implementations (bool, int64, bigint)
|
16
|
+
types: Type definitions
|
17
|
+
"""
|
18
|
+
|
19
|
+
from .bitarray import (
|
20
|
+
BigIntBitArray,
|
21
|
+
BitArray,
|
22
|
+
ListBoolBitArray,
|
23
|
+
ListInt64BitArray,
|
24
|
+
)
|
25
|
+
from .core import FlexFloat
|
26
|
+
|
27
|
+
__version__ = "0.3.0"
|
28
|
+
__author__ = "Ferran Sanchez Llado"
|
29
|
+
|
30
|
+
__all__ = [
|
31
|
+
"FlexFloat",
|
32
|
+
"BitArray",
|
33
|
+
"ListBoolBitArray",
|
34
|
+
"ListInt64BitArray",
|
35
|
+
"BigIntBitArray",
|
36
|
+
]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"""BitArray implementation for the flexfloat package.
|
2
|
+
|
3
|
+
This module provides a factory and utilities for working with different BitArray
|
4
|
+
implementations, including:
|
5
|
+
- ListBoolBitArray: List of booleans (default, flexible, easy to use)
|
6
|
+
- ListInt64BitArray: List of int64 chunks (memory efficient for large arrays)
|
7
|
+
- BigIntBitArray: Single Python int (arbitrary size, efficient for very large
|
8
|
+
arrays)
|
9
|
+
|
10
|
+
Example:
|
11
|
+
from flexfloat.bitarray import create_bitarray
|
12
|
+
ba = create_bitarray('int64', [True, False, True])
|
13
|
+
print(type(ba).__name__)
|
14
|
+
# Output: ListInt64BitArray
|
15
|
+
"""
|
16
|
+
|
17
|
+
from __future__ import annotations
|
18
|
+
|
19
|
+
from .bitarray import BitArray
|
20
|
+
from .bitarray_bigint import BigIntBitArray
|
21
|
+
from .bitarray_bool import ListBoolBitArray
|
22
|
+
from .bitarray_int64 import ListInt64BitArray
|
23
|
+
from .bitarray_mixins import BitArrayCommonMixin
|
24
|
+
|
25
|
+
__all__ = [
|
26
|
+
"BitArray",
|
27
|
+
"ListBoolBitArray",
|
28
|
+
"ListInt64BitArray",
|
29
|
+
"BigIntBitArray",
|
30
|
+
"BitArrayCommonMixin",
|
31
|
+
]
|