flexfloat 0.1.5__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.5 → flexfloat-0.3.0}/.bumpversion.cfg +1 -1
- {flexfloat-0.1.5 → flexfloat-0.3.0}/PKG-INFO +48 -25
- {flexfloat-0.1.5 → flexfloat-0.3.0}/README.md +47 -24
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/__init__.py +1 -1
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat.egg-info/PKG-INFO +48 -25
- {flexfloat-0.1.5 → flexfloat-0.3.0}/pyproject.toml +1 -1
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/build-check.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/manual-release.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/pr-labeler.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/release.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/test.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/version-bump.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.github/workflows/version-check.yml +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/.gitignore +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/LICENSE +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/MANIFEST.in +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/bitarray/__init__.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/bitarray/bitarray.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/bitarray/bitarray_bigint.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/bitarray/bitarray_bool.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/bitarray/bitarray_int64.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/bitarray/bitarray_mixins.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/core.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/py.typed +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat/types.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat.egg-info/SOURCES.txt +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat.egg-info/dependency_links.txt +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat.egg-info/requires.txt +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/flexfloat.egg-info/top_level.txt +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/scripts/validate_cicd.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/scripts/version_manager.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/setup.cfg +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/setup.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/__init__.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_addition.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_bigint_bitarray.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_bitarray.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_bitarray_implementations.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_conversions.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_division.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_flexfloat.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_multiplication.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_power.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_str_representation.py +0 -0
- {flexfloat-0.1.5 → flexfloat-0.3.0}/tests/test_subtraction.py +0 -0
@@ -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)]
|
@@ -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)]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|