flexfloat 0.1.5__py3-none-any.whl → 0.3.0__py3-none-any.whl
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/__init__.py +1 -1
- {flexfloat-0.1.5.dist-info → flexfloat-0.3.0.dist-info}/METADATA +48 -25
- {flexfloat-0.1.5.dist-info → flexfloat-0.3.0.dist-info}/RECORD +6 -6
- {flexfloat-0.1.5.dist-info → flexfloat-0.3.0.dist-info}/WHEEL +0 -0
- {flexfloat-0.1.5.dist-info → flexfloat-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {flexfloat-0.1.5.dist-info → flexfloat-0.3.0.dist-info}/top_level.txt +0 -0
flexfloat/__init__.py
CHANGED
@@ -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)]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
flexfloat/__init__.py,sha256=
|
1
|
+
flexfloat/__init__.py,sha256=Y7oR-CRyfDv_ImzcS4jkVveMzaXc2BHvAyzItgUaF3E,933
|
2
2
|
flexfloat/core.py,sha256=EQiBMmUtDreWFLjVeuaEiEj-PyNNcOV9BmRtOCs4neU,42821
|
3
3
|
flexfloat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
flexfloat/types.py,sha256=Enm4-oyGnvxGI-7MOK6eEIH2IzWafk0wQBsPaTqFYrE,266
|
@@ -8,8 +8,8 @@ flexfloat/bitarray/bitarray_bigint.py,sha256=yLfAreZ9hhP2f2dIS7ptYSuAFlUTXJiv-Lt
|
|
8
8
|
flexfloat/bitarray/bitarray_bool.py,sha256=naTUcTycvP9BfU1_CJRgajgvsJoQz9jvi5aI224pphE,6429
|
9
9
|
flexfloat/bitarray/bitarray_int64.py,sha256=FLfbg2gk_Ia-9_4UjoiWYZNK3CbD4teAYU5SGSV3WF0,10856
|
10
10
|
flexfloat/bitarray/bitarray_mixins.py,sha256=HJkyseP_yat0tE3_XElFEqBgKk8oWEiHEKjzqIRwUnw,5026
|
11
|
-
flexfloat-0.
|
12
|
-
flexfloat-0.
|
13
|
-
flexfloat-0.
|
14
|
-
flexfloat-0.
|
15
|
-
flexfloat-0.
|
11
|
+
flexfloat-0.3.0.dist-info/licenses/LICENSE,sha256=uwwkK--SUYUV3lbrv9kXJ_vDiYfHVb-t732g6c4qg7Q,1077
|
12
|
+
flexfloat-0.3.0.dist-info/METADATA,sha256=l9sXHmygreTApX2unPPQny_I8vVekmGUl-A0SLcbXSU,11510
|
13
|
+
flexfloat-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
14
|
+
flexfloat-0.3.0.dist-info/top_level.txt,sha256=82S8dY2UoNZh-9pwg7tUvbwB3uw2s3mfEoyUW6vCMdU,10
|
15
|
+
flexfloat-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|