A simple module for approximate floating point arithmetic.
Project description
Approximate floating point arithmetic library. This simple module can be used to compare numbers using a relative and absolute tolerance, to mitigate floating point rounding errors.
from rr.approx import Approx
x = Approx(0.1) * 3
print x == 0.3 # True
The Approx class is very simple to use as a replacement for “regular” floats – you can use Approx objects instead of floats in most (if not all) contexts: arithmetic and comparisons.
The ApproxContext class, also accessible as Approx.Context, provides a context manager to temporarily modify the module’s tolerance parameters.
from rr.approx import Approx
print Approx.Context() # display current context
Approx.Context(1e-4, 1e-2).apply() # permanently modify tolerances
print Approx.Context()
with Approx.Context(rtol=1e-5, atol=1e-3): # temporary modification
print Approx.Context()
print Approx.Context()
Installation
pip install rr.approx
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for rr.approx-0.1.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4050076e7233ca275c88b893ec01e13513123b79f415141580a1ae9d6a1892fc |
|
MD5 | 0a586c2e52a07175c569334974b671b9 |
|
BLAKE2b-256 | 54cecdeef67994000f9edde49a05ca7f0b5ab472272c21fe87d48f59780b2b20 |