Utility library that provides a floating point type with tolerance for equality comparisons
Project description
fuzzyfloat
A utility library that provides transparent floating point types with tolerances for equality comparison.
Getting Started
>>>from fuzzyfloat import rel_fp
>>>value = rel_fp(100)
>>>value == 100
True
>>>value == 99.99999999
True
>>>value == 100.00000001
True
>>>value = 1000
>>>value == 1000.0000001
True
>>>value = 10000
>>>value == 10000.000001
True
>>>value = 100000
>>>value == 100000.00001
True
>>>from fuzzyfloat import abs_fp
>>>value = abs_fp(100)
>>>value = 100000
>>>value == 100000.00001
False
>>>value == 100000.00000001
True
Setting different tolerances
from fuzzyfloat import FuzzyFloatMeta
class my_fp(metaclass=FuzzyFloatMeta, rel_tol=1e-05, atol=0.01):
pass
Using a different underlying type
import numpy as np
from fuzzyfloat import FuzzyFloatMeta
class np_fp(metaclass=FuzzyFloatMeta, ftype=np.float128):
pass
class c_fp(metaclass=FuzzyFloatMeta, ftype=complex):
pass
Limitations
Any operations provided by the operators module will propogate the class type (and therefore the tolerances).
However, there are many other functions, especially those that touch c extensions, where the type information will
be lost, such as math.sqrt()
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fuzzyfloat-1.0.2.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for fuzzyfloat-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee58ab59b266a30fc185ee43a8ff2f249112f1a1a57a481e52c32370a289bbaa |
|
MD5 | c136e7c0f6d49a39119ac42f2d1798d1 |
|
BLAKE2b-256 | 16cbbe74e86f0188a564a3851d1057246c3fe8599db25ce269a3dc172a454757 |