This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
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.

print Approx.Context()  # display current context
Approx.Context(rtol=1e-4, atol=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()

Disclaimer

Please note that this module does not solve any problems with floating point numbers. What it does is provide a little (or big, depending on how you configure your tolerance parameters) buffer to compensate for rounding errors, but as these errors accumulate you can always get unexpected results.

Float rounding is inherently innaccurate in all computers and programming languages due to representing a possibly recurring decimal in a finite number of digits. If you really care about exact results and don’t mind paying a performance penalty, you should check out the decimal module from the standard library or some other alternative.

Installation

>From PyPI (“stable” release):

pip install rr.approx

Or from the Git repo:

git clone https://github.com/2xR/rr.approx.git
pip install ./rr.approx

Contributing

Contributions are welcome through github pull requests (tests would sure be nice to have… :P).

And if you’re using the library and would like to say “thanks!” and/or keep me working on it, why not buy me a beer?

Happy approximate comparisons!

Release History

Release History

0.1.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
rr.approx-0.1.2-py2-none-any.whl (8.3 kB) Copy SHA256 Checksum SHA256 py2 Wheel Jun 24, 2016
rr.approx-0.1.2.zip (9.9 kB) Copy SHA256 Checksum SHA256 Source Jun 24, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting