Skip to main content

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


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

rr.approx-0.1.1-py2-none-any.whl (6.9 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page